apk: replace the constraint regex and its cache with a hand-written parser - #2467
Draft
markusthoemmes wants to merge 1 commit into
Draft
apk: replace the constraint regex and its cache with a hand-written parser#2467markusthoemmes wants to merge 1 commit into
markusthoemmes wants to merge 1 commit into
Conversation
…arser ResolvePackageNameVersionPin parsed with a regex and hid the cost behind a process-global sync.Map keyed by every constraint string ever seen. The grammar is small enough to parse by hand in about 25 ns with no allocations, faster than the cache lookup was, so the cache is deleted and all call sites parse directly. On the Wolfi x86_64 index a resolver build goes from 63 ms to 36 ms. The resolver build uses a name-only path that skips the shared library version tweak, which never changes the name, so it allocates nothing per provide. ParseConstraint is exported as the variant without the tweak that reports whether the string fit the grammar, and pkg/build/lock.go uses it in place of its own copy of the regex. The previous regex implementations stay in the tests as oracles, with a table, a fuzz test and a check over every string in the Wolfi indexes.
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.
ResolvePackageNameVersionPin parsed with a regex and hid the cost behind a process-global sync.Map keyed by every constraint string ever seen. The grammar is small enough to parse by hand in about 25 ns with no allocations, faster than the cache lookup was, so the cache is deleted and all call sites parse directly. On the Wolfi x86_64 index a resolver build goes from 63 ms to 36 ms. The resolver build uses a name-only path that skips the shared library version tweak, which never changes the name, so it allocates nothing per provide.
ParseConstraint is exported as the variant without the tweak that reports whether the string fit the grammar, and pkg/build/lock.go uses it in place of its own copy of the regex. The previous regex implementations stay in the tests as oracles, with a table, a fuzz test and a check over every string in the Wolfi indexes.