Skip to content

fix: speed up local spec startup - #371

Merged
danielgtaylor merged 2 commits into
mainfrom
fix/local-spec-startup-cache
Jun 6, 2026
Merged

fix: speed up local spec startup#371
danielgtaylor merged 2 commits into
mainfrom
fix/local-spec-startup-cache

Conversation

@danielgtaylor

Copy link
Copy Markdown
Collaborator

Summary

  • Preserve local spec file mtime precision in spec cache metadata and accept legacy second-precision cache entries.
  • Skip generated API command registration for restish --version startup.
  • Add regression coverage for local spec cache reuse and version startup scanning.

Root Cause

Local spec file mtimes could round-trip through the CBOR cache at whole-second precision, while os.Stat returned 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/spec
  • env GOCACHE=/tmp/restish-gocache go test ./internal/cli
  • env GOCACHE=/tmp/restish-gocache go test ./internal/spec ./internal/cli
  • git diff --check
  • Rechecked the Datadog local spec repro: repeat --version is about 0.02s, while --help remains fast and still lists generated APIs.

Fixes #370

@danielgtaylor
danielgtaylor marked this pull request as ready for review June 5, 2026 16:19
@danielgtaylor
danielgtaylor requested a review from Copilot June 5, 2026 16:19

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 mtime at nanosecond precision (via mod_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 --version startup 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.

Comment thread internal/spec/cache_test.go

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated no new comments.

@danielgtaylor
danielgtaylor merged commit 9a17d90 into main Jun 6, 2026
8 checks passed
@danielgtaylor
danielgtaylor deleted the fix/local-spec-startup-cache branch June 6, 2026 00:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Local spec files increase startup time

2 participants