Skip to content

regexp: speed up onepass prefix check #48892

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

Open
wants to merge 2 commits 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 Used by googlebot to label PRs as having a valid CLA. The text of this label should not change. label Oct 9, 2021
@gopherbot
Copy link
Contributor

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

@gopherbot
Copy link
Contributor

Message from Mn Mn:

Patch Set 1:

(1 comment)


Please don’t reply on this GitHub thread. Visit golang.org/cl/354909.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link
Contributor

Message from Mn Mn:

Patch Set 1: Code-Review+1


Please don’t reply on this GitHub thread. Visit golang.org/cl/354909.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link
Contributor

Message from Ian Lance Taylor:

Patch Set 1: Run-TryBot+1


Please don’t reply on this GitHub thread. Visit golang.org/cl/354909.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link
Contributor

Message from Go Bot:

Patch Set 1:

(1 comment)


Please don’t reply on this GitHub thread. Visit golang.org/cl/354909.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link
Contributor

Message from Go Bot:

Patch Set 1: TryBot-Result+1

(1 comment)


Please don’t reply on this GitHub thread. Visit golang.org/cl/354909.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link
Contributor

Message from Russ Cox:

Patch Set 1:

(2 comments)


Please don’t reply on this GitHub thread. Visit golang.org/cl/354909.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link
Contributor

Message from Bryan Boreham:

Patch Set 1:

(1 comment)


Please don’t reply on this GitHub thread. Visit golang.org/cl/354909.
After addressing review feedback, remember to publish your drafts!

Move initialization of r and r1 next to each other.
@gopherbot
Copy link
Contributor

This PR (HEAD: d63b833) 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

@717r
Copy link

717r commented Oct 24, 2021

  • [ ]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes Used by googlebot to label PRs as having a valid CLA. The text of this label should not change.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

regexp: doOnePass does unnecessary check when regexp has a prefix
3 participants