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

gogrep: don't copy capture slice during backtracking #210

Merged
merged 1 commit into from
Feb 4, 2021

Conversation

quasilyte
Copy link
Owner

@quasilyte quasilyte commented Feb 4, 2021

Since we use slices now, we can avoid copying when backtracking.

Instead of copying a slice to a restart record, we store a slice
handle of the current length. When backtracking is involved, we
discard all excessive captures by the fact that elements past
length would be forgotten.

This makes gogrep more efficient for the patterns that backtrack.

name                           old time/op    new time/op    delta
Match/captureBacktrackLeft-8     4.67µs ± 3%    3.20µs ± 3%  -31.63%  (p=0.008 n=5+5)
Match/captureBacktrackRight-8    2.45µs ± 1%    1.85µs ± 2%  -24.15%  (p=0.008 n=5+5)

name                           old alloc/op   new alloc/op   delta
Match/captureBacktrackLeft-8       848B ± 0%      368B ± 0%  -56.60%  (p=0.008 n=5+5)
Match/captureBacktrackRight-8      432B ± 0%      208B ± 0%  -51.85%  (p=0.008 n=5+5)

name                           old allocs/op  new allocs/op  delta
Match/captureBacktrackLeft-8       21.0 ± 0%      11.0 ± 0%  -47.62%  (p=0.008 n=5+5)
Match/captureBacktrackRight-8      12.0 ± 0%       6.0 ± 0%  -50.00%  (p=0.008 n=5+5)

Since we use slices now, we can avoid copying when backtracking.

Instead of copying a slice to a restart record, we store a slice
handle of the current length. When backtracking is involved, we
discard all excessive captures by the fact that elements past
length would be forgotten.

This makes gogrep more efficient for the patterns that backtrack.

name                           old time/op    new time/op    delta
Match/captureBacktrackLeft-8     4.67µs ± 3%    3.20µs ± 3%  -31.63%  (p=0.008 n=5+5)
Match/captureBacktrackRight-8    2.45µs ± 1%    1.85µs ± 2%  -24.15%  (p=0.008 n=5+5)

name                           old alloc/op   new alloc/op   delta
Match/captureBacktrackLeft-8       848B ± 0%      368B ± 0%  -56.60%  (p=0.008 n=5+5)
Match/captureBacktrackRight-8      432B ± 0%      208B ± 0%  -51.85%  (p=0.008 n=5+5)

name                           old allocs/op  new allocs/op  delta
Match/captureBacktrackLeft-8       21.0 ± 0%      11.0 ± 0%  -47.62%  (p=0.008 n=5+5)
Match/captureBacktrackRight-8      12.0 ± 0%       6.0 ± 0%  -50.00%  (p=0.008 n=5+5)
@quasilyte quasilyte merged commit 6f82058 into master Feb 4, 2021
@quasilyte quasilyte deleted the quasilyte/gogrep/no_capture_copying branch February 4, 2021 19:19
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