Repository navigation
mr starts 18x faster: regexps compile on first use (#8) - #66
Merged
Merged
Conversation
init of package main compiled all 47 package-level patterns on every start (every CGI request and hook): 3.2 ms, 2.48 MB, 33,442 allocations on x86. lazyRegexp compiles on first use; now 0.18 ms, 39,696 bytes, 289 allocations. A test compiles every pattern; CI fails if init allocates >= 256 KiB. Closes #8
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.
What
mr/lazyre.go:lazyRegexp(pattern)compiles on first use (sync.Once) and provides the methods the code uses (MatchString,FindStringSubmatch,FindSubmatch, …). All 47 package-levelregexp.MustCompilebecomelazyRegexp.GODEBUG=inittrace=1 mr versionand fails if package main's init allocates 256 KiB or more — a new eager package-levelMustCompileis caught.Why
mrstarts for every web UI request (CGI) and every hook. Its init compiled every pattern each time, although a call uses few of them — including ones with large counted repetitions that expand into long programs.init main(x86, build host)The router's Cortex-A53 is several times slower than the build host, so the saving per request is larger there.
Verification
Measured before / after on the build host (numbers above);
tools/ci.shpasses (private and public trees) with the new init-cost check.Closes #8
https://claude.ai/code/session_01HWeUjo1dmS7gBkCYHrVjCr