Repository navigation
perf(registry): index snapshot entries for GetEntry - #1052
Merged
Merged
Conversation
Snapshot.GetEntry scanned every entry and canonicalized both IDs per comparison, so each Lua snapshot:get cost O(entries) on a large registry. Build a map of canonical ID parts to the first entry position on first lookup, once per snapshot under sync.Once. Snapshots that only list, find or plan changes never pay for it. Results match ID.Equal: canonical parts are the key, the earliest duplicate wins, and the not-found error is unchanged.
Canonical joined namespace and name to compare against the cached string, and the join allocates once it exceeds the compiler's 32-byte stack buffer. Compare the cached string in place so already canonical IDs never allocate, as the method documents. This also removes one allocation per entry from snapshot index builds and one per registry lookup.
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.
A Lua registry snapshot answers
getby scanning every entry and canonicalizing both IDs per comparison, so a snapshot read costs time proportional to the whole registry. Under real application load this scan was 47% of CPU samples during bursts.GetEntryuses a lazy index on canonical (namespace, name), built once per snapshot. The first duplicate still wins, and the not-found error is unchanged. The key is not the joined string, sinceID.Equaltreats("a","b:c")and("a:b","c")as different.ID.Canonicalno longer allocates for already-canonical IDs over 32 bytes, as it documents.The index belongs to each snapshot, so a snapshot with fewer than about 15 gets costs more than before. Moving the index to the published registry state would remove that cost; it is left for a separate change.
Tests compare results against the old scan across canonical, name-only, duplicate, colliding, empty and missing IDs, the Lua path, and concurrent readers under
-race.