Skip to content

apk: replace the constraint regex and its cache with a hand-written parser - #2467

Draft
markusthoemmes wants to merge 1 commit into
chainguard-dev:mainfrom
markusthoemmes:constraint-parser
Draft

apk: replace the constraint regex and its cache with a hand-written parser#2467
markusthoemmes wants to merge 1 commit into
chainguard-dev:mainfrom
markusthoemmes:constraint-parser

Conversation

@markusthoemmes

Copy link
Copy Markdown
Member

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.

…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.
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.

1 participant