The Wayback Machine - https://web.archive.org/web/20211009145330/https://github.com/golang/go/pull/48892
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

regexp: speed up onepass prefix check #48892

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

@bboreham
Copy link
Contributor

@bboreham bboreham commented Oct 9, 2021

Remove an unnecessary check that the first operation matches - we know
from compile-time that it is EmptyBeginText which will always match at
position 0.

This enables the call to i.hasPrefix to be done before unpacking the
instruction or the first two runes. If the prefix does not match we
go straight to return, and if it does match we need the runes after the
match, so in either case unpacking the runes was unnecessary.

Fixes #48891

Modifying the regexp in BenchmarkAnchoredLiteralShortNonMatch to "^zbc(d|e).*$"
so it uses the onepass engine (see #48748), we get this improvement:

name                            old time/op    new time/op    delta
AnchoredLiteralShortNonMatch-8    29.8ns ± 5%    20.6ns ± 2%  -30.89%  (p=0.008 n=5+5)

name                            old alloc/op   new alloc/op   delta
AnchoredLiteralShortNonMatch-8     0.00B          0.00B          ~     (all equal)

name                            old allocs/op  new allocs/op  delta
AnchoredLiteralShortNonMatch-8      0.00           0.00          ~     (all equal)
Remove an unnecessary check that the first operation matches - we know
from compile-time that it is EmptyBeginText which will always match at
position 0.

This enables the call to i.hasPrefix to be done before unpacking the
instruction or the first two runes. If the prefix does not match we
go straight to return, and if it does match we need the runes after the
match, so in either case unpacking the runes was unnecessary.
@google-cla google-cla bot added the cla: yes label Oct 9, 2021
@gopherbot
Copy link

@gopherbot gopherbot commented Oct 9, 2021

This PR (HEAD: 8574350) has been imported to Gerrit for code review.

Please visit https://go-review.googlesource.com/c/go/+/354909 to see it.

Tip: You can toggle comments from me using the comments slash command (e.g. /comments off)
See the Wiki page for more info

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

2 participants