fix: speed up local spec startup - #371
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR improves Restish startup performance for configurations that use large local OpenAPI spec files by making spec-cache validation more robust to timestamp precision loss, and by avoiding generated API command registration work for restish --version.
Changes:
- Extend cached local spec file metadata to store
mtimeat nanosecond precision (viamod_time_unix_nano) while still accepting legacy second-precision cache entries. - Skip generated API command registration when the invocation is
--version. - Add regression tests covering legacy cache reuse, nanosecond mtime handling, and
--versionstartup scanning behavior.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| internal/spec/discover.go | Adds nanosecond mtime capture and legacy-safe mtime matching for local spec cache metadata. |
| internal/spec/discover_test.go | Extends metadata tests to cover mod_time_unix_nano and legacy second-precision matching. |
| internal/spec/cache.go | Adds ModTimeUnixNano to the CBOR cache schema for local spec file metadata. |
| internal/spec/cache_test.go | Adds regression tests for legacy second-precision cache hits and local-spec cache reuse. |
| internal/cli/cli.go | Detects --version early and avoids generated API command scanning/registration for that path. |
| internal/cli/cli_internal_test.go | Adds coverage ensuring --version doesn’t request generated API command metadata while --help still does. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
restish --versionstartup.Root Cause
Local spec file mtimes could round-trip through the CBOR cache at whole-second precision, while
os.Statreturned nanosecond precision. Exact mtime equality failed, so cached local spec metadata was treated as stale and large local specs were reparsed during startup.Validation
env GOCACHE=/tmp/restish-gocache go test ./internal/specenv GOCACHE=/tmp/restish-gocache go test ./internal/clienv GOCACHE=/tmp/restish-gocache go test ./internal/spec ./internal/cligit diff --check--versionis about0.02s, while--helpremains fast and still lists generated APIs.Fixes #370