go/src/regexp/backtrack.go

367 lines
8.8 KiB
Go
Raw Normal View History

regexp: port RE2's bitstate backtracker to the regexp package This is a port of RE2's bitstate backtracker, which triggers under the same conditions that the RE2 backtracker triggers. However I wasn't sure how to port over some of the optimizations in the RE2 backtracker, and there is a ~2% penalty on benchmarks that don't trigger the backtracker. benchmark old ns/op new ns/op delta BenchmarkLiteral 312 189 -39.42% BenchmarkNotLiteral 4435 3001 -32.33% BenchmarkMatchClass 5758 4378 -23.97% BenchmarkMatchClass_InRange 5385 4084 -24.16% BenchmarkReplaceAll 5291 3505 -33.76% BenchmarkAnchoredLiteralShortNonMatch 190 200 +5.26% BenchmarkAnchoredLiteralLongNonMatch 189 194 +2.65% BenchmarkAnchoredShortMatch 479 304 -36.53% BenchmarkAnchoredLongMatch 478 499 +4.39% BenchmarkOnePassShortA 791 798 +0.88% BenchmarkNotOnePassShortA 3202 1571 -50.94% BenchmarkOnePassShortB 614 633 +3.09% BenchmarkNotOnePassShortB 2685 881 -67.19% BenchmarkOnePassLongPrefix 152 154 +1.32% BenchmarkOnePassLongNotPrefix 505 533 +5.54% BenchmarkMatchEasy0_32 139 171 +23.02% BenchmarkMatchEasy0_1K 653 1797 +175.19% BenchmarkMatchEasy0_32K 12032 13346 +10.92% BenchmarkMatchEasy0_1M 462882 461272 -0.35% BenchmarkMatchEasy0_32M 15015339 15365238 +2.33% BenchmarkMatchEasy1_32 122 168 +37.70% BenchmarkMatchEasy1_1K 3339 2612 -21.77% BenchmarkMatchEasy1_32K 72330 71721 -0.84% BenchmarkMatchEasy1_1M 2545410 2652284 +4.20% BenchmarkMatchEasy1_32M 80072063 82609750 +3.17% BenchmarkMatchMedium_32 2359 1980 -16.07% BenchmarkMatchMedium_1K 75939 58593 -22.84% BenchmarkMatchMedium_32K 2450907 2501106 +2.05% BenchmarkMatchMedium_1M 78707697 80174418 +1.86% BenchmarkMatchMedium_32M 2535146010 2570896441 +1.41% BenchmarkMatchHard_32 4297 2960 -31.11% BenchmarkMatchHard_1K 133592 88997 -33.38% BenchmarkMatchHard_32K 4240445 4336907 +2.27% BenchmarkMatchHard_1M 136187006 139350238 +2.32% BenchmarkMatchHard_32M 4350855890 4478537306 +2.93% benchmark old MB/s new MB/s speedup BenchmarkMatchEasy0_32 228.74 186.11 0.81x BenchmarkMatchEasy0_1K 1565.91 569.64 0.36x BenchmarkMatchEasy0_32K 2723.31 2455.10 0.90x BenchmarkMatchEasy0_1M 2265.32 2273.22 1.00x BenchmarkMatchEasy0_32M 2234.68 2183.79 0.98x BenchmarkMatchEasy1_32 261.08 190.22 0.73x BenchmarkMatchEasy1_1K 306.59 391.91 1.28x BenchmarkMatchEasy1_32K 453.03 456.88 1.01x BenchmarkMatchEasy1_1M 411.95 395.35 0.96x BenchmarkMatchEasy1_32M 419.05 406.18 0.97x BenchmarkMatchMedium_32 13.56 16.16 1.19x BenchmarkMatchMedium_1K 13.48 17.48 1.30x BenchmarkMatchMedium_32K 13.37 13.10 0.98x BenchmarkMatchMedium_1M 13.32 13.08 0.98x BenchmarkMatchMedium_32M 13.24 13.05 0.99x BenchmarkMatchHard_32 7.45 10.81 1.45x BenchmarkMatchHard_1K 7.67 11.51 1.50x BenchmarkMatchHard_32K 7.73 7.56 0.98x BenchmarkMatchHard_1M 7.70 7.52 0.98x BenchmarkMatchHard_32M 7.71 7.49 0.97x Fixes #4154 Change-Id: Iff7fb9507f0872b320d08afc08679751ed1b28bc Reviewed-on: https://go-review.googlesource.com/2153 Reviewed-by: Russ Cox <rsc@golang.org>
2014-12-28 00:17:01 -08:00
// Copyright 2015 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// backtrack is a regular expression search with submatch
// tracking for small regular expressions and texts. It allocates
// a bit vector with (length of input) * (length of prog) bits,
// to make sure it never explores the same (character position, instruction)
// state multiple times. This limits the search to run in time linear in
// the length of the test.
//
// backtrack is a fast replacement for the NFA code on small
// regexps when onepass cannot be used.
package regexp
regexp: split bit-state execution out of machine struct This allows the bit-state executions to have their own pool of allocated structures. A step toward eliminating the per-Regexp machine cache. Note especially the -92% on MatchParallelShared. This is real but not a complete story: the other execution engines still need to be de-shared, but the benchmark was only using bit-state. The tiny slowdowns in unrelated code are noise. name old time/op new time/op delta Find-12 264ns ± 3% 254ns ± 0% -3.86% (p=0.000 n=10+9) FindAllNoMatches-12 140ns ± 2% 135ns ± 0% -3.91% (p=0.000 n=10+9) FindString-12 256ns ± 0% 247ns ± 0% -3.52% (p=0.000 n=8+8) FindSubmatch-12 339ns ± 1% 334ns ± 0% -1.41% (p=0.000 n=9+10) FindStringSubmatch-12 322ns ± 0% 321ns ± 0% -0.21% (p=0.005 n=8+9) Literal-12 100ns ± 2% 92ns ± 0% -8.10% (p=0.000 n=10+9) NotLiteral-12 1.50µs ± 0% 1.47µs ± 0% -1.91% (p=0.000 n=8+9) MatchClass-12 2.18µs ± 0% 2.17µs ± 0% -0.20% (p=0.001 n=10+7) MatchClass_InRange-12 2.12µs ± 0% 2.13µs ± 0% +0.23% (p=0.000 n=10+10) ReplaceAll-12 1.41µs ± 0% 1.39µs ± 0% -1.30% (p=0.000 n=7+10) AnchoredLiteralShortNonMatch-12 89.8ns ± 0% 83.2ns ± 0% -7.35% (p=0.000 n=8+8) AnchoredLiteralLongNonMatch-12 105ns ± 3% 105ns ± 0% ~ (p=0.186 n=10+10) AnchoredShortMatch-12 141ns ± 0% 131ns ± 0% -7.09% (p=0.000 n=9+10) AnchoredLongMatch-12 276ns ± 4% 267ns ± 0% -3.23% (p=0.000 n=10+10) OnePassShortA-12 620ns ± 0% 611ns ± 0% -1.39% (p=0.000 n=10+9) NotOnePassShortA-12 575ns ± 3% 552ns ± 0% -3.97% (p=0.000 n=10+8) OnePassShortB-12 493ns ± 0% 491ns ± 0% -0.33% (p=0.000 n=8+8) NotOnePassShortB-12 423ns ± 0% 412ns ± 0% -2.60% (p=0.000 n=8+9) OnePassLongPrefix-12 112ns ± 0% 112ns ± 0% ~ (all equal) OnePassLongNotPrefix-12 405ns ± 0% 410ns ± 0% +1.23% (p=0.000 n=8+9) MatchParallelShared-12 501ns ± 1% 39ns ± 1% -92.27% (p=0.000 n=10+10) MatchParallelCopied-12 39.1ns ± 0% 39.2ns ± 3% ~ (p=0.785 n=6+10) QuoteMetaAll-12 94.6ns ± 0% 94.6ns ± 0% ~ (p=0.439 n=10+8) QuoteMetaNone-12 52.7ns ± 0% 52.7ns ± 0% ~ (all equal) Match/Easy0/32-12 79.1ns ± 0% 72.9ns ± 0% -7.85% (p=0.000 n=9+9) Match/Easy0/1K-12 307ns ± 1% 298ns ± 0% -2.99% (p=0.000 n=10+6) Match/Easy0/32K-12 4.65µs ± 2% 4.60µs ± 2% ~ (p=0.159 n=10+10) Match/Easy0/1M-12 234µs ± 0% 235µs ± 0% +0.17% (p=0.003 n=10+10) Match/Easy0/32M-12 7.98ms ± 1% 7.96ms ± 0% ~ (p=0.278 n=9+10) Match/Easy0i/32-12 1.13µs ± 1% 1.09µs ± 0% -3.24% (p=0.000 n=9+8) Match/Easy0i/1K-12 32.5µs ± 0% 31.7µs ± 0% -2.66% (p=0.000 n=9+9) Match/Easy0i/32K-12 1.59ms ± 0% 1.61ms ± 0% +0.75% (p=0.000 n=9+9) Match/Easy0i/1M-12 51.0ms ± 0% 51.4ms ± 0% +0.77% (p=0.000 n=10+8) Match/Easy0i/32M-12 1.63s ± 0% 1.65s ± 1% +1.24% (p=0.000 n=7+9) Match/Easy1/32-12 75.1ns ± 1% 67.9ns ± 0% -9.54% (p=0.000 n=8+8) Match/Easy1/1K-12 861ns ± 0% 884ns ± 0% +2.71% (p=0.000 n=8+9) Match/Easy1/32K-12 39.2µs ± 1% 39.2µs ± 0% ~ (p=0.090 n=10+9) Match/Easy1/1M-12 1.38ms ± 0% 1.39ms ± 0% ~ (p=0.095 n=10+9) Match/Easy1/32M-12 44.2ms ± 1% 44.2ms ± 1% ~ (p=0.218 n=10+10) Match/Medium/32-12 1.04µs ± 1% 1.05µs ± 0% +1.05% (p=0.000 n=9+8) Match/Medium/1K-12 31.3µs ± 0% 31.3µs ± 0% -0.14% (p=0.004 n=9+9) Match/Medium/32K-12 1.44ms ± 0% 1.45ms ± 0% +0.18% (p=0.001 n=8+8) Match/Medium/1M-12 46.1ms ± 0% 46.2ms ± 0% +0.13% (p=0.003 n=6+9) Match/Medium/32M-12 1.48s ± 0% 1.48s ± 0% +0.20% (p=0.002 n=9+8) Match/Hard/32-12 1.54µs ± 1% 1.49µs ± 0% -3.60% (p=0.000 n=9+10) Match/Hard/1K-12 46.4µs ± 1% 45.1µs ± 1% -2.78% (p=0.000 n=9+10) Match/Hard/32K-12 2.19ms ± 0% 2.18ms ± 1% -0.51% (p=0.006 n=8+9) Match/Hard/1M-12 70.1ms ± 0% 69.7ms ± 1% -0.52% (p=0.006 n=8+9) Match/Hard/32M-12 2.24s ± 0% 2.23s ± 1% -0.42% (p=0.046 n=8+9) Match/Hard1/32-12 8.17µs ± 1% 7.89µs ± 0% -3.42% (p=0.000 n=8+9) Match/Hard1/1K-12 254µs ± 2% 244µs ± 0% -3.91% (p=0.000 n=9+9) Match/Hard1/32K-12 9.58ms ± 1% 10.35ms ± 0% +8.00% (p=0.000 n=10+10) Match/Hard1/1M-12 306ms ± 1% 331ms ± 0% +8.27% (p=0.000 n=9+8) Match/Hard1/32M-12 9.79s ± 1% 10.60s ± 0% +8.29% (p=0.000 n=9+8) Match_onepass_regex/32-12 808ns ± 0% 812ns ± 0% +0.47% (p=0.000 n=8+10) Match_onepass_regex/1K-12 27.8µs ± 0% 28.5µs ± 0% +2.32% (p=0.000 n=8+10) Match_onepass_regex/32K-12 925µs ± 0% 936µs ± 0% +1.24% (p=0.000 n=9+10) Match_onepass_regex/1M-12 29.5ms ± 0% 30.2ms ± 0% +2.38% (p=0.000 n=10+10) Match_onepass_regex/32M-12 945ms ± 0% 970ms ± 0% +2.60% (p=0.000 n=9+10) CompileOnepass-12 4.67µs ± 0% 4.63µs ± 1% -0.84% (p=0.000 n=10+10) [Geo mean] 24.5µs 23.3µs -5.04% https://perf.golang.org/search?q=upload:20181004.1 Change-Id: Idbc2b76223718265657819ff38be2d9aba1c54b4 Reviewed-on: https://go-review.googlesource.com/c/139779 Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-09-28 16:37:16 -04:00
import (
"regexp/syntax"
"sync"
)
regexp: port RE2's bitstate backtracker to the regexp package This is a port of RE2's bitstate backtracker, which triggers under the same conditions that the RE2 backtracker triggers. However I wasn't sure how to port over some of the optimizations in the RE2 backtracker, and there is a ~2% penalty on benchmarks that don't trigger the backtracker. benchmark old ns/op new ns/op delta BenchmarkLiteral 312 189 -39.42% BenchmarkNotLiteral 4435 3001 -32.33% BenchmarkMatchClass 5758 4378 -23.97% BenchmarkMatchClass_InRange 5385 4084 -24.16% BenchmarkReplaceAll 5291 3505 -33.76% BenchmarkAnchoredLiteralShortNonMatch 190 200 +5.26% BenchmarkAnchoredLiteralLongNonMatch 189 194 +2.65% BenchmarkAnchoredShortMatch 479 304 -36.53% BenchmarkAnchoredLongMatch 478 499 +4.39% BenchmarkOnePassShortA 791 798 +0.88% BenchmarkNotOnePassShortA 3202 1571 -50.94% BenchmarkOnePassShortB 614 633 +3.09% BenchmarkNotOnePassShortB 2685 881 -67.19% BenchmarkOnePassLongPrefix 152 154 +1.32% BenchmarkOnePassLongNotPrefix 505 533 +5.54% BenchmarkMatchEasy0_32 139 171 +23.02% BenchmarkMatchEasy0_1K 653 1797 +175.19% BenchmarkMatchEasy0_32K 12032 13346 +10.92% BenchmarkMatchEasy0_1M 462882 461272 -0.35% BenchmarkMatchEasy0_32M 15015339 15365238 +2.33% BenchmarkMatchEasy1_32 122 168 +37.70% BenchmarkMatchEasy1_1K 3339 2612 -21.77% BenchmarkMatchEasy1_32K 72330 71721 -0.84% BenchmarkMatchEasy1_1M 2545410 2652284 +4.20% BenchmarkMatchEasy1_32M 80072063 82609750 +3.17% BenchmarkMatchMedium_32 2359 1980 -16.07% BenchmarkMatchMedium_1K 75939 58593 -22.84% BenchmarkMatchMedium_32K 2450907 2501106 +2.05% BenchmarkMatchMedium_1M 78707697 80174418 +1.86% BenchmarkMatchMedium_32M 2535146010 2570896441 +1.41% BenchmarkMatchHard_32 4297 2960 -31.11% BenchmarkMatchHard_1K 133592 88997 -33.38% BenchmarkMatchHard_32K 4240445 4336907 +2.27% BenchmarkMatchHard_1M 136187006 139350238 +2.32% BenchmarkMatchHard_32M 4350855890 4478537306 +2.93% benchmark old MB/s new MB/s speedup BenchmarkMatchEasy0_32 228.74 186.11 0.81x BenchmarkMatchEasy0_1K 1565.91 569.64 0.36x BenchmarkMatchEasy0_32K 2723.31 2455.10 0.90x BenchmarkMatchEasy0_1M 2265.32 2273.22 1.00x BenchmarkMatchEasy0_32M 2234.68 2183.79 0.98x BenchmarkMatchEasy1_32 261.08 190.22 0.73x BenchmarkMatchEasy1_1K 306.59 391.91 1.28x BenchmarkMatchEasy1_32K 453.03 456.88 1.01x BenchmarkMatchEasy1_1M 411.95 395.35 0.96x BenchmarkMatchEasy1_32M 419.05 406.18 0.97x BenchmarkMatchMedium_32 13.56 16.16 1.19x BenchmarkMatchMedium_1K 13.48 17.48 1.30x BenchmarkMatchMedium_32K 13.37 13.10 0.98x BenchmarkMatchMedium_1M 13.32 13.08 0.98x BenchmarkMatchMedium_32M 13.24 13.05 0.99x BenchmarkMatchHard_32 7.45 10.81 1.45x BenchmarkMatchHard_1K 7.67 11.51 1.50x BenchmarkMatchHard_32K 7.73 7.56 0.98x BenchmarkMatchHard_1M 7.70 7.52 0.98x BenchmarkMatchHard_32M 7.71 7.49 0.97x Fixes #4154 Change-Id: Iff7fb9507f0872b320d08afc08679751ed1b28bc Reviewed-on: https://go-review.googlesource.com/2153 Reviewed-by: Russ Cox <rsc@golang.org>
2014-12-28 00:17:01 -08:00
// A job is an entry on the backtracker's job stack. It holds
// the instruction pc and the position in the input.
type job struct {
pc uint32
regexp: make (*bitState).push inlinable By refactoring job.arg from int with 0/1 as the only valid values into bool and simplifying (*bitState).push, we reduce the number of nodes below the inlining threshold. This improves backtracking regexp performance by 5-10% and go1 geomean by 1.7% Full performance data below: name old time/op new time/op delta Find-6 510ns ± 0% 480ns ± 1% -5.90% (p=0.000 n=10+10) FindString-6 504ns ± 1% 479ns ± 1% -5.10% (p=0.000 n=10+10) FindSubmatch-6 689ns ± 1% 659ns ± 1% -4.27% (p=0.000 n=9+10) FindStringSubmatch-6 659ns ± 0% 628ns ± 1% -4.69% (p=0.000 n=8+10) Literal-6 174ns ± 1% 171ns ± 1% -1.50% (p=0.000 n=10+10) NotLiteral-6 2.89µs ± 1% 2.72µs ± 0% -5.84% (p=0.000 n=10+9) MatchClass-6 4.65µs ± 1% 4.28µs ± 1% -7.96% (p=0.000 n=10+10) MatchClass_InRange-6 4.15µs ± 1% 3.80µs ± 0% -8.61% (p=0.000 n=10+8) ReplaceAll-6 2.72µs ± 1% 2.60µs ± 1% -4.68% (p=0.000 n=10+10) AnchoredLiteralShortNonMatch-6 158ns ± 1% 153ns ± 1% -3.03% (p=0.000 n=10+10) AnchoredLiteralLongNonMatch-6 176ns ± 1% 176ns ± 0% ~ (p=1.000 n=10+9) AnchoredShortMatch-6 260ns ± 0% 255ns ± 1% -1.84% (p=0.000 n=9+10) AnchoredLongMatch-6 456ns ± 0% 455ns ± 0% -0.19% (p=0.008 n=8+10) OnePassShortA-6 1.13µs ± 1% 1.12µs ± 0% -0.57% (p=0.046 n=10+8) NotOnePassShortA-6 1.14µs ± 1% 1.14µs ± 1% ~ (p=0.162 n=10+10) OnePassShortB-6 908ns ± 0% 893ns ± 0% -1.60% (p=0.000 n=8+9) NotOnePassShortB-6 857ns ± 0% 803ns ± 1% -6.34% (p=0.000 n=8+10) OnePassLongPrefix-6 190ns ± 0% 190ns ± 1% ~ (p=0.059 n=8+10) OnePassLongNotPrefix-6 722ns ± 1% 722ns ± 1% ~ (p=0.451 n=10+10) MatchParallelShared-6 810ns ± 2% 807ns ± 2% ~ (p=0.643 n=10+10) MatchParallelCopied-6 72.1ns ± 1% 69.4ns ± 1% -3.81% (p=0.000 n=10+10) QuoteMetaAll-6 213ns ± 2% 216ns ± 3% ~ (p=0.284 n=10+10) QuoteMetaNone-6 89.7ns ± 1% 89.8ns ± 1% ~ (p=0.616 n=10+10) Match/Easy0/32-6 127ns ± 1% 127ns ± 1% ~ (p=0.977 n=10+10) Match/Easy0/1K-6 566ns ± 0% 566ns ± 0% ~ (p=1.000 n=8+8) Match/Easy0/32K-6 9.30µs ± 1% 9.28µs ± 1% ~ (p=0.529 n=10+10) Match/Easy0/1M-6 460µs ± 1% 460µs ± 1% ~ (p=0.853 n=10+10) Match/Easy0/32M-6 15.0ms ± 0% 15.1ms ± 0% +0.77% (p=0.000 n=9+8) Match/Easy0i/32-6 2.10µs ± 1% 1.98µs ± 0% -6.02% (p=0.000 n=10+8) Match/Easy0i/1K-6 61.5µs ± 0% 57.2µs ± 0% -6.97% (p=0.000 n=10+9) Match/Easy0i/32K-6 2.75ms ± 0% 2.72ms ± 0% -1.10% (p=0.000 n=9+9) Match/Easy0i/1M-6 88.0ms ± 0% 86.9ms ± 1% -1.29% (p=0.000 n=8+10) Match/Easy0i/32M-6 2.82s ± 0% 2.77s ± 1% -1.81% (p=0.000 n=8+10) Match/Easy1/32-6 123ns ± 1% 124ns ± 1% +0.90% (p=0.001 n=10+10) Match/Easy1/1K-6 1.70µs ± 1% 1.65µs ± 0% -3.18% (p=0.000 n=9+10) Match/Easy1/32K-6 69.1µs ± 0% 68.4µs ± 1% -0.95% (p=0.000 n=8+10) Match/Easy1/1M-6 2.46ms ± 1% 2.42ms ± 1% -1.66% (p=0.000 n=10+10) Match/Easy1/32M-6 78.4ms ± 1% 77.5ms ± 0% -1.08% (p=0.000 n=10+9) Match/Medium/32-6 2.07µs ± 1% 1.91µs ± 1% -7.69% (p=0.000 n=10+10) Match/Medium/1K-6 62.8µs ± 0% 58.0µs ± 1% -7.70% (p=0.000 n=8+10) Match/Medium/32K-6 2.63ms ± 1% 2.58ms ± 1% -2.14% (p=0.000 n=10+10) Match/Medium/1M-6 84.6ms ± 0% 82.5ms ± 0% -2.37% (p=0.000 n=8+9) Match/Medium/32M-6 2.71s ± 0% 2.64s ± 0% -2.46% (p=0.000 n=10+9) Match/Hard/32-6 3.26µs ± 1% 2.98µs ± 1% -8.49% (p=0.000 n=10+10) Match/Hard/1K-6 100µs ± 0% 90µs ± 1% -9.55% (p=0.000 n=9+10) Match/Hard/32K-6 3.82ms ± 0% 3.82ms ± 1% ~ (p=0.515 n=8+10) Match/Hard/1M-6 122ms ± 1% 123ms ± 0% +0.66% (p=0.000 n=10+8) Match/Hard/32M-6 3.89s ± 1% 3.91s ± 1% ~ (p=0.105 n=10+10) Match/Hard1/32-6 18.1µs ± 1% 16.1µs ± 1% -11.31% (p=0.000 n=10+10) Match/Hard1/1K-6 565µs ± 0% 493µs ± 1% -12.65% (p=0.000 n=8+10) Match/Hard1/32K-6 18.8ms ± 0% 18.8ms ± 1% ~ (p=0.905 n=9+10) Match/Hard1/1M-6 602ms ± 1% 602ms ± 1% ~ (p=0.278 n=9+10) Match/Hard1/32M-6 19.1s ± 1% 19.2s ± 1% +0.31% (p=0.035 n=9+10) Match_onepass_regex/32-6 6.32µs ± 1% 6.34µs ± 1% ~ (p=0.060 n=10+10) Match_onepass_regex/1K-6 204µs ± 1% 204µs ± 1% ~ (p=0.842 n=9+10) Match_onepass_regex/32K-6 6.53ms ± 0% 6.55ms ± 1% +0.36% (p=0.005 n=10+10) Match_onepass_regex/1M-6 209ms ± 0% 208ms ± 1% -0.65% (p=0.034 n=8+10) Match_onepass_regex/32M-6 6.72s ± 0% 6.68s ± 1% -0.74% (p=0.000 n=9+10) CompileOnepass/^(?:(?:(?:.(?:$))?))...-6 7.02µs ± 1% 7.02µs ± 1% ~ (p=0.671 n=10+10) CompileOnepass/^abcd$-6 5.65µs ± 1% 5.65µs ± 1% ~ (p=0.411 n=10+9) CompileOnepass/^(?:(?:a{0,})*?)$-6 7.06µs ± 1% 7.06µs ± 1% ~ (p=0.912 n=10+10) CompileOnepass/^(?:(?:a+)*)$-6 6.40µs ± 1% 6.41µs ± 1% ~ (p=0.699 n=10+10) CompileOnepass/^(?:(?:a|(?:aa)))$-6 8.18µs ± 2% 8.16µs ± 1% ~ (p=0.529 n=10+10) CompileOnepass/^(?:[^\s\S])$-6 5.08µs ± 1% 5.17µs ± 1% +1.77% (p=0.000 n=9+10) CompileOnepass/^(?:(?:(?:a*)+))$-6 6.86µs ± 1% 6.85µs ± 0% ~ (p=0.190 n=10+9) CompileOnepass/^[a-c]+$-6 5.14µs ± 1% 5.11µs ± 0% -0.53% (p=0.041 n=10+10) CompileOnepass/^[a-c]*$-6 5.62µs ± 1% 5.63µs ± 1% ~ (p=0.382 n=10+10) CompileOnepass/^(?:a*)$-6 5.76µs ± 1% 5.73µs ± 1% -0.41% (p=0.008 n=9+10) CompileOnepass/^(?:(?:aa)|a)$-6 7.89µs ± 1% 7.84µs ± 1% -0.66% (p=0.020 n=10+10) CompileOnepass/^...$-6 5.38µs ± 1% 5.38µs ± 1% ~ (p=0.857 n=9+10) CompileOnepass/^(?:a|(?:aa))$-6 7.80µs ± 2% 7.82µs ± 1% ~ (p=0.342 n=10+10) CompileOnepass/^a((b))c$-6 7.75µs ± 1% 7.78µs ± 1% ~ (p=0.172 n=10+10) CompileOnepass/^a.[l-nA-Cg-j]?e$-6 8.39µs ± 1% 8.42µs ± 1% ~ (p=0.138 n=10+10) CompileOnepass/^a((b))$-6 6.92µs ± 1% 6.95µs ± 1% ~ (p=0.159 n=10+10) CompileOnepass/^a(?:(b)|(c))c$-6 10.0µs ± 1% 10.0µs ± 1% ~ (p=0.896 n=10+10) CompileOnepass/^a(?:b|c)$-6 5.62µs ± 1% 5.66µs ± 1% +0.71% (p=0.023 n=10+10) CompileOnepass/^a(?:b?|c)$-6 8.49µs ± 1% 8.43µs ± 1% -0.69% (p=0.010 n=10+10) CompileOnepass/^a(?:b?|c+)$-6 9.26µs ± 1% 9.28µs ± 1% ~ (p=0.448 n=10+10) CompileOnepass/^a(?:bc)+$-6 6.52µs ± 1% 6.46µs ± 2% -1.02% (p=0.003 n=10+10) CompileOnepass/^a(?:[bcd])+$-6 6.29µs ± 1% 6.32µs ± 1% ~ (p=0.256 n=10+10) CompileOnepass/^a((?:[bcd])+)$-6 7.77µs ± 1% 7.79µs ± 1% ~ (p=0.105 n=10+10) CompileOnepass/^a(:?b|c)*d$-6 14.0µs ± 1% 13.9µs ± 1% -0.69% (p=0.003 n=10+10) CompileOnepass/^.bc(d|e)*$-6 8.96µs ± 1% 9.06µs ± 1% +1.20% (p=0.000 n=10+9) CompileOnepass/^loooooooooooooooooo...-6 219µs ± 1% 220µs ± 1% +0.63% (p=0.006 n=9+10) [Geo mean] 31.6µs 31.1µs -1.82% name old speed new speed delta QuoteMetaAll-6 65.5MB/s ± 2% 64.8MB/s ± 3% ~ (p=0.315 n=10+10) QuoteMetaNone-6 290MB/s ± 1% 290MB/s ± 1% ~ (p=0.755 n=10+10) Match/Easy0/32-6 250MB/s ± 0% 251MB/s ± 1% ~ (p=0.277 n=8+9) Match/Easy0/1K-6 1.81GB/s ± 0% 1.81GB/s ± 0% ~ (p=0.408 n=8+10) Match/Easy0/32K-6 3.52GB/s ± 1% 3.53GB/s ± 1% ~ (p=0.529 n=10+10) Match/Easy0/1M-6 2.28GB/s ± 1% 2.28GB/s ± 1% ~ (p=0.853 n=10+10) Match/Easy0/32M-6 2.24GB/s ± 0% 2.23GB/s ± 0% -0.76% (p=0.000 n=9+8) Match/Easy0i/32-6 15.2MB/s ± 1% 16.2MB/s ± 0% +6.43% (p=0.000 n=10+9) Match/Easy0i/1K-6 16.6MB/s ± 0% 17.9MB/s ± 0% +7.48% (p=0.000 n=10+9) Match/Easy0i/32K-6 11.9MB/s ± 0% 12.0MB/s ± 0% +1.11% (p=0.000 n=9+9) Match/Easy0i/1M-6 11.9MB/s ± 0% 12.1MB/s ± 1% +1.31% (p=0.000 n=8+10) Match/Easy0i/32M-6 11.9MB/s ± 0% 12.1MB/s ± 1% +1.84% (p=0.000 n=8+10) Match/Easy1/32-6 260MB/s ± 1% 258MB/s ± 1% -0.91% (p=0.001 n=10+10) Match/Easy1/1K-6 601MB/s ± 1% 621MB/s ± 0% +3.28% (p=0.000 n=9+10) Match/Easy1/32K-6 474MB/s ± 0% 479MB/s ± 1% +0.96% (p=0.000 n=8+10) Match/Easy1/1M-6 426MB/s ± 1% 433MB/s ± 1% +1.68% (p=0.000 n=10+10) Match/Easy1/32M-6 428MB/s ± 1% 433MB/s ± 0% +1.09% (p=0.000 n=10+9) Match/Medium/32-6 15.4MB/s ± 1% 16.7MB/s ± 1% +8.23% (p=0.000 n=10+9) Match/Medium/1K-6 16.3MB/s ± 1% 17.7MB/s ± 1% +8.43% (p=0.000 n=9+10) Match/Medium/32K-6 12.5MB/s ± 1% 12.7MB/s ± 1% +2.15% (p=0.000 n=10+10) Match/Medium/1M-6 12.4MB/s ± 0% 12.7MB/s ± 0% +2.44% (p=0.000 n=8+9) Match/Medium/32M-6 12.4MB/s ± 0% 12.7MB/s ± 0% +2.52% (p=0.000 n=10+9) Match/Hard/32-6 9.82MB/s ± 1% 10.73MB/s ± 1% +9.29% (p=0.000 n=10+10) Match/Hard/1K-6 10.2MB/s ± 0% 11.3MB/s ± 1% +10.56% (p=0.000 n=9+10) Match/Hard/32K-6 8.58MB/s ± 0% 8.58MB/s ± 1% ~ (p=0.554 n=8+10) Match/Hard/1M-6 8.59MB/s ± 1% 8.53MB/s ± 0% -0.70% (p=0.000 n=10+8) Match/Hard/32M-6 8.62MB/s ± 1% 8.59MB/s ± 1% ~ (p=0.098 n=10+10) Match/Hard1/32-6 1.77MB/s ± 1% 1.99MB/s ± 1% +12.40% (p=0.000 n=10+8) Match/Hard1/1K-6 1.81MB/s ± 1% 2.08MB/s ± 1% +14.55% (p=0.000 n=10+10) Match/Hard1/32K-6 1.74MB/s ± 0% 1.74MB/s ± 0% ~ (p=0.108 n=9+10) Match/Hard1/1M-6 1.74MB/s ± 0% 1.74MB/s ± 1% ~ (p=1.000 n=9+10) Match/Hard1/32M-6 1.75MB/s ± 0% 1.75MB/s ± 1% ~ (p=0.157 n=9+10) Match_onepass_regex/32-6 5.05MB/s ± 0% 5.05MB/s ± 1% ~ (p=0.262 n=8+10) Match_onepass_regex/1K-6 5.02MB/s ± 1% 5.02MB/s ± 1% ~ (p=0.677 n=9+10) Match_onepass_regex/32K-6 5.02MB/s ± 0% 4.99MB/s ± 0% -0.47% (p=0.000 n=10+9) Match_onepass_regex/1M-6 5.01MB/s ± 0% 5.04MB/s ± 1% +0.68% (p=0.017 n=8+10) Match_onepass_regex/32M-6 4.99MB/s ± 0% 5.03MB/s ± 1% +0.74% (p=0.000 n=10+10) [Geo mean] 29.1MB/s 29.8MB/s +2.44% go1 data for reference name old time/op new time/op delta BinaryTree17-6 4.39s ± 1% 4.37s ± 0% -0.58% (p=0.006 n=9+9) Fannkuch11-6 5.13s ± 0% 5.18s ± 0% +0.87% (p=0.000 n=8+8) FmtFprintfEmpty-6 74.2ns ± 0% 71.7ns ± 3% -3.41% (p=0.000 n=10+10) FmtFprintfString-6 120ns ± 1% 122ns ± 2% ~ (p=0.333 n=10+10) FmtFprintfInt-6 127ns ± 1% 127ns ± 1% ~ (p=0.809 n=10+10) FmtFprintfIntInt-6 186ns ± 0% 188ns ± 1% +1.02% (p=0.002 n=8+10) FmtFprintfPrefixedInt-6 223ns ± 1% 222ns ± 2% ~ (p=0.421 n=10+10) FmtFprintfFloat-6 374ns ± 0% 376ns ± 1% +0.43% (p=0.030 n=8+10) FmtManyArgs-6 795ns ± 0% 788ns ± 1% -0.79% (p=0.000 n=8+9) GobDecode-6 10.9ms ± 1% 10.9ms ± 0% ~ (p=0.079 n=10+9) GobEncode-6 8.60ms ± 1% 8.56ms ± 0% -0.52% (p=0.004 n=10+10) Gzip-6 378ms ± 1% 386ms ± 1% +2.28% (p=0.000 n=10+10) Gunzip-6 63.7ms ± 0% 62.3ms ± 0% -2.22% (p=0.000 n=9+8) HTTPClientServer-6 120µs ± 3% 114µs ± 3% -4.99% (p=0.000 n=10+10) JSONEncode-6 20.3ms ± 1% 19.9ms ± 0% -1.90% (p=0.000 n=9+10) JSONDecode-6 84.3ms ± 0% 83.7ms ± 0% -0.76% (p=0.000 n=8+8) Mandelbrot200-6 6.91ms ± 0% 6.89ms ± 0% -0.31% (p=0.000 n=9+8) GoParse-6 5.49ms ± 0% 5.47ms ± 1% ~ (p=0.101 n=8+10) RegexpMatchEasy0_32-6 130ns ± 0% 128ns ± 0% -1.54% (p=0.002 n=8+10) RegexpMatchEasy0_1K-6 322ns ± 1% 322ns ± 0% ~ (p=0.525 n=10+9) RegexpMatchEasy1_32-6 124ns ± 0% 124ns ± 0% -0.32% (p=0.046 n=8+10) RegexpMatchEasy1_1K-6 570ns ± 0% 548ns ± 1% -3.76% (p=0.000 n=10+10) RegexpMatchMedium_32-6 196ns ± 0% 183ns ± 1% -6.61% (p=0.000 n=8+10) RegexpMatchMedium_1K-6 64.3µs ± 0% 59.0µs ± 1% -8.31% (p=0.000 n=8+10) RegexpMatchHard_32-6 3.08µs ± 0% 2.80µs ± 0% -8.96% (p=0.000 n=8+9) RegexpMatchHard_1K-6 93.0µs ± 0% 84.5µs ± 1% -9.17% (p=0.000 n=8+9) Revcomp-6 647ms ± 2% 646ms ± 1% ~ (p=0.720 n=10+9) Template-6 92.3ms ± 0% 91.7ms ± 0% -0.65% (p=0.000 n=8+8) TimeParse-6 490ns ± 0% 488ns ± 0% -0.43% (p=0.000 n=10+10) TimeFormat-6 513ns ± 0% 513ns ± 1% ~ (p=0.144 n=9+10) [Geo mean] 79.1µs 77.7µs -1.73% name old speed new speed delta GobDecode-6 70.1MB/s ± 1% 70.3MB/s ± 0% ~ (p=0.078 n=10+9) GobEncode-6 89.2MB/s ± 1% 89.7MB/s ± 0% +0.52% (p=0.004 n=10+10) Gzip-6 51.4MB/s ± 1% 50.2MB/s ± 1% -2.23% (p=0.000 n=10+10) Gunzip-6 304MB/s ± 0% 311MB/s ± 0% +2.27% (p=0.000 n=9+8) JSONEncode-6 95.8MB/s ± 1% 97.7MB/s ± 0% +1.93% (p=0.000 n=9+10) JSONDecode-6 23.0MB/s ± 0% 23.2MB/s ± 0% +0.76% (p=0.000 n=8+8) GoParse-6 10.6MB/s ± 0% 10.6MB/s ± 1% ~ (p=0.111 n=8+10) RegexpMatchEasy0_32-6 244MB/s ± 0% 249MB/s ± 0% +2.06% (p=0.000 n=9+10) RegexpMatchEasy0_1K-6 3.18GB/s ± 1% 3.17GB/s ± 0% ~ (p=0.211 n=10+9) RegexpMatchEasy1_32-6 257MB/s ± 0% 258MB/s ± 0% +0.37% (p=0.000 n=8+8) RegexpMatchEasy1_1K-6 1.80GB/s ± 0% 1.87GB/s ± 1% +3.91% (p=0.000 n=10+10) RegexpMatchMedium_32-6 5.08MB/s ± 0% 5.43MB/s ± 1% +7.03% (p=0.000 n=8+10) RegexpMatchMedium_1K-6 15.9MB/s ± 0% 17.4MB/s ± 1% +9.08% (p=0.000 n=8+10) RegexpMatchHard_32-6 10.4MB/s ± 0% 11.4MB/s ± 0% +9.82% (p=0.000 n=8+9) RegexpMatchHard_1K-6 11.0MB/s ± 0% 12.1MB/s ± 1% +10.10% (p=0.000 n=8+9) Revcomp-6 393MB/s ± 2% 394MB/s ± 1% ~ (p=0.720 n=10+9) Template-6 21.0MB/s ± 0% 21.2MB/s ± 0% +0.66% (p=0.000 n=8+8) [Geo mean] 74.2MB/s 76.2MB/s +2.70% Updates #21851 Change-Id: Ie88455db925f422a828f8528293790726a9c036b Reviewed-on: https://go-review.googlesource.com/65491 Run-TryBot: Ilya Tocar <ilya.tocar@intel.com> Reviewed-by: Daniel Martí <mvdan@mvdan.cc> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2017-09-22 15:15:23 -05:00
arg bool
regexp: port RE2's bitstate backtracker to the regexp package This is a port of RE2's bitstate backtracker, which triggers under the same conditions that the RE2 backtracker triggers. However I wasn't sure how to port over some of the optimizations in the RE2 backtracker, and there is a ~2% penalty on benchmarks that don't trigger the backtracker. benchmark old ns/op new ns/op delta BenchmarkLiteral 312 189 -39.42% BenchmarkNotLiteral 4435 3001 -32.33% BenchmarkMatchClass 5758 4378 -23.97% BenchmarkMatchClass_InRange 5385 4084 -24.16% BenchmarkReplaceAll 5291 3505 -33.76% BenchmarkAnchoredLiteralShortNonMatch 190 200 +5.26% BenchmarkAnchoredLiteralLongNonMatch 189 194 +2.65% BenchmarkAnchoredShortMatch 479 304 -36.53% BenchmarkAnchoredLongMatch 478 499 +4.39% BenchmarkOnePassShortA 791 798 +0.88% BenchmarkNotOnePassShortA 3202 1571 -50.94% BenchmarkOnePassShortB 614 633 +3.09% BenchmarkNotOnePassShortB 2685 881 -67.19% BenchmarkOnePassLongPrefix 152 154 +1.32% BenchmarkOnePassLongNotPrefix 505 533 +5.54% BenchmarkMatchEasy0_32 139 171 +23.02% BenchmarkMatchEasy0_1K 653 1797 +175.19% BenchmarkMatchEasy0_32K 12032 13346 +10.92% BenchmarkMatchEasy0_1M 462882 461272 -0.35% BenchmarkMatchEasy0_32M 15015339 15365238 +2.33% BenchmarkMatchEasy1_32 122 168 +37.70% BenchmarkMatchEasy1_1K 3339 2612 -21.77% BenchmarkMatchEasy1_32K 72330 71721 -0.84% BenchmarkMatchEasy1_1M 2545410 2652284 +4.20% BenchmarkMatchEasy1_32M 80072063 82609750 +3.17% BenchmarkMatchMedium_32 2359 1980 -16.07% BenchmarkMatchMedium_1K 75939 58593 -22.84% BenchmarkMatchMedium_32K 2450907 2501106 +2.05% BenchmarkMatchMedium_1M 78707697 80174418 +1.86% BenchmarkMatchMedium_32M 2535146010 2570896441 +1.41% BenchmarkMatchHard_32 4297 2960 -31.11% BenchmarkMatchHard_1K 133592 88997 -33.38% BenchmarkMatchHard_32K 4240445 4336907 +2.27% BenchmarkMatchHard_1M 136187006 139350238 +2.32% BenchmarkMatchHard_32M 4350855890 4478537306 +2.93% benchmark old MB/s new MB/s speedup BenchmarkMatchEasy0_32 228.74 186.11 0.81x BenchmarkMatchEasy0_1K 1565.91 569.64 0.36x BenchmarkMatchEasy0_32K 2723.31 2455.10 0.90x BenchmarkMatchEasy0_1M 2265.32 2273.22 1.00x BenchmarkMatchEasy0_32M 2234.68 2183.79 0.98x BenchmarkMatchEasy1_32 261.08 190.22 0.73x BenchmarkMatchEasy1_1K 306.59 391.91 1.28x BenchmarkMatchEasy1_32K 453.03 456.88 1.01x BenchmarkMatchEasy1_1M 411.95 395.35 0.96x BenchmarkMatchEasy1_32M 419.05 406.18 0.97x BenchmarkMatchMedium_32 13.56 16.16 1.19x BenchmarkMatchMedium_1K 13.48 17.48 1.30x BenchmarkMatchMedium_32K 13.37 13.10 0.98x BenchmarkMatchMedium_1M 13.32 13.08 0.98x BenchmarkMatchMedium_32M 13.24 13.05 0.99x BenchmarkMatchHard_32 7.45 10.81 1.45x BenchmarkMatchHard_1K 7.67 11.51 1.50x BenchmarkMatchHard_32K 7.73 7.56 0.98x BenchmarkMatchHard_1M 7.70 7.52 0.98x BenchmarkMatchHard_32M 7.71 7.49 0.97x Fixes #4154 Change-Id: Iff7fb9507f0872b320d08afc08679751ed1b28bc Reviewed-on: https://go-review.googlesource.com/2153 Reviewed-by: Russ Cox <rsc@golang.org>
2014-12-28 00:17:01 -08:00
pos int
}
const (
visitedBits = 32
maxBacktrackProg = 500 // len(prog.Inst) <= max
maxBacktrackVector = 256 * 1024 // bit vector size <= max (bits)
)
// bitState holds state for the backtracker.
type bitState struct {
regexp: split bit-state execution out of machine struct This allows the bit-state executions to have their own pool of allocated structures. A step toward eliminating the per-Regexp machine cache. Note especially the -92% on MatchParallelShared. This is real but not a complete story: the other execution engines still need to be de-shared, but the benchmark was only using bit-state. The tiny slowdowns in unrelated code are noise. name old time/op new time/op delta Find-12 264ns ± 3% 254ns ± 0% -3.86% (p=0.000 n=10+9) FindAllNoMatches-12 140ns ± 2% 135ns ± 0% -3.91% (p=0.000 n=10+9) FindString-12 256ns ± 0% 247ns ± 0% -3.52% (p=0.000 n=8+8) FindSubmatch-12 339ns ± 1% 334ns ± 0% -1.41% (p=0.000 n=9+10) FindStringSubmatch-12 322ns ± 0% 321ns ± 0% -0.21% (p=0.005 n=8+9) Literal-12 100ns ± 2% 92ns ± 0% -8.10% (p=0.000 n=10+9) NotLiteral-12 1.50µs ± 0% 1.47µs ± 0% -1.91% (p=0.000 n=8+9) MatchClass-12 2.18µs ± 0% 2.17µs ± 0% -0.20% (p=0.001 n=10+7) MatchClass_InRange-12 2.12µs ± 0% 2.13µs ± 0% +0.23% (p=0.000 n=10+10) ReplaceAll-12 1.41µs ± 0% 1.39µs ± 0% -1.30% (p=0.000 n=7+10) AnchoredLiteralShortNonMatch-12 89.8ns ± 0% 83.2ns ± 0% -7.35% (p=0.000 n=8+8) AnchoredLiteralLongNonMatch-12 105ns ± 3% 105ns ± 0% ~ (p=0.186 n=10+10) AnchoredShortMatch-12 141ns ± 0% 131ns ± 0% -7.09% (p=0.000 n=9+10) AnchoredLongMatch-12 276ns ± 4% 267ns ± 0% -3.23% (p=0.000 n=10+10) OnePassShortA-12 620ns ± 0% 611ns ± 0% -1.39% (p=0.000 n=10+9) NotOnePassShortA-12 575ns ± 3% 552ns ± 0% -3.97% (p=0.000 n=10+8) OnePassShortB-12 493ns ± 0% 491ns ± 0% -0.33% (p=0.000 n=8+8) NotOnePassShortB-12 423ns ± 0% 412ns ± 0% -2.60% (p=0.000 n=8+9) OnePassLongPrefix-12 112ns ± 0% 112ns ± 0% ~ (all equal) OnePassLongNotPrefix-12 405ns ± 0% 410ns ± 0% +1.23% (p=0.000 n=8+9) MatchParallelShared-12 501ns ± 1% 39ns ± 1% -92.27% (p=0.000 n=10+10) MatchParallelCopied-12 39.1ns ± 0% 39.2ns ± 3% ~ (p=0.785 n=6+10) QuoteMetaAll-12 94.6ns ± 0% 94.6ns ± 0% ~ (p=0.439 n=10+8) QuoteMetaNone-12 52.7ns ± 0% 52.7ns ± 0% ~ (all equal) Match/Easy0/32-12 79.1ns ± 0% 72.9ns ± 0% -7.85% (p=0.000 n=9+9) Match/Easy0/1K-12 307ns ± 1% 298ns ± 0% -2.99% (p=0.000 n=10+6) Match/Easy0/32K-12 4.65µs ± 2% 4.60µs ± 2% ~ (p=0.159 n=10+10) Match/Easy0/1M-12 234µs ± 0% 235µs ± 0% +0.17% (p=0.003 n=10+10) Match/Easy0/32M-12 7.98ms ± 1% 7.96ms ± 0% ~ (p=0.278 n=9+10) Match/Easy0i/32-12 1.13µs ± 1% 1.09µs ± 0% -3.24% (p=0.000 n=9+8) Match/Easy0i/1K-12 32.5µs ± 0% 31.7µs ± 0% -2.66% (p=0.000 n=9+9) Match/Easy0i/32K-12 1.59ms ± 0% 1.61ms ± 0% +0.75% (p=0.000 n=9+9) Match/Easy0i/1M-12 51.0ms ± 0% 51.4ms ± 0% +0.77% (p=0.000 n=10+8) Match/Easy0i/32M-12 1.63s ± 0% 1.65s ± 1% +1.24% (p=0.000 n=7+9) Match/Easy1/32-12 75.1ns ± 1% 67.9ns ± 0% -9.54% (p=0.000 n=8+8) Match/Easy1/1K-12 861ns ± 0% 884ns ± 0% +2.71% (p=0.000 n=8+9) Match/Easy1/32K-12 39.2µs ± 1% 39.2µs ± 0% ~ (p=0.090 n=10+9) Match/Easy1/1M-12 1.38ms ± 0% 1.39ms ± 0% ~ (p=0.095 n=10+9) Match/Easy1/32M-12 44.2ms ± 1% 44.2ms ± 1% ~ (p=0.218 n=10+10) Match/Medium/32-12 1.04µs ± 1% 1.05µs ± 0% +1.05% (p=0.000 n=9+8) Match/Medium/1K-12 31.3µs ± 0% 31.3µs ± 0% -0.14% (p=0.004 n=9+9) Match/Medium/32K-12 1.44ms ± 0% 1.45ms ± 0% +0.18% (p=0.001 n=8+8) Match/Medium/1M-12 46.1ms ± 0% 46.2ms ± 0% +0.13% (p=0.003 n=6+9) Match/Medium/32M-12 1.48s ± 0% 1.48s ± 0% +0.20% (p=0.002 n=9+8) Match/Hard/32-12 1.54µs ± 1% 1.49µs ± 0% -3.60% (p=0.000 n=9+10) Match/Hard/1K-12 46.4µs ± 1% 45.1µs ± 1% -2.78% (p=0.000 n=9+10) Match/Hard/32K-12 2.19ms ± 0% 2.18ms ± 1% -0.51% (p=0.006 n=8+9) Match/Hard/1M-12 70.1ms ± 0% 69.7ms ± 1% -0.52% (p=0.006 n=8+9) Match/Hard/32M-12 2.24s ± 0% 2.23s ± 1% -0.42% (p=0.046 n=8+9) Match/Hard1/32-12 8.17µs ± 1% 7.89µs ± 0% -3.42% (p=0.000 n=8+9) Match/Hard1/1K-12 254µs ± 2% 244µs ± 0% -3.91% (p=0.000 n=9+9) Match/Hard1/32K-12 9.58ms ± 1% 10.35ms ± 0% +8.00% (p=0.000 n=10+10) Match/Hard1/1M-12 306ms ± 1% 331ms ± 0% +8.27% (p=0.000 n=9+8) Match/Hard1/32M-12 9.79s ± 1% 10.60s ± 0% +8.29% (p=0.000 n=9+8) Match_onepass_regex/32-12 808ns ± 0% 812ns ± 0% +0.47% (p=0.000 n=8+10) Match_onepass_regex/1K-12 27.8µs ± 0% 28.5µs ± 0% +2.32% (p=0.000 n=8+10) Match_onepass_regex/32K-12 925µs ± 0% 936µs ± 0% +1.24% (p=0.000 n=9+10) Match_onepass_regex/1M-12 29.5ms ± 0% 30.2ms ± 0% +2.38% (p=0.000 n=10+10) Match_onepass_regex/32M-12 945ms ± 0% 970ms ± 0% +2.60% (p=0.000 n=9+10) CompileOnepass-12 4.67µs ± 0% 4.63µs ± 1% -0.84% (p=0.000 n=10+10) [Geo mean] 24.5µs 23.3µs -5.04% https://perf.golang.org/search?q=upload:20181004.1 Change-Id: Idbc2b76223718265657819ff38be2d9aba1c54b4 Reviewed-on: https://go-review.googlesource.com/c/139779 Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-09-28 16:37:16 -04:00
end int
cap []int
matchcap []int
jobs []job
visited []uint32
inputs inputs
}
var bitStatePool sync.Pool
regexp: port RE2's bitstate backtracker to the regexp package This is a port of RE2's bitstate backtracker, which triggers under the same conditions that the RE2 backtracker triggers. However I wasn't sure how to port over some of the optimizations in the RE2 backtracker, and there is a ~2% penalty on benchmarks that don't trigger the backtracker. benchmark old ns/op new ns/op delta BenchmarkLiteral 312 189 -39.42% BenchmarkNotLiteral 4435 3001 -32.33% BenchmarkMatchClass 5758 4378 -23.97% BenchmarkMatchClass_InRange 5385 4084 -24.16% BenchmarkReplaceAll 5291 3505 -33.76% BenchmarkAnchoredLiteralShortNonMatch 190 200 +5.26% BenchmarkAnchoredLiteralLongNonMatch 189 194 +2.65% BenchmarkAnchoredShortMatch 479 304 -36.53% BenchmarkAnchoredLongMatch 478 499 +4.39% BenchmarkOnePassShortA 791 798 +0.88% BenchmarkNotOnePassShortA 3202 1571 -50.94% BenchmarkOnePassShortB 614 633 +3.09% BenchmarkNotOnePassShortB 2685 881 -67.19% BenchmarkOnePassLongPrefix 152 154 +1.32% BenchmarkOnePassLongNotPrefix 505 533 +5.54% BenchmarkMatchEasy0_32 139 171 +23.02% BenchmarkMatchEasy0_1K 653 1797 +175.19% BenchmarkMatchEasy0_32K 12032 13346 +10.92% BenchmarkMatchEasy0_1M 462882 461272 -0.35% BenchmarkMatchEasy0_32M 15015339 15365238 +2.33% BenchmarkMatchEasy1_32 122 168 +37.70% BenchmarkMatchEasy1_1K 3339 2612 -21.77% BenchmarkMatchEasy1_32K 72330 71721 -0.84% BenchmarkMatchEasy1_1M 2545410 2652284 +4.20% BenchmarkMatchEasy1_32M 80072063 82609750 +3.17% BenchmarkMatchMedium_32 2359 1980 -16.07% BenchmarkMatchMedium_1K 75939 58593 -22.84% BenchmarkMatchMedium_32K 2450907 2501106 +2.05% BenchmarkMatchMedium_1M 78707697 80174418 +1.86% BenchmarkMatchMedium_32M 2535146010 2570896441 +1.41% BenchmarkMatchHard_32 4297 2960 -31.11% BenchmarkMatchHard_1K 133592 88997 -33.38% BenchmarkMatchHard_32K 4240445 4336907 +2.27% BenchmarkMatchHard_1M 136187006 139350238 +2.32% BenchmarkMatchHard_32M 4350855890 4478537306 +2.93% benchmark old MB/s new MB/s speedup BenchmarkMatchEasy0_32 228.74 186.11 0.81x BenchmarkMatchEasy0_1K 1565.91 569.64 0.36x BenchmarkMatchEasy0_32K 2723.31 2455.10 0.90x BenchmarkMatchEasy0_1M 2265.32 2273.22 1.00x BenchmarkMatchEasy0_32M 2234.68 2183.79 0.98x BenchmarkMatchEasy1_32 261.08 190.22 0.73x BenchmarkMatchEasy1_1K 306.59 391.91 1.28x BenchmarkMatchEasy1_32K 453.03 456.88 1.01x BenchmarkMatchEasy1_1M 411.95 395.35 0.96x BenchmarkMatchEasy1_32M 419.05 406.18 0.97x BenchmarkMatchMedium_32 13.56 16.16 1.19x BenchmarkMatchMedium_1K 13.48 17.48 1.30x BenchmarkMatchMedium_32K 13.37 13.10 0.98x BenchmarkMatchMedium_1M 13.32 13.08 0.98x BenchmarkMatchMedium_32M 13.24 13.05 0.99x BenchmarkMatchHard_32 7.45 10.81 1.45x BenchmarkMatchHard_1K 7.67 11.51 1.50x BenchmarkMatchHard_32K 7.73 7.56 0.98x BenchmarkMatchHard_1M 7.70 7.52 0.98x BenchmarkMatchHard_32M 7.71 7.49 0.97x Fixes #4154 Change-Id: Iff7fb9507f0872b320d08afc08679751ed1b28bc Reviewed-on: https://go-review.googlesource.com/2153 Reviewed-by: Russ Cox <rsc@golang.org>
2014-12-28 00:17:01 -08:00
regexp: split bit-state execution out of machine struct This allows the bit-state executions to have their own pool of allocated structures. A step toward eliminating the per-Regexp machine cache. Note especially the -92% on MatchParallelShared. This is real but not a complete story: the other execution engines still need to be de-shared, but the benchmark was only using bit-state. The tiny slowdowns in unrelated code are noise. name old time/op new time/op delta Find-12 264ns ± 3% 254ns ± 0% -3.86% (p=0.000 n=10+9) FindAllNoMatches-12 140ns ± 2% 135ns ± 0% -3.91% (p=0.000 n=10+9) FindString-12 256ns ± 0% 247ns ± 0% -3.52% (p=0.000 n=8+8) FindSubmatch-12 339ns ± 1% 334ns ± 0% -1.41% (p=0.000 n=9+10) FindStringSubmatch-12 322ns ± 0% 321ns ± 0% -0.21% (p=0.005 n=8+9) Literal-12 100ns ± 2% 92ns ± 0% -8.10% (p=0.000 n=10+9) NotLiteral-12 1.50µs ± 0% 1.47µs ± 0% -1.91% (p=0.000 n=8+9) MatchClass-12 2.18µs ± 0% 2.17µs ± 0% -0.20% (p=0.001 n=10+7) MatchClass_InRange-12 2.12µs ± 0% 2.13µs ± 0% +0.23% (p=0.000 n=10+10) ReplaceAll-12 1.41µs ± 0% 1.39µs ± 0% -1.30% (p=0.000 n=7+10) AnchoredLiteralShortNonMatch-12 89.8ns ± 0% 83.2ns ± 0% -7.35% (p=0.000 n=8+8) AnchoredLiteralLongNonMatch-12 105ns ± 3% 105ns ± 0% ~ (p=0.186 n=10+10) AnchoredShortMatch-12 141ns ± 0% 131ns ± 0% -7.09% (p=0.000 n=9+10) AnchoredLongMatch-12 276ns ± 4% 267ns ± 0% -3.23% (p=0.000 n=10+10) OnePassShortA-12 620ns ± 0% 611ns ± 0% -1.39% (p=0.000 n=10+9) NotOnePassShortA-12 575ns ± 3% 552ns ± 0% -3.97% (p=0.000 n=10+8) OnePassShortB-12 493ns ± 0% 491ns ± 0% -0.33% (p=0.000 n=8+8) NotOnePassShortB-12 423ns ± 0% 412ns ± 0% -2.60% (p=0.000 n=8+9) OnePassLongPrefix-12 112ns ± 0% 112ns ± 0% ~ (all equal) OnePassLongNotPrefix-12 405ns ± 0% 410ns ± 0% +1.23% (p=0.000 n=8+9) MatchParallelShared-12 501ns ± 1% 39ns ± 1% -92.27% (p=0.000 n=10+10) MatchParallelCopied-12 39.1ns ± 0% 39.2ns ± 3% ~ (p=0.785 n=6+10) QuoteMetaAll-12 94.6ns ± 0% 94.6ns ± 0% ~ (p=0.439 n=10+8) QuoteMetaNone-12 52.7ns ± 0% 52.7ns ± 0% ~ (all equal) Match/Easy0/32-12 79.1ns ± 0% 72.9ns ± 0% -7.85% (p=0.000 n=9+9) Match/Easy0/1K-12 307ns ± 1% 298ns ± 0% -2.99% (p=0.000 n=10+6) Match/Easy0/32K-12 4.65µs ± 2% 4.60µs ± 2% ~ (p=0.159 n=10+10) Match/Easy0/1M-12 234µs ± 0% 235µs ± 0% +0.17% (p=0.003 n=10+10) Match/Easy0/32M-12 7.98ms ± 1% 7.96ms ± 0% ~ (p=0.278 n=9+10) Match/Easy0i/32-12 1.13µs ± 1% 1.09µs ± 0% -3.24% (p=0.000 n=9+8) Match/Easy0i/1K-12 32.5µs ± 0% 31.7µs ± 0% -2.66% (p=0.000 n=9+9) Match/Easy0i/32K-12 1.59ms ± 0% 1.61ms ± 0% +0.75% (p=0.000 n=9+9) Match/Easy0i/1M-12 51.0ms ± 0% 51.4ms ± 0% +0.77% (p=0.000 n=10+8) Match/Easy0i/32M-12 1.63s ± 0% 1.65s ± 1% +1.24% (p=0.000 n=7+9) Match/Easy1/32-12 75.1ns ± 1% 67.9ns ± 0% -9.54% (p=0.000 n=8+8) Match/Easy1/1K-12 861ns ± 0% 884ns ± 0% +2.71% (p=0.000 n=8+9) Match/Easy1/32K-12 39.2µs ± 1% 39.2µs ± 0% ~ (p=0.090 n=10+9) Match/Easy1/1M-12 1.38ms ± 0% 1.39ms ± 0% ~ (p=0.095 n=10+9) Match/Easy1/32M-12 44.2ms ± 1% 44.2ms ± 1% ~ (p=0.218 n=10+10) Match/Medium/32-12 1.04µs ± 1% 1.05µs ± 0% +1.05% (p=0.000 n=9+8) Match/Medium/1K-12 31.3µs ± 0% 31.3µs ± 0% -0.14% (p=0.004 n=9+9) Match/Medium/32K-12 1.44ms ± 0% 1.45ms ± 0% +0.18% (p=0.001 n=8+8) Match/Medium/1M-12 46.1ms ± 0% 46.2ms ± 0% +0.13% (p=0.003 n=6+9) Match/Medium/32M-12 1.48s ± 0% 1.48s ± 0% +0.20% (p=0.002 n=9+8) Match/Hard/32-12 1.54µs ± 1% 1.49µs ± 0% -3.60% (p=0.000 n=9+10) Match/Hard/1K-12 46.4µs ± 1% 45.1µs ± 1% -2.78% (p=0.000 n=9+10) Match/Hard/32K-12 2.19ms ± 0% 2.18ms ± 1% -0.51% (p=0.006 n=8+9) Match/Hard/1M-12 70.1ms ± 0% 69.7ms ± 1% -0.52% (p=0.006 n=8+9) Match/Hard/32M-12 2.24s ± 0% 2.23s ± 1% -0.42% (p=0.046 n=8+9) Match/Hard1/32-12 8.17µs ± 1% 7.89µs ± 0% -3.42% (p=0.000 n=8+9) Match/Hard1/1K-12 254µs ± 2% 244µs ± 0% -3.91% (p=0.000 n=9+9) Match/Hard1/32K-12 9.58ms ± 1% 10.35ms ± 0% +8.00% (p=0.000 n=10+10) Match/Hard1/1M-12 306ms ± 1% 331ms ± 0% +8.27% (p=0.000 n=9+8) Match/Hard1/32M-12 9.79s ± 1% 10.60s ± 0% +8.29% (p=0.000 n=9+8) Match_onepass_regex/32-12 808ns ± 0% 812ns ± 0% +0.47% (p=0.000 n=8+10) Match_onepass_regex/1K-12 27.8µs ± 0% 28.5µs ± 0% +2.32% (p=0.000 n=8+10) Match_onepass_regex/32K-12 925µs ± 0% 936µs ± 0% +1.24% (p=0.000 n=9+10) Match_onepass_regex/1M-12 29.5ms ± 0% 30.2ms ± 0% +2.38% (p=0.000 n=10+10) Match_onepass_regex/32M-12 945ms ± 0% 970ms ± 0% +2.60% (p=0.000 n=9+10) CompileOnepass-12 4.67µs ± 0% 4.63µs ± 1% -0.84% (p=0.000 n=10+10) [Geo mean] 24.5µs 23.3µs -5.04% https://perf.golang.org/search?q=upload:20181004.1 Change-Id: Idbc2b76223718265657819ff38be2d9aba1c54b4 Reviewed-on: https://go-review.googlesource.com/c/139779 Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-09-28 16:37:16 -04:00
func newBitState() *bitState {
b, ok := bitStatePool.Get().(*bitState)
if !ok {
b = new(bitState)
}
return b
regexp: port RE2's bitstate backtracker to the regexp package This is a port of RE2's bitstate backtracker, which triggers under the same conditions that the RE2 backtracker triggers. However I wasn't sure how to port over some of the optimizations in the RE2 backtracker, and there is a ~2% penalty on benchmarks that don't trigger the backtracker. benchmark old ns/op new ns/op delta BenchmarkLiteral 312 189 -39.42% BenchmarkNotLiteral 4435 3001 -32.33% BenchmarkMatchClass 5758 4378 -23.97% BenchmarkMatchClass_InRange 5385 4084 -24.16% BenchmarkReplaceAll 5291 3505 -33.76% BenchmarkAnchoredLiteralShortNonMatch 190 200 +5.26% BenchmarkAnchoredLiteralLongNonMatch 189 194 +2.65% BenchmarkAnchoredShortMatch 479 304 -36.53% BenchmarkAnchoredLongMatch 478 499 +4.39% BenchmarkOnePassShortA 791 798 +0.88% BenchmarkNotOnePassShortA 3202 1571 -50.94% BenchmarkOnePassShortB 614 633 +3.09% BenchmarkNotOnePassShortB 2685 881 -67.19% BenchmarkOnePassLongPrefix 152 154 +1.32% BenchmarkOnePassLongNotPrefix 505 533 +5.54% BenchmarkMatchEasy0_32 139 171 +23.02% BenchmarkMatchEasy0_1K 653 1797 +175.19% BenchmarkMatchEasy0_32K 12032 13346 +10.92% BenchmarkMatchEasy0_1M 462882 461272 -0.35% BenchmarkMatchEasy0_32M 15015339 15365238 +2.33% BenchmarkMatchEasy1_32 122 168 +37.70% BenchmarkMatchEasy1_1K 3339 2612 -21.77% BenchmarkMatchEasy1_32K 72330 71721 -0.84% BenchmarkMatchEasy1_1M 2545410 2652284 +4.20% BenchmarkMatchEasy1_32M 80072063 82609750 +3.17% BenchmarkMatchMedium_32 2359 1980 -16.07% BenchmarkMatchMedium_1K 75939 58593 -22.84% BenchmarkMatchMedium_32K 2450907 2501106 +2.05% BenchmarkMatchMedium_1M 78707697 80174418 +1.86% BenchmarkMatchMedium_32M 2535146010 2570896441 +1.41% BenchmarkMatchHard_32 4297 2960 -31.11% BenchmarkMatchHard_1K 133592 88997 -33.38% BenchmarkMatchHard_32K 4240445 4336907 +2.27% BenchmarkMatchHard_1M 136187006 139350238 +2.32% BenchmarkMatchHard_32M 4350855890 4478537306 +2.93% benchmark old MB/s new MB/s speedup BenchmarkMatchEasy0_32 228.74 186.11 0.81x BenchmarkMatchEasy0_1K 1565.91 569.64 0.36x BenchmarkMatchEasy0_32K 2723.31 2455.10 0.90x BenchmarkMatchEasy0_1M 2265.32 2273.22 1.00x BenchmarkMatchEasy0_32M 2234.68 2183.79 0.98x BenchmarkMatchEasy1_32 261.08 190.22 0.73x BenchmarkMatchEasy1_1K 306.59 391.91 1.28x BenchmarkMatchEasy1_32K 453.03 456.88 1.01x BenchmarkMatchEasy1_1M 411.95 395.35 0.96x BenchmarkMatchEasy1_32M 419.05 406.18 0.97x BenchmarkMatchMedium_32 13.56 16.16 1.19x BenchmarkMatchMedium_1K 13.48 17.48 1.30x BenchmarkMatchMedium_32K 13.37 13.10 0.98x BenchmarkMatchMedium_1M 13.32 13.08 0.98x BenchmarkMatchMedium_32M 13.24 13.05 0.99x BenchmarkMatchHard_32 7.45 10.81 1.45x BenchmarkMatchHard_1K 7.67 11.51 1.50x BenchmarkMatchHard_32K 7.73 7.56 0.98x BenchmarkMatchHard_1M 7.70 7.52 0.98x BenchmarkMatchHard_32M 7.71 7.49 0.97x Fixes #4154 Change-Id: Iff7fb9507f0872b320d08afc08679751ed1b28bc Reviewed-on: https://go-review.googlesource.com/2153 Reviewed-by: Russ Cox <rsc@golang.org>
2014-12-28 00:17:01 -08:00
}
regexp: split bit-state execution out of machine struct This allows the bit-state executions to have their own pool of allocated structures. A step toward eliminating the per-Regexp machine cache. Note especially the -92% on MatchParallelShared. This is real but not a complete story: the other execution engines still need to be de-shared, but the benchmark was only using bit-state. The tiny slowdowns in unrelated code are noise. name old time/op new time/op delta Find-12 264ns ± 3% 254ns ± 0% -3.86% (p=0.000 n=10+9) FindAllNoMatches-12 140ns ± 2% 135ns ± 0% -3.91% (p=0.000 n=10+9) FindString-12 256ns ± 0% 247ns ± 0% -3.52% (p=0.000 n=8+8) FindSubmatch-12 339ns ± 1% 334ns ± 0% -1.41% (p=0.000 n=9+10) FindStringSubmatch-12 322ns ± 0% 321ns ± 0% -0.21% (p=0.005 n=8+9) Literal-12 100ns ± 2% 92ns ± 0% -8.10% (p=0.000 n=10+9) NotLiteral-12 1.50µs ± 0% 1.47µs ± 0% -1.91% (p=0.000 n=8+9) MatchClass-12 2.18µs ± 0% 2.17µs ± 0% -0.20% (p=0.001 n=10+7) MatchClass_InRange-12 2.12µs ± 0% 2.13µs ± 0% +0.23% (p=0.000 n=10+10) ReplaceAll-12 1.41µs ± 0% 1.39µs ± 0% -1.30% (p=0.000 n=7+10) AnchoredLiteralShortNonMatch-12 89.8ns ± 0% 83.2ns ± 0% -7.35% (p=0.000 n=8+8) AnchoredLiteralLongNonMatch-12 105ns ± 3% 105ns ± 0% ~ (p=0.186 n=10+10) AnchoredShortMatch-12 141ns ± 0% 131ns ± 0% -7.09% (p=0.000 n=9+10) AnchoredLongMatch-12 276ns ± 4% 267ns ± 0% -3.23% (p=0.000 n=10+10) OnePassShortA-12 620ns ± 0% 611ns ± 0% -1.39% (p=0.000 n=10+9) NotOnePassShortA-12 575ns ± 3% 552ns ± 0% -3.97% (p=0.000 n=10+8) OnePassShortB-12 493ns ± 0% 491ns ± 0% -0.33% (p=0.000 n=8+8) NotOnePassShortB-12 423ns ± 0% 412ns ± 0% -2.60% (p=0.000 n=8+9) OnePassLongPrefix-12 112ns ± 0% 112ns ± 0% ~ (all equal) OnePassLongNotPrefix-12 405ns ± 0% 410ns ± 0% +1.23% (p=0.000 n=8+9) MatchParallelShared-12 501ns ± 1% 39ns ± 1% -92.27% (p=0.000 n=10+10) MatchParallelCopied-12 39.1ns ± 0% 39.2ns ± 3% ~ (p=0.785 n=6+10) QuoteMetaAll-12 94.6ns ± 0% 94.6ns ± 0% ~ (p=0.439 n=10+8) QuoteMetaNone-12 52.7ns ± 0% 52.7ns ± 0% ~ (all equal) Match/Easy0/32-12 79.1ns ± 0% 72.9ns ± 0% -7.85% (p=0.000 n=9+9) Match/Easy0/1K-12 307ns ± 1% 298ns ± 0% -2.99% (p=0.000 n=10+6) Match/Easy0/32K-12 4.65µs ± 2% 4.60µs ± 2% ~ (p=0.159 n=10+10) Match/Easy0/1M-12 234µs ± 0% 235µs ± 0% +0.17% (p=0.003 n=10+10) Match/Easy0/32M-12 7.98ms ± 1% 7.96ms ± 0% ~ (p=0.278 n=9+10) Match/Easy0i/32-12 1.13µs ± 1% 1.09µs ± 0% -3.24% (p=0.000 n=9+8) Match/Easy0i/1K-12 32.5µs ± 0% 31.7µs ± 0% -2.66% (p=0.000 n=9+9) Match/Easy0i/32K-12 1.59ms ± 0% 1.61ms ± 0% +0.75% (p=0.000 n=9+9) Match/Easy0i/1M-12 51.0ms ± 0% 51.4ms ± 0% +0.77% (p=0.000 n=10+8) Match/Easy0i/32M-12 1.63s ± 0% 1.65s ± 1% +1.24% (p=0.000 n=7+9) Match/Easy1/32-12 75.1ns ± 1% 67.9ns ± 0% -9.54% (p=0.000 n=8+8) Match/Easy1/1K-12 861ns ± 0% 884ns ± 0% +2.71% (p=0.000 n=8+9) Match/Easy1/32K-12 39.2µs ± 1% 39.2µs ± 0% ~ (p=0.090 n=10+9) Match/Easy1/1M-12 1.38ms ± 0% 1.39ms ± 0% ~ (p=0.095 n=10+9) Match/Easy1/32M-12 44.2ms ± 1% 44.2ms ± 1% ~ (p=0.218 n=10+10) Match/Medium/32-12 1.04µs ± 1% 1.05µs ± 0% +1.05% (p=0.000 n=9+8) Match/Medium/1K-12 31.3µs ± 0% 31.3µs ± 0% -0.14% (p=0.004 n=9+9) Match/Medium/32K-12 1.44ms ± 0% 1.45ms ± 0% +0.18% (p=0.001 n=8+8) Match/Medium/1M-12 46.1ms ± 0% 46.2ms ± 0% +0.13% (p=0.003 n=6+9) Match/Medium/32M-12 1.48s ± 0% 1.48s ± 0% +0.20% (p=0.002 n=9+8) Match/Hard/32-12 1.54µs ± 1% 1.49µs ± 0% -3.60% (p=0.000 n=9+10) Match/Hard/1K-12 46.4µs ± 1% 45.1µs ± 1% -2.78% (p=0.000 n=9+10) Match/Hard/32K-12 2.19ms ± 0% 2.18ms ± 1% -0.51% (p=0.006 n=8+9) Match/Hard/1M-12 70.1ms ± 0% 69.7ms ± 1% -0.52% (p=0.006 n=8+9) Match/Hard/32M-12 2.24s ± 0% 2.23s ± 1% -0.42% (p=0.046 n=8+9) Match/Hard1/32-12 8.17µs ± 1% 7.89µs ± 0% -3.42% (p=0.000 n=8+9) Match/Hard1/1K-12 254µs ± 2% 244µs ± 0% -3.91% (p=0.000 n=9+9) Match/Hard1/32K-12 9.58ms ± 1% 10.35ms ± 0% +8.00% (p=0.000 n=10+10) Match/Hard1/1M-12 306ms ± 1% 331ms ± 0% +8.27% (p=0.000 n=9+8) Match/Hard1/32M-12 9.79s ± 1% 10.60s ± 0% +8.29% (p=0.000 n=9+8) Match_onepass_regex/32-12 808ns ± 0% 812ns ± 0% +0.47% (p=0.000 n=8+10) Match_onepass_regex/1K-12 27.8µs ± 0% 28.5µs ± 0% +2.32% (p=0.000 n=8+10) Match_onepass_regex/32K-12 925µs ± 0% 936µs ± 0% +1.24% (p=0.000 n=9+10) Match_onepass_regex/1M-12 29.5ms ± 0% 30.2ms ± 0% +2.38% (p=0.000 n=10+10) Match_onepass_regex/32M-12 945ms ± 0% 970ms ± 0% +2.60% (p=0.000 n=9+10) CompileOnepass-12 4.67µs ± 0% 4.63µs ± 1% -0.84% (p=0.000 n=10+10) [Geo mean] 24.5µs 23.3µs -5.04% https://perf.golang.org/search?q=upload:20181004.1 Change-Id: Idbc2b76223718265657819ff38be2d9aba1c54b4 Reviewed-on: https://go-review.googlesource.com/c/139779 Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-09-28 16:37:16 -04:00
func freeBitState(b *bitState) {
b.inputs.clear()
bitStatePool.Put(b)
}
regexp: port RE2's bitstate backtracker to the regexp package This is a port of RE2's bitstate backtracker, which triggers under the same conditions that the RE2 backtracker triggers. However I wasn't sure how to port over some of the optimizations in the RE2 backtracker, and there is a ~2% penalty on benchmarks that don't trigger the backtracker. benchmark old ns/op new ns/op delta BenchmarkLiteral 312 189 -39.42% BenchmarkNotLiteral 4435 3001 -32.33% BenchmarkMatchClass 5758 4378 -23.97% BenchmarkMatchClass_InRange 5385 4084 -24.16% BenchmarkReplaceAll 5291 3505 -33.76% BenchmarkAnchoredLiteralShortNonMatch 190 200 +5.26% BenchmarkAnchoredLiteralLongNonMatch 189 194 +2.65% BenchmarkAnchoredShortMatch 479 304 -36.53% BenchmarkAnchoredLongMatch 478 499 +4.39% BenchmarkOnePassShortA 791 798 +0.88% BenchmarkNotOnePassShortA 3202 1571 -50.94% BenchmarkOnePassShortB 614 633 +3.09% BenchmarkNotOnePassShortB 2685 881 -67.19% BenchmarkOnePassLongPrefix 152 154 +1.32% BenchmarkOnePassLongNotPrefix 505 533 +5.54% BenchmarkMatchEasy0_32 139 171 +23.02% BenchmarkMatchEasy0_1K 653 1797 +175.19% BenchmarkMatchEasy0_32K 12032 13346 +10.92% BenchmarkMatchEasy0_1M 462882 461272 -0.35% BenchmarkMatchEasy0_32M 15015339 15365238 +2.33% BenchmarkMatchEasy1_32 122 168 +37.70% BenchmarkMatchEasy1_1K 3339 2612 -21.77% BenchmarkMatchEasy1_32K 72330 71721 -0.84% BenchmarkMatchEasy1_1M 2545410 2652284 +4.20% BenchmarkMatchEasy1_32M 80072063 82609750 +3.17% BenchmarkMatchMedium_32 2359 1980 -16.07% BenchmarkMatchMedium_1K 75939 58593 -22.84% BenchmarkMatchMedium_32K 2450907 2501106 +2.05% BenchmarkMatchMedium_1M 78707697 80174418 +1.86% BenchmarkMatchMedium_32M 2535146010 2570896441 +1.41% BenchmarkMatchHard_32 4297 2960 -31.11% BenchmarkMatchHard_1K 133592 88997 -33.38% BenchmarkMatchHard_32K 4240445 4336907 +2.27% BenchmarkMatchHard_1M 136187006 139350238 +2.32% BenchmarkMatchHard_32M 4350855890 4478537306 +2.93% benchmark old MB/s new MB/s speedup BenchmarkMatchEasy0_32 228.74 186.11 0.81x BenchmarkMatchEasy0_1K 1565.91 569.64 0.36x BenchmarkMatchEasy0_32K 2723.31 2455.10 0.90x BenchmarkMatchEasy0_1M 2265.32 2273.22 1.00x BenchmarkMatchEasy0_32M 2234.68 2183.79 0.98x BenchmarkMatchEasy1_32 261.08 190.22 0.73x BenchmarkMatchEasy1_1K 306.59 391.91 1.28x BenchmarkMatchEasy1_32K 453.03 456.88 1.01x BenchmarkMatchEasy1_1M 411.95 395.35 0.96x BenchmarkMatchEasy1_32M 419.05 406.18 0.97x BenchmarkMatchMedium_32 13.56 16.16 1.19x BenchmarkMatchMedium_1K 13.48 17.48 1.30x BenchmarkMatchMedium_32K 13.37 13.10 0.98x BenchmarkMatchMedium_1M 13.32 13.08 0.98x BenchmarkMatchMedium_32M 13.24 13.05 0.99x BenchmarkMatchHard_32 7.45 10.81 1.45x BenchmarkMatchHard_1K 7.67 11.51 1.50x BenchmarkMatchHard_32K 7.73 7.56 0.98x BenchmarkMatchHard_1M 7.70 7.52 0.98x BenchmarkMatchHard_32M 7.71 7.49 0.97x Fixes #4154 Change-Id: Iff7fb9507f0872b320d08afc08679751ed1b28bc Reviewed-on: https://go-review.googlesource.com/2153 Reviewed-by: Russ Cox <rsc@golang.org>
2014-12-28 00:17:01 -08:00
// maxBitStateLen returns the maximum length of a string to search with
// the backtracker using prog.
func maxBitStateLen(prog *syntax.Prog) int {
if !shouldBacktrack(prog) {
return 0
}
regexp: port RE2's bitstate backtracker to the regexp package This is a port of RE2's bitstate backtracker, which triggers under the same conditions that the RE2 backtracker triggers. However I wasn't sure how to port over some of the optimizations in the RE2 backtracker, and there is a ~2% penalty on benchmarks that don't trigger the backtracker. benchmark old ns/op new ns/op delta BenchmarkLiteral 312 189 -39.42% BenchmarkNotLiteral 4435 3001 -32.33% BenchmarkMatchClass 5758 4378 -23.97% BenchmarkMatchClass_InRange 5385 4084 -24.16% BenchmarkReplaceAll 5291 3505 -33.76% BenchmarkAnchoredLiteralShortNonMatch 190 200 +5.26% BenchmarkAnchoredLiteralLongNonMatch 189 194 +2.65% BenchmarkAnchoredShortMatch 479 304 -36.53% BenchmarkAnchoredLongMatch 478 499 +4.39% BenchmarkOnePassShortA 791 798 +0.88% BenchmarkNotOnePassShortA 3202 1571 -50.94% BenchmarkOnePassShortB 614 633 +3.09% BenchmarkNotOnePassShortB 2685 881 -67.19% BenchmarkOnePassLongPrefix 152 154 +1.32% BenchmarkOnePassLongNotPrefix 505 533 +5.54% BenchmarkMatchEasy0_32 139 171 +23.02% BenchmarkMatchEasy0_1K 653 1797 +175.19% BenchmarkMatchEasy0_32K 12032 13346 +10.92% BenchmarkMatchEasy0_1M 462882 461272 -0.35% BenchmarkMatchEasy0_32M 15015339 15365238 +2.33% BenchmarkMatchEasy1_32 122 168 +37.70% BenchmarkMatchEasy1_1K 3339 2612 -21.77% BenchmarkMatchEasy1_32K 72330 71721 -0.84% BenchmarkMatchEasy1_1M 2545410 2652284 +4.20% BenchmarkMatchEasy1_32M 80072063 82609750 +3.17% BenchmarkMatchMedium_32 2359 1980 -16.07% BenchmarkMatchMedium_1K 75939 58593 -22.84% BenchmarkMatchMedium_32K 2450907 2501106 +2.05% BenchmarkMatchMedium_1M 78707697 80174418 +1.86% BenchmarkMatchMedium_32M 2535146010 2570896441 +1.41% BenchmarkMatchHard_32 4297 2960 -31.11% BenchmarkMatchHard_1K 133592 88997 -33.38% BenchmarkMatchHard_32K 4240445 4336907 +2.27% BenchmarkMatchHard_1M 136187006 139350238 +2.32% BenchmarkMatchHard_32M 4350855890 4478537306 +2.93% benchmark old MB/s new MB/s speedup BenchmarkMatchEasy0_32 228.74 186.11 0.81x BenchmarkMatchEasy0_1K 1565.91 569.64 0.36x BenchmarkMatchEasy0_32K 2723.31 2455.10 0.90x BenchmarkMatchEasy0_1M 2265.32 2273.22 1.00x BenchmarkMatchEasy0_32M 2234.68 2183.79 0.98x BenchmarkMatchEasy1_32 261.08 190.22 0.73x BenchmarkMatchEasy1_1K 306.59 391.91 1.28x BenchmarkMatchEasy1_32K 453.03 456.88 1.01x BenchmarkMatchEasy1_1M 411.95 395.35 0.96x BenchmarkMatchEasy1_32M 419.05 406.18 0.97x BenchmarkMatchMedium_32 13.56 16.16 1.19x BenchmarkMatchMedium_1K 13.48 17.48 1.30x BenchmarkMatchMedium_32K 13.37 13.10 0.98x BenchmarkMatchMedium_1M 13.32 13.08 0.98x BenchmarkMatchMedium_32M 13.24 13.05 0.99x BenchmarkMatchHard_32 7.45 10.81 1.45x BenchmarkMatchHard_1K 7.67 11.51 1.50x BenchmarkMatchHard_32K 7.73 7.56 0.98x BenchmarkMatchHard_1M 7.70 7.52 0.98x BenchmarkMatchHard_32M 7.71 7.49 0.97x Fixes #4154 Change-Id: Iff7fb9507f0872b320d08afc08679751ed1b28bc Reviewed-on: https://go-review.googlesource.com/2153 Reviewed-by: Russ Cox <rsc@golang.org>
2014-12-28 00:17:01 -08:00
return maxBacktrackVector / len(prog.Inst)
}
// shouldBacktrack reports whether the program is too
// long for the backtracker to run.
func shouldBacktrack(prog *syntax.Prog) bool {
return len(prog.Inst) <= maxBacktrackProg
}
regexp: port RE2's bitstate backtracker to the regexp package This is a port of RE2's bitstate backtracker, which triggers under the same conditions that the RE2 backtracker triggers. However I wasn't sure how to port over some of the optimizations in the RE2 backtracker, and there is a ~2% penalty on benchmarks that don't trigger the backtracker. benchmark old ns/op new ns/op delta BenchmarkLiteral 312 189 -39.42% BenchmarkNotLiteral 4435 3001 -32.33% BenchmarkMatchClass 5758 4378 -23.97% BenchmarkMatchClass_InRange 5385 4084 -24.16% BenchmarkReplaceAll 5291 3505 -33.76% BenchmarkAnchoredLiteralShortNonMatch 190 200 +5.26% BenchmarkAnchoredLiteralLongNonMatch 189 194 +2.65% BenchmarkAnchoredShortMatch 479 304 -36.53% BenchmarkAnchoredLongMatch 478 499 +4.39% BenchmarkOnePassShortA 791 798 +0.88% BenchmarkNotOnePassShortA 3202 1571 -50.94% BenchmarkOnePassShortB 614 633 +3.09% BenchmarkNotOnePassShortB 2685 881 -67.19% BenchmarkOnePassLongPrefix 152 154 +1.32% BenchmarkOnePassLongNotPrefix 505 533 +5.54% BenchmarkMatchEasy0_32 139 171 +23.02% BenchmarkMatchEasy0_1K 653 1797 +175.19% BenchmarkMatchEasy0_32K 12032 13346 +10.92% BenchmarkMatchEasy0_1M 462882 461272 -0.35% BenchmarkMatchEasy0_32M 15015339 15365238 +2.33% BenchmarkMatchEasy1_32 122 168 +37.70% BenchmarkMatchEasy1_1K 3339 2612 -21.77% BenchmarkMatchEasy1_32K 72330 71721 -0.84% BenchmarkMatchEasy1_1M 2545410 2652284 +4.20% BenchmarkMatchEasy1_32M 80072063 82609750 +3.17% BenchmarkMatchMedium_32 2359 1980 -16.07% BenchmarkMatchMedium_1K 75939 58593 -22.84% BenchmarkMatchMedium_32K 2450907 2501106 +2.05% BenchmarkMatchMedium_1M 78707697 80174418 +1.86% BenchmarkMatchMedium_32M 2535146010 2570896441 +1.41% BenchmarkMatchHard_32 4297 2960 -31.11% BenchmarkMatchHard_1K 133592 88997 -33.38% BenchmarkMatchHard_32K 4240445 4336907 +2.27% BenchmarkMatchHard_1M 136187006 139350238 +2.32% BenchmarkMatchHard_32M 4350855890 4478537306 +2.93% benchmark old MB/s new MB/s speedup BenchmarkMatchEasy0_32 228.74 186.11 0.81x BenchmarkMatchEasy0_1K 1565.91 569.64 0.36x BenchmarkMatchEasy0_32K 2723.31 2455.10 0.90x BenchmarkMatchEasy0_1M 2265.32 2273.22 1.00x BenchmarkMatchEasy0_32M 2234.68 2183.79 0.98x BenchmarkMatchEasy1_32 261.08 190.22 0.73x BenchmarkMatchEasy1_1K 306.59 391.91 1.28x BenchmarkMatchEasy1_32K 453.03 456.88 1.01x BenchmarkMatchEasy1_1M 411.95 395.35 0.96x BenchmarkMatchEasy1_32M 419.05 406.18 0.97x BenchmarkMatchMedium_32 13.56 16.16 1.19x BenchmarkMatchMedium_1K 13.48 17.48 1.30x BenchmarkMatchMedium_32K 13.37 13.10 0.98x BenchmarkMatchMedium_1M 13.32 13.08 0.98x BenchmarkMatchMedium_32M 13.24 13.05 0.99x BenchmarkMatchHard_32 7.45 10.81 1.45x BenchmarkMatchHard_1K 7.67 11.51 1.50x BenchmarkMatchHard_32K 7.73 7.56 0.98x BenchmarkMatchHard_1M 7.70 7.52 0.98x BenchmarkMatchHard_32M 7.71 7.49 0.97x Fixes #4154 Change-Id: Iff7fb9507f0872b320d08afc08679751ed1b28bc Reviewed-on: https://go-review.googlesource.com/2153 Reviewed-by: Russ Cox <rsc@golang.org>
2014-12-28 00:17:01 -08:00
// reset resets the state of the backtracker.
// end is the end position in the input.
// ncap is the number of captures.
regexp: split bit-state execution out of machine struct This allows the bit-state executions to have their own pool of allocated structures. A step toward eliminating the per-Regexp machine cache. Note especially the -92% on MatchParallelShared. This is real but not a complete story: the other execution engines still need to be de-shared, but the benchmark was only using bit-state. The tiny slowdowns in unrelated code are noise. name old time/op new time/op delta Find-12 264ns ± 3% 254ns ± 0% -3.86% (p=0.000 n=10+9) FindAllNoMatches-12 140ns ± 2% 135ns ± 0% -3.91% (p=0.000 n=10+9) FindString-12 256ns ± 0% 247ns ± 0% -3.52% (p=0.000 n=8+8) FindSubmatch-12 339ns ± 1% 334ns ± 0% -1.41% (p=0.000 n=9+10) FindStringSubmatch-12 322ns ± 0% 321ns ± 0% -0.21% (p=0.005 n=8+9) Literal-12 100ns ± 2% 92ns ± 0% -8.10% (p=0.000 n=10+9) NotLiteral-12 1.50µs ± 0% 1.47µs ± 0% -1.91% (p=0.000 n=8+9) MatchClass-12 2.18µs ± 0% 2.17µs ± 0% -0.20% (p=0.001 n=10+7) MatchClass_InRange-12 2.12µs ± 0% 2.13µs ± 0% +0.23% (p=0.000 n=10+10) ReplaceAll-12 1.41µs ± 0% 1.39µs ± 0% -1.30% (p=0.000 n=7+10) AnchoredLiteralShortNonMatch-12 89.8ns ± 0% 83.2ns ± 0% -7.35% (p=0.000 n=8+8) AnchoredLiteralLongNonMatch-12 105ns ± 3% 105ns ± 0% ~ (p=0.186 n=10+10) AnchoredShortMatch-12 141ns ± 0% 131ns ± 0% -7.09% (p=0.000 n=9+10) AnchoredLongMatch-12 276ns ± 4% 267ns ± 0% -3.23% (p=0.000 n=10+10) OnePassShortA-12 620ns ± 0% 611ns ± 0% -1.39% (p=0.000 n=10+9) NotOnePassShortA-12 575ns ± 3% 552ns ± 0% -3.97% (p=0.000 n=10+8) OnePassShortB-12 493ns ± 0% 491ns ± 0% -0.33% (p=0.000 n=8+8) NotOnePassShortB-12 423ns ± 0% 412ns ± 0% -2.60% (p=0.000 n=8+9) OnePassLongPrefix-12 112ns ± 0% 112ns ± 0% ~ (all equal) OnePassLongNotPrefix-12 405ns ± 0% 410ns ± 0% +1.23% (p=0.000 n=8+9) MatchParallelShared-12 501ns ± 1% 39ns ± 1% -92.27% (p=0.000 n=10+10) MatchParallelCopied-12 39.1ns ± 0% 39.2ns ± 3% ~ (p=0.785 n=6+10) QuoteMetaAll-12 94.6ns ± 0% 94.6ns ± 0% ~ (p=0.439 n=10+8) QuoteMetaNone-12 52.7ns ± 0% 52.7ns ± 0% ~ (all equal) Match/Easy0/32-12 79.1ns ± 0% 72.9ns ± 0% -7.85% (p=0.000 n=9+9) Match/Easy0/1K-12 307ns ± 1% 298ns ± 0% -2.99% (p=0.000 n=10+6) Match/Easy0/32K-12 4.65µs ± 2% 4.60µs ± 2% ~ (p=0.159 n=10+10) Match/Easy0/1M-12 234µs ± 0% 235µs ± 0% +0.17% (p=0.003 n=10+10) Match/Easy0/32M-12 7.98ms ± 1% 7.96ms ± 0% ~ (p=0.278 n=9+10) Match/Easy0i/32-12 1.13µs ± 1% 1.09µs ± 0% -3.24% (p=0.000 n=9+8) Match/Easy0i/1K-12 32.5µs ± 0% 31.7µs ± 0% -2.66% (p=0.000 n=9+9) Match/Easy0i/32K-12 1.59ms ± 0% 1.61ms ± 0% +0.75% (p=0.000 n=9+9) Match/Easy0i/1M-12 51.0ms ± 0% 51.4ms ± 0% +0.77% (p=0.000 n=10+8) Match/Easy0i/32M-12 1.63s ± 0% 1.65s ± 1% +1.24% (p=0.000 n=7+9) Match/Easy1/32-12 75.1ns ± 1% 67.9ns ± 0% -9.54% (p=0.000 n=8+8) Match/Easy1/1K-12 861ns ± 0% 884ns ± 0% +2.71% (p=0.000 n=8+9) Match/Easy1/32K-12 39.2µs ± 1% 39.2µs ± 0% ~ (p=0.090 n=10+9) Match/Easy1/1M-12 1.38ms ± 0% 1.39ms ± 0% ~ (p=0.095 n=10+9) Match/Easy1/32M-12 44.2ms ± 1% 44.2ms ± 1% ~ (p=0.218 n=10+10) Match/Medium/32-12 1.04µs ± 1% 1.05µs ± 0% +1.05% (p=0.000 n=9+8) Match/Medium/1K-12 31.3µs ± 0% 31.3µs ± 0% -0.14% (p=0.004 n=9+9) Match/Medium/32K-12 1.44ms ± 0% 1.45ms ± 0% +0.18% (p=0.001 n=8+8) Match/Medium/1M-12 46.1ms ± 0% 46.2ms ± 0% +0.13% (p=0.003 n=6+9) Match/Medium/32M-12 1.48s ± 0% 1.48s ± 0% +0.20% (p=0.002 n=9+8) Match/Hard/32-12 1.54µs ± 1% 1.49µs ± 0% -3.60% (p=0.000 n=9+10) Match/Hard/1K-12 46.4µs ± 1% 45.1µs ± 1% -2.78% (p=0.000 n=9+10) Match/Hard/32K-12 2.19ms ± 0% 2.18ms ± 1% -0.51% (p=0.006 n=8+9) Match/Hard/1M-12 70.1ms ± 0% 69.7ms ± 1% -0.52% (p=0.006 n=8+9) Match/Hard/32M-12 2.24s ± 0% 2.23s ± 1% -0.42% (p=0.046 n=8+9) Match/Hard1/32-12 8.17µs ± 1% 7.89µs ± 0% -3.42% (p=0.000 n=8+9) Match/Hard1/1K-12 254µs ± 2% 244µs ± 0% -3.91% (p=0.000 n=9+9) Match/Hard1/32K-12 9.58ms ± 1% 10.35ms ± 0% +8.00% (p=0.000 n=10+10) Match/Hard1/1M-12 306ms ± 1% 331ms ± 0% +8.27% (p=0.000 n=9+8) Match/Hard1/32M-12 9.79s ± 1% 10.60s ± 0% +8.29% (p=0.000 n=9+8) Match_onepass_regex/32-12 808ns ± 0% 812ns ± 0% +0.47% (p=0.000 n=8+10) Match_onepass_regex/1K-12 27.8µs ± 0% 28.5µs ± 0% +2.32% (p=0.000 n=8+10) Match_onepass_regex/32K-12 925µs ± 0% 936µs ± 0% +1.24% (p=0.000 n=9+10) Match_onepass_regex/1M-12 29.5ms ± 0% 30.2ms ± 0% +2.38% (p=0.000 n=10+10) Match_onepass_regex/32M-12 945ms ± 0% 970ms ± 0% +2.60% (p=0.000 n=9+10) CompileOnepass-12 4.67µs ± 0% 4.63µs ± 1% -0.84% (p=0.000 n=10+10) [Geo mean] 24.5µs 23.3µs -5.04% https://perf.golang.org/search?q=upload:20181004.1 Change-Id: Idbc2b76223718265657819ff38be2d9aba1c54b4 Reviewed-on: https://go-review.googlesource.com/c/139779 Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-09-28 16:37:16 -04:00
func (b *bitState) reset(prog *syntax.Prog, end int, ncap int) {
regexp: port RE2's bitstate backtracker to the regexp package This is a port of RE2's bitstate backtracker, which triggers under the same conditions that the RE2 backtracker triggers. However I wasn't sure how to port over some of the optimizations in the RE2 backtracker, and there is a ~2% penalty on benchmarks that don't trigger the backtracker. benchmark old ns/op new ns/op delta BenchmarkLiteral 312 189 -39.42% BenchmarkNotLiteral 4435 3001 -32.33% BenchmarkMatchClass 5758 4378 -23.97% BenchmarkMatchClass_InRange 5385 4084 -24.16% BenchmarkReplaceAll 5291 3505 -33.76% BenchmarkAnchoredLiteralShortNonMatch 190 200 +5.26% BenchmarkAnchoredLiteralLongNonMatch 189 194 +2.65% BenchmarkAnchoredShortMatch 479 304 -36.53% BenchmarkAnchoredLongMatch 478 499 +4.39% BenchmarkOnePassShortA 791 798 +0.88% BenchmarkNotOnePassShortA 3202 1571 -50.94% BenchmarkOnePassShortB 614 633 +3.09% BenchmarkNotOnePassShortB 2685 881 -67.19% BenchmarkOnePassLongPrefix 152 154 +1.32% BenchmarkOnePassLongNotPrefix 505 533 +5.54% BenchmarkMatchEasy0_32 139 171 +23.02% BenchmarkMatchEasy0_1K 653 1797 +175.19% BenchmarkMatchEasy0_32K 12032 13346 +10.92% BenchmarkMatchEasy0_1M 462882 461272 -0.35% BenchmarkMatchEasy0_32M 15015339 15365238 +2.33% BenchmarkMatchEasy1_32 122 168 +37.70% BenchmarkMatchEasy1_1K 3339 2612 -21.77% BenchmarkMatchEasy1_32K 72330 71721 -0.84% BenchmarkMatchEasy1_1M 2545410 2652284 +4.20% BenchmarkMatchEasy1_32M 80072063 82609750 +3.17% BenchmarkMatchMedium_32 2359 1980 -16.07% BenchmarkMatchMedium_1K 75939 58593 -22.84% BenchmarkMatchMedium_32K 2450907 2501106 +2.05% BenchmarkMatchMedium_1M 78707697 80174418 +1.86% BenchmarkMatchMedium_32M 2535146010 2570896441 +1.41% BenchmarkMatchHard_32 4297 2960 -31.11% BenchmarkMatchHard_1K 133592 88997 -33.38% BenchmarkMatchHard_32K 4240445 4336907 +2.27% BenchmarkMatchHard_1M 136187006 139350238 +2.32% BenchmarkMatchHard_32M 4350855890 4478537306 +2.93% benchmark old MB/s new MB/s speedup BenchmarkMatchEasy0_32 228.74 186.11 0.81x BenchmarkMatchEasy0_1K 1565.91 569.64 0.36x BenchmarkMatchEasy0_32K 2723.31 2455.10 0.90x BenchmarkMatchEasy0_1M 2265.32 2273.22 1.00x BenchmarkMatchEasy0_32M 2234.68 2183.79 0.98x BenchmarkMatchEasy1_32 261.08 190.22 0.73x BenchmarkMatchEasy1_1K 306.59 391.91 1.28x BenchmarkMatchEasy1_32K 453.03 456.88 1.01x BenchmarkMatchEasy1_1M 411.95 395.35 0.96x BenchmarkMatchEasy1_32M 419.05 406.18 0.97x BenchmarkMatchMedium_32 13.56 16.16 1.19x BenchmarkMatchMedium_1K 13.48 17.48 1.30x BenchmarkMatchMedium_32K 13.37 13.10 0.98x BenchmarkMatchMedium_1M 13.32 13.08 0.98x BenchmarkMatchMedium_32M 13.24 13.05 0.99x BenchmarkMatchHard_32 7.45 10.81 1.45x BenchmarkMatchHard_1K 7.67 11.51 1.50x BenchmarkMatchHard_32K 7.73 7.56 0.98x BenchmarkMatchHard_1M 7.70 7.52 0.98x BenchmarkMatchHard_32M 7.71 7.49 0.97x Fixes #4154 Change-Id: Iff7fb9507f0872b320d08afc08679751ed1b28bc Reviewed-on: https://go-review.googlesource.com/2153 Reviewed-by: Russ Cox <rsc@golang.org>
2014-12-28 00:17:01 -08:00
b.end = end
if cap(b.jobs) == 0 {
b.jobs = make([]job, 0, 256)
} else {
b.jobs = b.jobs[:0]
}
regexp: split bit-state execution out of machine struct This allows the bit-state executions to have their own pool of allocated structures. A step toward eliminating the per-Regexp machine cache. Note especially the -92% on MatchParallelShared. This is real but not a complete story: the other execution engines still need to be de-shared, but the benchmark was only using bit-state. The tiny slowdowns in unrelated code are noise. name old time/op new time/op delta Find-12 264ns ± 3% 254ns ± 0% -3.86% (p=0.000 n=10+9) FindAllNoMatches-12 140ns ± 2% 135ns ± 0% -3.91% (p=0.000 n=10+9) FindString-12 256ns ± 0% 247ns ± 0% -3.52% (p=0.000 n=8+8) FindSubmatch-12 339ns ± 1% 334ns ± 0% -1.41% (p=0.000 n=9+10) FindStringSubmatch-12 322ns ± 0% 321ns ± 0% -0.21% (p=0.005 n=8+9) Literal-12 100ns ± 2% 92ns ± 0% -8.10% (p=0.000 n=10+9) NotLiteral-12 1.50µs ± 0% 1.47µs ± 0% -1.91% (p=0.000 n=8+9) MatchClass-12 2.18µs ± 0% 2.17µs ± 0% -0.20% (p=0.001 n=10+7) MatchClass_InRange-12 2.12µs ± 0% 2.13µs ± 0% +0.23% (p=0.000 n=10+10) ReplaceAll-12 1.41µs ± 0% 1.39µs ± 0% -1.30% (p=0.000 n=7+10) AnchoredLiteralShortNonMatch-12 89.8ns ± 0% 83.2ns ± 0% -7.35% (p=0.000 n=8+8) AnchoredLiteralLongNonMatch-12 105ns ± 3% 105ns ± 0% ~ (p=0.186 n=10+10) AnchoredShortMatch-12 141ns ± 0% 131ns ± 0% -7.09% (p=0.000 n=9+10) AnchoredLongMatch-12 276ns ± 4% 267ns ± 0% -3.23% (p=0.000 n=10+10) OnePassShortA-12 620ns ± 0% 611ns ± 0% -1.39% (p=0.000 n=10+9) NotOnePassShortA-12 575ns ± 3% 552ns ± 0% -3.97% (p=0.000 n=10+8) OnePassShortB-12 493ns ± 0% 491ns ± 0% -0.33% (p=0.000 n=8+8) NotOnePassShortB-12 423ns ± 0% 412ns ± 0% -2.60% (p=0.000 n=8+9) OnePassLongPrefix-12 112ns ± 0% 112ns ± 0% ~ (all equal) OnePassLongNotPrefix-12 405ns ± 0% 410ns ± 0% +1.23% (p=0.000 n=8+9) MatchParallelShared-12 501ns ± 1% 39ns ± 1% -92.27% (p=0.000 n=10+10) MatchParallelCopied-12 39.1ns ± 0% 39.2ns ± 3% ~ (p=0.785 n=6+10) QuoteMetaAll-12 94.6ns ± 0% 94.6ns ± 0% ~ (p=0.439 n=10+8) QuoteMetaNone-12 52.7ns ± 0% 52.7ns ± 0% ~ (all equal) Match/Easy0/32-12 79.1ns ± 0% 72.9ns ± 0% -7.85% (p=0.000 n=9+9) Match/Easy0/1K-12 307ns ± 1% 298ns ± 0% -2.99% (p=0.000 n=10+6) Match/Easy0/32K-12 4.65µs ± 2% 4.60µs ± 2% ~ (p=0.159 n=10+10) Match/Easy0/1M-12 234µs ± 0% 235µs ± 0% +0.17% (p=0.003 n=10+10) Match/Easy0/32M-12 7.98ms ± 1% 7.96ms ± 0% ~ (p=0.278 n=9+10) Match/Easy0i/32-12 1.13µs ± 1% 1.09µs ± 0% -3.24% (p=0.000 n=9+8) Match/Easy0i/1K-12 32.5µs ± 0% 31.7µs ± 0% -2.66% (p=0.000 n=9+9) Match/Easy0i/32K-12 1.59ms ± 0% 1.61ms ± 0% +0.75% (p=0.000 n=9+9) Match/Easy0i/1M-12 51.0ms ± 0% 51.4ms ± 0% +0.77% (p=0.000 n=10+8) Match/Easy0i/32M-12 1.63s ± 0% 1.65s ± 1% +1.24% (p=0.000 n=7+9) Match/Easy1/32-12 75.1ns ± 1% 67.9ns ± 0% -9.54% (p=0.000 n=8+8) Match/Easy1/1K-12 861ns ± 0% 884ns ± 0% +2.71% (p=0.000 n=8+9) Match/Easy1/32K-12 39.2µs ± 1% 39.2µs ± 0% ~ (p=0.090 n=10+9) Match/Easy1/1M-12 1.38ms ± 0% 1.39ms ± 0% ~ (p=0.095 n=10+9) Match/Easy1/32M-12 44.2ms ± 1% 44.2ms ± 1% ~ (p=0.218 n=10+10) Match/Medium/32-12 1.04µs ± 1% 1.05µs ± 0% +1.05% (p=0.000 n=9+8) Match/Medium/1K-12 31.3µs ± 0% 31.3µs ± 0% -0.14% (p=0.004 n=9+9) Match/Medium/32K-12 1.44ms ± 0% 1.45ms ± 0% +0.18% (p=0.001 n=8+8) Match/Medium/1M-12 46.1ms ± 0% 46.2ms ± 0% +0.13% (p=0.003 n=6+9) Match/Medium/32M-12 1.48s ± 0% 1.48s ± 0% +0.20% (p=0.002 n=9+8) Match/Hard/32-12 1.54µs ± 1% 1.49µs ± 0% -3.60% (p=0.000 n=9+10) Match/Hard/1K-12 46.4µs ± 1% 45.1µs ± 1% -2.78% (p=0.000 n=9+10) Match/Hard/32K-12 2.19ms ± 0% 2.18ms ± 1% -0.51% (p=0.006 n=8+9) Match/Hard/1M-12 70.1ms ± 0% 69.7ms ± 1% -0.52% (p=0.006 n=8+9) Match/Hard/32M-12 2.24s ± 0% 2.23s ± 1% -0.42% (p=0.046 n=8+9) Match/Hard1/32-12 8.17µs ± 1% 7.89µs ± 0% -3.42% (p=0.000 n=8+9) Match/Hard1/1K-12 254µs ± 2% 244µs ± 0% -3.91% (p=0.000 n=9+9) Match/Hard1/32K-12 9.58ms ± 1% 10.35ms ± 0% +8.00% (p=0.000 n=10+10) Match/Hard1/1M-12 306ms ± 1% 331ms ± 0% +8.27% (p=0.000 n=9+8) Match/Hard1/32M-12 9.79s ± 1% 10.60s ± 0% +8.29% (p=0.000 n=9+8) Match_onepass_regex/32-12 808ns ± 0% 812ns ± 0% +0.47% (p=0.000 n=8+10) Match_onepass_regex/1K-12 27.8µs ± 0% 28.5µs ± 0% +2.32% (p=0.000 n=8+10) Match_onepass_regex/32K-12 925µs ± 0% 936µs ± 0% +1.24% (p=0.000 n=9+10) Match_onepass_regex/1M-12 29.5ms ± 0% 30.2ms ± 0% +2.38% (p=0.000 n=10+10) Match_onepass_regex/32M-12 945ms ± 0% 970ms ± 0% +2.60% (p=0.000 n=9+10) CompileOnepass-12 4.67µs ± 0% 4.63µs ± 1% -0.84% (p=0.000 n=10+10) [Geo mean] 24.5µs 23.3µs -5.04% https://perf.golang.org/search?q=upload:20181004.1 Change-Id: Idbc2b76223718265657819ff38be2d9aba1c54b4 Reviewed-on: https://go-review.googlesource.com/c/139779 Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-09-28 16:37:16 -04:00
visitedSize := (len(prog.Inst)*(end+1) + visitedBits - 1) / visitedBits
regexp: port RE2's bitstate backtracker to the regexp package This is a port of RE2's bitstate backtracker, which triggers under the same conditions that the RE2 backtracker triggers. However I wasn't sure how to port over some of the optimizations in the RE2 backtracker, and there is a ~2% penalty on benchmarks that don't trigger the backtracker. benchmark old ns/op new ns/op delta BenchmarkLiteral 312 189 -39.42% BenchmarkNotLiteral 4435 3001 -32.33% BenchmarkMatchClass 5758 4378 -23.97% BenchmarkMatchClass_InRange 5385 4084 -24.16% BenchmarkReplaceAll 5291 3505 -33.76% BenchmarkAnchoredLiteralShortNonMatch 190 200 +5.26% BenchmarkAnchoredLiteralLongNonMatch 189 194 +2.65% BenchmarkAnchoredShortMatch 479 304 -36.53% BenchmarkAnchoredLongMatch 478 499 +4.39% BenchmarkOnePassShortA 791 798 +0.88% BenchmarkNotOnePassShortA 3202 1571 -50.94% BenchmarkOnePassShortB 614 633 +3.09% BenchmarkNotOnePassShortB 2685 881 -67.19% BenchmarkOnePassLongPrefix 152 154 +1.32% BenchmarkOnePassLongNotPrefix 505 533 +5.54% BenchmarkMatchEasy0_32 139 171 +23.02% BenchmarkMatchEasy0_1K 653 1797 +175.19% BenchmarkMatchEasy0_32K 12032 13346 +10.92% BenchmarkMatchEasy0_1M 462882 461272 -0.35% BenchmarkMatchEasy0_32M 15015339 15365238 +2.33% BenchmarkMatchEasy1_32 122 168 +37.70% BenchmarkMatchEasy1_1K 3339 2612 -21.77% BenchmarkMatchEasy1_32K 72330 71721 -0.84% BenchmarkMatchEasy1_1M 2545410 2652284 +4.20% BenchmarkMatchEasy1_32M 80072063 82609750 +3.17% BenchmarkMatchMedium_32 2359 1980 -16.07% BenchmarkMatchMedium_1K 75939 58593 -22.84% BenchmarkMatchMedium_32K 2450907 2501106 +2.05% BenchmarkMatchMedium_1M 78707697 80174418 +1.86% BenchmarkMatchMedium_32M 2535146010 2570896441 +1.41% BenchmarkMatchHard_32 4297 2960 -31.11% BenchmarkMatchHard_1K 133592 88997 -33.38% BenchmarkMatchHard_32K 4240445 4336907 +2.27% BenchmarkMatchHard_1M 136187006 139350238 +2.32% BenchmarkMatchHard_32M 4350855890 4478537306 +2.93% benchmark old MB/s new MB/s speedup BenchmarkMatchEasy0_32 228.74 186.11 0.81x BenchmarkMatchEasy0_1K 1565.91 569.64 0.36x BenchmarkMatchEasy0_32K 2723.31 2455.10 0.90x BenchmarkMatchEasy0_1M 2265.32 2273.22 1.00x BenchmarkMatchEasy0_32M 2234.68 2183.79 0.98x BenchmarkMatchEasy1_32 261.08 190.22 0.73x BenchmarkMatchEasy1_1K 306.59 391.91 1.28x BenchmarkMatchEasy1_32K 453.03 456.88 1.01x BenchmarkMatchEasy1_1M 411.95 395.35 0.96x BenchmarkMatchEasy1_32M 419.05 406.18 0.97x BenchmarkMatchMedium_32 13.56 16.16 1.19x BenchmarkMatchMedium_1K 13.48 17.48 1.30x BenchmarkMatchMedium_32K 13.37 13.10 0.98x BenchmarkMatchMedium_1M 13.32 13.08 0.98x BenchmarkMatchMedium_32M 13.24 13.05 0.99x BenchmarkMatchHard_32 7.45 10.81 1.45x BenchmarkMatchHard_1K 7.67 11.51 1.50x BenchmarkMatchHard_32K 7.73 7.56 0.98x BenchmarkMatchHard_1M 7.70 7.52 0.98x BenchmarkMatchHard_32M 7.71 7.49 0.97x Fixes #4154 Change-Id: Iff7fb9507f0872b320d08afc08679751ed1b28bc Reviewed-on: https://go-review.googlesource.com/2153 Reviewed-by: Russ Cox <rsc@golang.org>
2014-12-28 00:17:01 -08:00
if cap(b.visited) < visitedSize {
b.visited = make([]uint32, visitedSize, maxBacktrackVector/visitedBits)
} else {
b.visited = b.visited[:visitedSize]
for i := range b.visited {
b.visited[i] = 0
}
}
if cap(b.cap) < ncap {
regexp: port RE2's bitstate backtracker to the regexp package This is a port of RE2's bitstate backtracker, which triggers under the same conditions that the RE2 backtracker triggers. However I wasn't sure how to port over some of the optimizations in the RE2 backtracker, and there is a ~2% penalty on benchmarks that don't trigger the backtracker. benchmark old ns/op new ns/op delta BenchmarkLiteral 312 189 -39.42% BenchmarkNotLiteral 4435 3001 -32.33% BenchmarkMatchClass 5758 4378 -23.97% BenchmarkMatchClass_InRange 5385 4084 -24.16% BenchmarkReplaceAll 5291 3505 -33.76% BenchmarkAnchoredLiteralShortNonMatch 190 200 +5.26% BenchmarkAnchoredLiteralLongNonMatch 189 194 +2.65% BenchmarkAnchoredShortMatch 479 304 -36.53% BenchmarkAnchoredLongMatch 478 499 +4.39% BenchmarkOnePassShortA 791 798 +0.88% BenchmarkNotOnePassShortA 3202 1571 -50.94% BenchmarkOnePassShortB 614 633 +3.09% BenchmarkNotOnePassShortB 2685 881 -67.19% BenchmarkOnePassLongPrefix 152 154 +1.32% BenchmarkOnePassLongNotPrefix 505 533 +5.54% BenchmarkMatchEasy0_32 139 171 +23.02% BenchmarkMatchEasy0_1K 653 1797 +175.19% BenchmarkMatchEasy0_32K 12032 13346 +10.92% BenchmarkMatchEasy0_1M 462882 461272 -0.35% BenchmarkMatchEasy0_32M 15015339 15365238 +2.33% BenchmarkMatchEasy1_32 122 168 +37.70% BenchmarkMatchEasy1_1K 3339 2612 -21.77% BenchmarkMatchEasy1_32K 72330 71721 -0.84% BenchmarkMatchEasy1_1M 2545410 2652284 +4.20% BenchmarkMatchEasy1_32M 80072063 82609750 +3.17% BenchmarkMatchMedium_32 2359 1980 -16.07% BenchmarkMatchMedium_1K 75939 58593 -22.84% BenchmarkMatchMedium_32K 2450907 2501106 +2.05% BenchmarkMatchMedium_1M 78707697 80174418 +1.86% BenchmarkMatchMedium_32M 2535146010 2570896441 +1.41% BenchmarkMatchHard_32 4297 2960 -31.11% BenchmarkMatchHard_1K 133592 88997 -33.38% BenchmarkMatchHard_32K 4240445 4336907 +2.27% BenchmarkMatchHard_1M 136187006 139350238 +2.32% BenchmarkMatchHard_32M 4350855890 4478537306 +2.93% benchmark old MB/s new MB/s speedup BenchmarkMatchEasy0_32 228.74 186.11 0.81x BenchmarkMatchEasy0_1K 1565.91 569.64 0.36x BenchmarkMatchEasy0_32K 2723.31 2455.10 0.90x BenchmarkMatchEasy0_1M 2265.32 2273.22 1.00x BenchmarkMatchEasy0_32M 2234.68 2183.79 0.98x BenchmarkMatchEasy1_32 261.08 190.22 0.73x BenchmarkMatchEasy1_1K 306.59 391.91 1.28x BenchmarkMatchEasy1_32K 453.03 456.88 1.01x BenchmarkMatchEasy1_1M 411.95 395.35 0.96x BenchmarkMatchEasy1_32M 419.05 406.18 0.97x BenchmarkMatchMedium_32 13.56 16.16 1.19x BenchmarkMatchMedium_1K 13.48 17.48 1.30x BenchmarkMatchMedium_32K 13.37 13.10 0.98x BenchmarkMatchMedium_1M 13.32 13.08 0.98x BenchmarkMatchMedium_32M 13.24 13.05 0.99x BenchmarkMatchHard_32 7.45 10.81 1.45x BenchmarkMatchHard_1K 7.67 11.51 1.50x BenchmarkMatchHard_32K 7.73 7.56 0.98x BenchmarkMatchHard_1M 7.70 7.52 0.98x BenchmarkMatchHard_32M 7.71 7.49 0.97x Fixes #4154 Change-Id: Iff7fb9507f0872b320d08afc08679751ed1b28bc Reviewed-on: https://go-review.googlesource.com/2153 Reviewed-by: Russ Cox <rsc@golang.org>
2014-12-28 00:17:01 -08:00
b.cap = make([]int, ncap)
} else {
b.cap = b.cap[:ncap]
regexp: port RE2's bitstate backtracker to the regexp package This is a port of RE2's bitstate backtracker, which triggers under the same conditions that the RE2 backtracker triggers. However I wasn't sure how to port over some of the optimizations in the RE2 backtracker, and there is a ~2% penalty on benchmarks that don't trigger the backtracker. benchmark old ns/op new ns/op delta BenchmarkLiteral 312 189 -39.42% BenchmarkNotLiteral 4435 3001 -32.33% BenchmarkMatchClass 5758 4378 -23.97% BenchmarkMatchClass_InRange 5385 4084 -24.16% BenchmarkReplaceAll 5291 3505 -33.76% BenchmarkAnchoredLiteralShortNonMatch 190 200 +5.26% BenchmarkAnchoredLiteralLongNonMatch 189 194 +2.65% BenchmarkAnchoredShortMatch 479 304 -36.53% BenchmarkAnchoredLongMatch 478 499 +4.39% BenchmarkOnePassShortA 791 798 +0.88% BenchmarkNotOnePassShortA 3202 1571 -50.94% BenchmarkOnePassShortB 614 633 +3.09% BenchmarkNotOnePassShortB 2685 881 -67.19% BenchmarkOnePassLongPrefix 152 154 +1.32% BenchmarkOnePassLongNotPrefix 505 533 +5.54% BenchmarkMatchEasy0_32 139 171 +23.02% BenchmarkMatchEasy0_1K 653 1797 +175.19% BenchmarkMatchEasy0_32K 12032 13346 +10.92% BenchmarkMatchEasy0_1M 462882 461272 -0.35% BenchmarkMatchEasy0_32M 15015339 15365238 +2.33% BenchmarkMatchEasy1_32 122 168 +37.70% BenchmarkMatchEasy1_1K 3339 2612 -21.77% BenchmarkMatchEasy1_32K 72330 71721 -0.84% BenchmarkMatchEasy1_1M 2545410 2652284 +4.20% BenchmarkMatchEasy1_32M 80072063 82609750 +3.17% BenchmarkMatchMedium_32 2359 1980 -16.07% BenchmarkMatchMedium_1K 75939 58593 -22.84% BenchmarkMatchMedium_32K 2450907 2501106 +2.05% BenchmarkMatchMedium_1M 78707697 80174418 +1.86% BenchmarkMatchMedium_32M 2535146010 2570896441 +1.41% BenchmarkMatchHard_32 4297 2960 -31.11% BenchmarkMatchHard_1K 133592 88997 -33.38% BenchmarkMatchHard_32K 4240445 4336907 +2.27% BenchmarkMatchHard_1M 136187006 139350238 +2.32% BenchmarkMatchHard_32M 4350855890 4478537306 +2.93% benchmark old MB/s new MB/s speedup BenchmarkMatchEasy0_32 228.74 186.11 0.81x BenchmarkMatchEasy0_1K 1565.91 569.64 0.36x BenchmarkMatchEasy0_32K 2723.31 2455.10 0.90x BenchmarkMatchEasy0_1M 2265.32 2273.22 1.00x BenchmarkMatchEasy0_32M 2234.68 2183.79 0.98x BenchmarkMatchEasy1_32 261.08 190.22 0.73x BenchmarkMatchEasy1_1K 306.59 391.91 1.28x BenchmarkMatchEasy1_32K 453.03 456.88 1.01x BenchmarkMatchEasy1_1M 411.95 395.35 0.96x BenchmarkMatchEasy1_32M 419.05 406.18 0.97x BenchmarkMatchMedium_32 13.56 16.16 1.19x BenchmarkMatchMedium_1K 13.48 17.48 1.30x BenchmarkMatchMedium_32K 13.37 13.10 0.98x BenchmarkMatchMedium_1M 13.32 13.08 0.98x BenchmarkMatchMedium_32M 13.24 13.05 0.99x BenchmarkMatchHard_32 7.45 10.81 1.45x BenchmarkMatchHard_1K 7.67 11.51 1.50x BenchmarkMatchHard_32K 7.73 7.56 0.98x BenchmarkMatchHard_1M 7.70 7.52 0.98x BenchmarkMatchHard_32M 7.71 7.49 0.97x Fixes #4154 Change-Id: Iff7fb9507f0872b320d08afc08679751ed1b28bc Reviewed-on: https://go-review.googlesource.com/2153 Reviewed-by: Russ Cox <rsc@golang.org>
2014-12-28 00:17:01 -08:00
}
for i := range b.cap {
b.cap[i] = -1
}
regexp: split bit-state execution out of machine struct This allows the bit-state executions to have their own pool of allocated structures. A step toward eliminating the per-Regexp machine cache. Note especially the -92% on MatchParallelShared. This is real but not a complete story: the other execution engines still need to be de-shared, but the benchmark was only using bit-state. The tiny slowdowns in unrelated code are noise. name old time/op new time/op delta Find-12 264ns ± 3% 254ns ± 0% -3.86% (p=0.000 n=10+9) FindAllNoMatches-12 140ns ± 2% 135ns ± 0% -3.91% (p=0.000 n=10+9) FindString-12 256ns ± 0% 247ns ± 0% -3.52% (p=0.000 n=8+8) FindSubmatch-12 339ns ± 1% 334ns ± 0% -1.41% (p=0.000 n=9+10) FindStringSubmatch-12 322ns ± 0% 321ns ± 0% -0.21% (p=0.005 n=8+9) Literal-12 100ns ± 2% 92ns ± 0% -8.10% (p=0.000 n=10+9) NotLiteral-12 1.50µs ± 0% 1.47µs ± 0% -1.91% (p=0.000 n=8+9) MatchClass-12 2.18µs ± 0% 2.17µs ± 0% -0.20% (p=0.001 n=10+7) MatchClass_InRange-12 2.12µs ± 0% 2.13µs ± 0% +0.23% (p=0.000 n=10+10) ReplaceAll-12 1.41µs ± 0% 1.39µs ± 0% -1.30% (p=0.000 n=7+10) AnchoredLiteralShortNonMatch-12 89.8ns ± 0% 83.2ns ± 0% -7.35% (p=0.000 n=8+8) AnchoredLiteralLongNonMatch-12 105ns ± 3% 105ns ± 0% ~ (p=0.186 n=10+10) AnchoredShortMatch-12 141ns ± 0% 131ns ± 0% -7.09% (p=0.000 n=9+10) AnchoredLongMatch-12 276ns ± 4% 267ns ± 0% -3.23% (p=0.000 n=10+10) OnePassShortA-12 620ns ± 0% 611ns ± 0% -1.39% (p=0.000 n=10+9) NotOnePassShortA-12 575ns ± 3% 552ns ± 0% -3.97% (p=0.000 n=10+8) OnePassShortB-12 493ns ± 0% 491ns ± 0% -0.33% (p=0.000 n=8+8) NotOnePassShortB-12 423ns ± 0% 412ns ± 0% -2.60% (p=0.000 n=8+9) OnePassLongPrefix-12 112ns ± 0% 112ns ± 0% ~ (all equal) OnePassLongNotPrefix-12 405ns ± 0% 410ns ± 0% +1.23% (p=0.000 n=8+9) MatchParallelShared-12 501ns ± 1% 39ns ± 1% -92.27% (p=0.000 n=10+10) MatchParallelCopied-12 39.1ns ± 0% 39.2ns ± 3% ~ (p=0.785 n=6+10) QuoteMetaAll-12 94.6ns ± 0% 94.6ns ± 0% ~ (p=0.439 n=10+8) QuoteMetaNone-12 52.7ns ± 0% 52.7ns ± 0% ~ (all equal) Match/Easy0/32-12 79.1ns ± 0% 72.9ns ± 0% -7.85% (p=0.000 n=9+9) Match/Easy0/1K-12 307ns ± 1% 298ns ± 0% -2.99% (p=0.000 n=10+6) Match/Easy0/32K-12 4.65µs ± 2% 4.60µs ± 2% ~ (p=0.159 n=10+10) Match/Easy0/1M-12 234µs ± 0% 235µs ± 0% +0.17% (p=0.003 n=10+10) Match/Easy0/32M-12 7.98ms ± 1% 7.96ms ± 0% ~ (p=0.278 n=9+10) Match/Easy0i/32-12 1.13µs ± 1% 1.09µs ± 0% -3.24% (p=0.000 n=9+8) Match/Easy0i/1K-12 32.5µs ± 0% 31.7µs ± 0% -2.66% (p=0.000 n=9+9) Match/Easy0i/32K-12 1.59ms ± 0% 1.61ms ± 0% +0.75% (p=0.000 n=9+9) Match/Easy0i/1M-12 51.0ms ± 0% 51.4ms ± 0% +0.77% (p=0.000 n=10+8) Match/Easy0i/32M-12 1.63s ± 0% 1.65s ± 1% +1.24% (p=0.000 n=7+9) Match/Easy1/32-12 75.1ns ± 1% 67.9ns ± 0% -9.54% (p=0.000 n=8+8) Match/Easy1/1K-12 861ns ± 0% 884ns ± 0% +2.71% (p=0.000 n=8+9) Match/Easy1/32K-12 39.2µs ± 1% 39.2µs ± 0% ~ (p=0.090 n=10+9) Match/Easy1/1M-12 1.38ms ± 0% 1.39ms ± 0% ~ (p=0.095 n=10+9) Match/Easy1/32M-12 44.2ms ± 1% 44.2ms ± 1% ~ (p=0.218 n=10+10) Match/Medium/32-12 1.04µs ± 1% 1.05µs ± 0% +1.05% (p=0.000 n=9+8) Match/Medium/1K-12 31.3µs ± 0% 31.3µs ± 0% -0.14% (p=0.004 n=9+9) Match/Medium/32K-12 1.44ms ± 0% 1.45ms ± 0% +0.18% (p=0.001 n=8+8) Match/Medium/1M-12 46.1ms ± 0% 46.2ms ± 0% +0.13% (p=0.003 n=6+9) Match/Medium/32M-12 1.48s ± 0% 1.48s ± 0% +0.20% (p=0.002 n=9+8) Match/Hard/32-12 1.54µs ± 1% 1.49µs ± 0% -3.60% (p=0.000 n=9+10) Match/Hard/1K-12 46.4µs ± 1% 45.1µs ± 1% -2.78% (p=0.000 n=9+10) Match/Hard/32K-12 2.19ms ± 0% 2.18ms ± 1% -0.51% (p=0.006 n=8+9) Match/Hard/1M-12 70.1ms ± 0% 69.7ms ± 1% -0.52% (p=0.006 n=8+9) Match/Hard/32M-12 2.24s ± 0% 2.23s ± 1% -0.42% (p=0.046 n=8+9) Match/Hard1/32-12 8.17µs ± 1% 7.89µs ± 0% -3.42% (p=0.000 n=8+9) Match/Hard1/1K-12 254µs ± 2% 244µs ± 0% -3.91% (p=0.000 n=9+9) Match/Hard1/32K-12 9.58ms ± 1% 10.35ms ± 0% +8.00% (p=0.000 n=10+10) Match/Hard1/1M-12 306ms ± 1% 331ms ± 0% +8.27% (p=0.000 n=9+8) Match/Hard1/32M-12 9.79s ± 1% 10.60s ± 0% +8.29% (p=0.000 n=9+8) Match_onepass_regex/32-12 808ns ± 0% 812ns ± 0% +0.47% (p=0.000 n=8+10) Match_onepass_regex/1K-12 27.8µs ± 0% 28.5µs ± 0% +2.32% (p=0.000 n=8+10) Match_onepass_regex/32K-12 925µs ± 0% 936µs ± 0% +1.24% (p=0.000 n=9+10) Match_onepass_regex/1M-12 29.5ms ± 0% 30.2ms ± 0% +2.38% (p=0.000 n=10+10) Match_onepass_regex/32M-12 945ms ± 0% 970ms ± 0% +2.60% (p=0.000 n=9+10) CompileOnepass-12 4.67µs ± 0% 4.63µs ± 1% -0.84% (p=0.000 n=10+10) [Geo mean] 24.5µs 23.3µs -5.04% https://perf.golang.org/search?q=upload:20181004.1 Change-Id: Idbc2b76223718265657819ff38be2d9aba1c54b4 Reviewed-on: https://go-review.googlesource.com/c/139779 Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-09-28 16:37:16 -04:00
if cap(b.matchcap) < ncap {
b.matchcap = make([]int, ncap)
} else {
b.matchcap = b.matchcap[:ncap]
}
for i := range b.matchcap {
b.matchcap[i] = -1
}
regexp: port RE2's bitstate backtracker to the regexp package This is a port of RE2's bitstate backtracker, which triggers under the same conditions that the RE2 backtracker triggers. However I wasn't sure how to port over some of the optimizations in the RE2 backtracker, and there is a ~2% penalty on benchmarks that don't trigger the backtracker. benchmark old ns/op new ns/op delta BenchmarkLiteral 312 189 -39.42% BenchmarkNotLiteral 4435 3001 -32.33% BenchmarkMatchClass 5758 4378 -23.97% BenchmarkMatchClass_InRange 5385 4084 -24.16% BenchmarkReplaceAll 5291 3505 -33.76% BenchmarkAnchoredLiteralShortNonMatch 190 200 +5.26% BenchmarkAnchoredLiteralLongNonMatch 189 194 +2.65% BenchmarkAnchoredShortMatch 479 304 -36.53% BenchmarkAnchoredLongMatch 478 499 +4.39% BenchmarkOnePassShortA 791 798 +0.88% BenchmarkNotOnePassShortA 3202 1571 -50.94% BenchmarkOnePassShortB 614 633 +3.09% BenchmarkNotOnePassShortB 2685 881 -67.19% BenchmarkOnePassLongPrefix 152 154 +1.32% BenchmarkOnePassLongNotPrefix 505 533 +5.54% BenchmarkMatchEasy0_32 139 171 +23.02% BenchmarkMatchEasy0_1K 653 1797 +175.19% BenchmarkMatchEasy0_32K 12032 13346 +10.92% BenchmarkMatchEasy0_1M 462882 461272 -0.35% BenchmarkMatchEasy0_32M 15015339 15365238 +2.33% BenchmarkMatchEasy1_32 122 168 +37.70% BenchmarkMatchEasy1_1K 3339 2612 -21.77% BenchmarkMatchEasy1_32K 72330 71721 -0.84% BenchmarkMatchEasy1_1M 2545410 2652284 +4.20% BenchmarkMatchEasy1_32M 80072063 82609750 +3.17% BenchmarkMatchMedium_32 2359 1980 -16.07% BenchmarkMatchMedium_1K 75939 58593 -22.84% BenchmarkMatchMedium_32K 2450907 2501106 +2.05% BenchmarkMatchMedium_1M 78707697 80174418 +1.86% BenchmarkMatchMedium_32M 2535146010 2570896441 +1.41% BenchmarkMatchHard_32 4297 2960 -31.11% BenchmarkMatchHard_1K 133592 88997 -33.38% BenchmarkMatchHard_32K 4240445 4336907 +2.27% BenchmarkMatchHard_1M 136187006 139350238 +2.32% BenchmarkMatchHard_32M 4350855890 4478537306 +2.93% benchmark old MB/s new MB/s speedup BenchmarkMatchEasy0_32 228.74 186.11 0.81x BenchmarkMatchEasy0_1K 1565.91 569.64 0.36x BenchmarkMatchEasy0_32K 2723.31 2455.10 0.90x BenchmarkMatchEasy0_1M 2265.32 2273.22 1.00x BenchmarkMatchEasy0_32M 2234.68 2183.79 0.98x BenchmarkMatchEasy1_32 261.08 190.22 0.73x BenchmarkMatchEasy1_1K 306.59 391.91 1.28x BenchmarkMatchEasy1_32K 453.03 456.88 1.01x BenchmarkMatchEasy1_1M 411.95 395.35 0.96x BenchmarkMatchEasy1_32M 419.05 406.18 0.97x BenchmarkMatchMedium_32 13.56 16.16 1.19x BenchmarkMatchMedium_1K 13.48 17.48 1.30x BenchmarkMatchMedium_32K 13.37 13.10 0.98x BenchmarkMatchMedium_1M 13.32 13.08 0.98x BenchmarkMatchMedium_32M 13.24 13.05 0.99x BenchmarkMatchHard_32 7.45 10.81 1.45x BenchmarkMatchHard_1K 7.67 11.51 1.50x BenchmarkMatchHard_32K 7.73 7.56 0.98x BenchmarkMatchHard_1M 7.70 7.52 0.98x BenchmarkMatchHard_32M 7.71 7.49 0.97x Fixes #4154 Change-Id: Iff7fb9507f0872b320d08afc08679751ed1b28bc Reviewed-on: https://go-review.googlesource.com/2153 Reviewed-by: Russ Cox <rsc@golang.org>
2014-12-28 00:17:01 -08:00
}
// shouldVisit reports whether the combination of (pc, pos) has not
// been visited yet.
func (b *bitState) shouldVisit(pc uint32, pos int) bool {
n := uint(int(pc)*(b.end+1) + pos)
if b.visited[n/visitedBits]&(1<<(n&(visitedBits-1))) != 0 {
return false
}
b.visited[n/visitedBits] |= 1 << (n & (visitedBits - 1))
return true
}
// push pushes (pc, pos, arg) onto the job stack if it should be
// visited.
regexp: split bit-state execution out of machine struct This allows the bit-state executions to have their own pool of allocated structures. A step toward eliminating the per-Regexp machine cache. Note especially the -92% on MatchParallelShared. This is real but not a complete story: the other execution engines still need to be de-shared, but the benchmark was only using bit-state. The tiny slowdowns in unrelated code are noise. name old time/op new time/op delta Find-12 264ns ± 3% 254ns ± 0% -3.86% (p=0.000 n=10+9) FindAllNoMatches-12 140ns ± 2% 135ns ± 0% -3.91% (p=0.000 n=10+9) FindString-12 256ns ± 0% 247ns ± 0% -3.52% (p=0.000 n=8+8) FindSubmatch-12 339ns ± 1% 334ns ± 0% -1.41% (p=0.000 n=9+10) FindStringSubmatch-12 322ns ± 0% 321ns ± 0% -0.21% (p=0.005 n=8+9) Literal-12 100ns ± 2% 92ns ± 0% -8.10% (p=0.000 n=10+9) NotLiteral-12 1.50µs ± 0% 1.47µs ± 0% -1.91% (p=0.000 n=8+9) MatchClass-12 2.18µs ± 0% 2.17µs ± 0% -0.20% (p=0.001 n=10+7) MatchClass_InRange-12 2.12µs ± 0% 2.13µs ± 0% +0.23% (p=0.000 n=10+10) ReplaceAll-12 1.41µs ± 0% 1.39µs ± 0% -1.30% (p=0.000 n=7+10) AnchoredLiteralShortNonMatch-12 89.8ns ± 0% 83.2ns ± 0% -7.35% (p=0.000 n=8+8) AnchoredLiteralLongNonMatch-12 105ns ± 3% 105ns ± 0% ~ (p=0.186 n=10+10) AnchoredShortMatch-12 141ns ± 0% 131ns ± 0% -7.09% (p=0.000 n=9+10) AnchoredLongMatch-12 276ns ± 4% 267ns ± 0% -3.23% (p=0.000 n=10+10) OnePassShortA-12 620ns ± 0% 611ns ± 0% -1.39% (p=0.000 n=10+9) NotOnePassShortA-12 575ns ± 3% 552ns ± 0% -3.97% (p=0.000 n=10+8) OnePassShortB-12 493ns ± 0% 491ns ± 0% -0.33% (p=0.000 n=8+8) NotOnePassShortB-12 423ns ± 0% 412ns ± 0% -2.60% (p=0.000 n=8+9) OnePassLongPrefix-12 112ns ± 0% 112ns ± 0% ~ (all equal) OnePassLongNotPrefix-12 405ns ± 0% 410ns ± 0% +1.23% (p=0.000 n=8+9) MatchParallelShared-12 501ns ± 1% 39ns ± 1% -92.27% (p=0.000 n=10+10) MatchParallelCopied-12 39.1ns ± 0% 39.2ns ± 3% ~ (p=0.785 n=6+10) QuoteMetaAll-12 94.6ns ± 0% 94.6ns ± 0% ~ (p=0.439 n=10+8) QuoteMetaNone-12 52.7ns ± 0% 52.7ns ± 0% ~ (all equal) Match/Easy0/32-12 79.1ns ± 0% 72.9ns ± 0% -7.85% (p=0.000 n=9+9) Match/Easy0/1K-12 307ns ± 1% 298ns ± 0% -2.99% (p=0.000 n=10+6) Match/Easy0/32K-12 4.65µs ± 2% 4.60µs ± 2% ~ (p=0.159 n=10+10) Match/Easy0/1M-12 234µs ± 0% 235µs ± 0% +0.17% (p=0.003 n=10+10) Match/Easy0/32M-12 7.98ms ± 1% 7.96ms ± 0% ~ (p=0.278 n=9+10) Match/Easy0i/32-12 1.13µs ± 1% 1.09µs ± 0% -3.24% (p=0.000 n=9+8) Match/Easy0i/1K-12 32.5µs ± 0% 31.7µs ± 0% -2.66% (p=0.000 n=9+9) Match/Easy0i/32K-12 1.59ms ± 0% 1.61ms ± 0% +0.75% (p=0.000 n=9+9) Match/Easy0i/1M-12 51.0ms ± 0% 51.4ms ± 0% +0.77% (p=0.000 n=10+8) Match/Easy0i/32M-12 1.63s ± 0% 1.65s ± 1% +1.24% (p=0.000 n=7+9) Match/Easy1/32-12 75.1ns ± 1% 67.9ns ± 0% -9.54% (p=0.000 n=8+8) Match/Easy1/1K-12 861ns ± 0% 884ns ± 0% +2.71% (p=0.000 n=8+9) Match/Easy1/32K-12 39.2µs ± 1% 39.2µs ± 0% ~ (p=0.090 n=10+9) Match/Easy1/1M-12 1.38ms ± 0% 1.39ms ± 0% ~ (p=0.095 n=10+9) Match/Easy1/32M-12 44.2ms ± 1% 44.2ms ± 1% ~ (p=0.218 n=10+10) Match/Medium/32-12 1.04µs ± 1% 1.05µs ± 0% +1.05% (p=0.000 n=9+8) Match/Medium/1K-12 31.3µs ± 0% 31.3µs ± 0% -0.14% (p=0.004 n=9+9) Match/Medium/32K-12 1.44ms ± 0% 1.45ms ± 0% +0.18% (p=0.001 n=8+8) Match/Medium/1M-12 46.1ms ± 0% 46.2ms ± 0% +0.13% (p=0.003 n=6+9) Match/Medium/32M-12 1.48s ± 0% 1.48s ± 0% +0.20% (p=0.002 n=9+8) Match/Hard/32-12 1.54µs ± 1% 1.49µs ± 0% -3.60% (p=0.000 n=9+10) Match/Hard/1K-12 46.4µs ± 1% 45.1µs ± 1% -2.78% (p=0.000 n=9+10) Match/Hard/32K-12 2.19ms ± 0% 2.18ms ± 1% -0.51% (p=0.006 n=8+9) Match/Hard/1M-12 70.1ms ± 0% 69.7ms ± 1% -0.52% (p=0.006 n=8+9) Match/Hard/32M-12 2.24s ± 0% 2.23s ± 1% -0.42% (p=0.046 n=8+9) Match/Hard1/32-12 8.17µs ± 1% 7.89µs ± 0% -3.42% (p=0.000 n=8+9) Match/Hard1/1K-12 254µs ± 2% 244µs ± 0% -3.91% (p=0.000 n=9+9) Match/Hard1/32K-12 9.58ms ± 1% 10.35ms ± 0% +8.00% (p=0.000 n=10+10) Match/Hard1/1M-12 306ms ± 1% 331ms ± 0% +8.27% (p=0.000 n=9+8) Match/Hard1/32M-12 9.79s ± 1% 10.60s ± 0% +8.29% (p=0.000 n=9+8) Match_onepass_regex/32-12 808ns ± 0% 812ns ± 0% +0.47% (p=0.000 n=8+10) Match_onepass_regex/1K-12 27.8µs ± 0% 28.5µs ± 0% +2.32% (p=0.000 n=8+10) Match_onepass_regex/32K-12 925µs ± 0% 936µs ± 0% +1.24% (p=0.000 n=9+10) Match_onepass_regex/1M-12 29.5ms ± 0% 30.2ms ± 0% +2.38% (p=0.000 n=10+10) Match_onepass_regex/32M-12 945ms ± 0% 970ms ± 0% +2.60% (p=0.000 n=9+10) CompileOnepass-12 4.67µs ± 0% 4.63µs ± 1% -0.84% (p=0.000 n=10+10) [Geo mean] 24.5µs 23.3µs -5.04% https://perf.golang.org/search?q=upload:20181004.1 Change-Id: Idbc2b76223718265657819ff38be2d9aba1c54b4 Reviewed-on: https://go-review.googlesource.com/c/139779 Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-09-28 16:37:16 -04:00
func (b *bitState) push(re *Regexp, pc uint32, pos int, arg bool) {
regexp: make (*bitState).push inlinable By refactoring job.arg from int with 0/1 as the only valid values into bool and simplifying (*bitState).push, we reduce the number of nodes below the inlining threshold. This improves backtracking regexp performance by 5-10% and go1 geomean by 1.7% Full performance data below: name old time/op new time/op delta Find-6 510ns ± 0% 480ns ± 1% -5.90% (p=0.000 n=10+10) FindString-6 504ns ± 1% 479ns ± 1% -5.10% (p=0.000 n=10+10) FindSubmatch-6 689ns ± 1% 659ns ± 1% -4.27% (p=0.000 n=9+10) FindStringSubmatch-6 659ns ± 0% 628ns ± 1% -4.69% (p=0.000 n=8+10) Literal-6 174ns ± 1% 171ns ± 1% -1.50% (p=0.000 n=10+10) NotLiteral-6 2.89µs ± 1% 2.72µs ± 0% -5.84% (p=0.000 n=10+9) MatchClass-6 4.65µs ± 1% 4.28µs ± 1% -7.96% (p=0.000 n=10+10) MatchClass_InRange-6 4.15µs ± 1% 3.80µs ± 0% -8.61% (p=0.000 n=10+8) ReplaceAll-6 2.72µs ± 1% 2.60µs ± 1% -4.68% (p=0.000 n=10+10) AnchoredLiteralShortNonMatch-6 158ns ± 1% 153ns ± 1% -3.03% (p=0.000 n=10+10) AnchoredLiteralLongNonMatch-6 176ns ± 1% 176ns ± 0% ~ (p=1.000 n=10+9) AnchoredShortMatch-6 260ns ± 0% 255ns ± 1% -1.84% (p=0.000 n=9+10) AnchoredLongMatch-6 456ns ± 0% 455ns ± 0% -0.19% (p=0.008 n=8+10) OnePassShortA-6 1.13µs ± 1% 1.12µs ± 0% -0.57% (p=0.046 n=10+8) NotOnePassShortA-6 1.14µs ± 1% 1.14µs ± 1% ~ (p=0.162 n=10+10) OnePassShortB-6 908ns ± 0% 893ns ± 0% -1.60% (p=0.000 n=8+9) NotOnePassShortB-6 857ns ± 0% 803ns ± 1% -6.34% (p=0.000 n=8+10) OnePassLongPrefix-6 190ns ± 0% 190ns ± 1% ~ (p=0.059 n=8+10) OnePassLongNotPrefix-6 722ns ± 1% 722ns ± 1% ~ (p=0.451 n=10+10) MatchParallelShared-6 810ns ± 2% 807ns ± 2% ~ (p=0.643 n=10+10) MatchParallelCopied-6 72.1ns ± 1% 69.4ns ± 1% -3.81% (p=0.000 n=10+10) QuoteMetaAll-6 213ns ± 2% 216ns ± 3% ~ (p=0.284 n=10+10) QuoteMetaNone-6 89.7ns ± 1% 89.8ns ± 1% ~ (p=0.616 n=10+10) Match/Easy0/32-6 127ns ± 1% 127ns ± 1% ~ (p=0.977 n=10+10) Match/Easy0/1K-6 566ns ± 0% 566ns ± 0% ~ (p=1.000 n=8+8) Match/Easy0/32K-6 9.30µs ± 1% 9.28µs ± 1% ~ (p=0.529 n=10+10) Match/Easy0/1M-6 460µs ± 1% 460µs ± 1% ~ (p=0.853 n=10+10) Match/Easy0/32M-6 15.0ms ± 0% 15.1ms ± 0% +0.77% (p=0.000 n=9+8) Match/Easy0i/32-6 2.10µs ± 1% 1.98µs ± 0% -6.02% (p=0.000 n=10+8) Match/Easy0i/1K-6 61.5µs ± 0% 57.2µs ± 0% -6.97% (p=0.000 n=10+9) Match/Easy0i/32K-6 2.75ms ± 0% 2.72ms ± 0% -1.10% (p=0.000 n=9+9) Match/Easy0i/1M-6 88.0ms ± 0% 86.9ms ± 1% -1.29% (p=0.000 n=8+10) Match/Easy0i/32M-6 2.82s ± 0% 2.77s ± 1% -1.81% (p=0.000 n=8+10) Match/Easy1/32-6 123ns ± 1% 124ns ± 1% +0.90% (p=0.001 n=10+10) Match/Easy1/1K-6 1.70µs ± 1% 1.65µs ± 0% -3.18% (p=0.000 n=9+10) Match/Easy1/32K-6 69.1µs ± 0% 68.4µs ± 1% -0.95% (p=0.000 n=8+10) Match/Easy1/1M-6 2.46ms ± 1% 2.42ms ± 1% -1.66% (p=0.000 n=10+10) Match/Easy1/32M-6 78.4ms ± 1% 77.5ms ± 0% -1.08% (p=0.000 n=10+9) Match/Medium/32-6 2.07µs ± 1% 1.91µs ± 1% -7.69% (p=0.000 n=10+10) Match/Medium/1K-6 62.8µs ± 0% 58.0µs ± 1% -7.70% (p=0.000 n=8+10) Match/Medium/32K-6 2.63ms ± 1% 2.58ms ± 1% -2.14% (p=0.000 n=10+10) Match/Medium/1M-6 84.6ms ± 0% 82.5ms ± 0% -2.37% (p=0.000 n=8+9) Match/Medium/32M-6 2.71s ± 0% 2.64s ± 0% -2.46% (p=0.000 n=10+9) Match/Hard/32-6 3.26µs ± 1% 2.98µs ± 1% -8.49% (p=0.000 n=10+10) Match/Hard/1K-6 100µs ± 0% 90µs ± 1% -9.55% (p=0.000 n=9+10) Match/Hard/32K-6 3.82ms ± 0% 3.82ms ± 1% ~ (p=0.515 n=8+10) Match/Hard/1M-6 122ms ± 1% 123ms ± 0% +0.66% (p=0.000 n=10+8) Match/Hard/32M-6 3.89s ± 1% 3.91s ± 1% ~ (p=0.105 n=10+10) Match/Hard1/32-6 18.1µs ± 1% 16.1µs ± 1% -11.31% (p=0.000 n=10+10) Match/Hard1/1K-6 565µs ± 0% 493µs ± 1% -12.65% (p=0.000 n=8+10) Match/Hard1/32K-6 18.8ms ± 0% 18.8ms ± 1% ~ (p=0.905 n=9+10) Match/Hard1/1M-6 602ms ± 1% 602ms ± 1% ~ (p=0.278 n=9+10) Match/Hard1/32M-6 19.1s ± 1% 19.2s ± 1% +0.31% (p=0.035 n=9+10) Match_onepass_regex/32-6 6.32µs ± 1% 6.34µs ± 1% ~ (p=0.060 n=10+10) Match_onepass_regex/1K-6 204µs ± 1% 204µs ± 1% ~ (p=0.842 n=9+10) Match_onepass_regex/32K-6 6.53ms ± 0% 6.55ms ± 1% +0.36% (p=0.005 n=10+10) Match_onepass_regex/1M-6 209ms ± 0% 208ms ± 1% -0.65% (p=0.034 n=8+10) Match_onepass_regex/32M-6 6.72s ± 0% 6.68s ± 1% -0.74% (p=0.000 n=9+10) CompileOnepass/^(?:(?:(?:.(?:$))?))...-6 7.02µs ± 1% 7.02µs ± 1% ~ (p=0.671 n=10+10) CompileOnepass/^abcd$-6 5.65µs ± 1% 5.65µs ± 1% ~ (p=0.411 n=10+9) CompileOnepass/^(?:(?:a{0,})*?)$-6 7.06µs ± 1% 7.06µs ± 1% ~ (p=0.912 n=10+10) CompileOnepass/^(?:(?:a+)*)$-6 6.40µs ± 1% 6.41µs ± 1% ~ (p=0.699 n=10+10) CompileOnepass/^(?:(?:a|(?:aa)))$-6 8.18µs ± 2% 8.16µs ± 1% ~ (p=0.529 n=10+10) CompileOnepass/^(?:[^\s\S])$-6 5.08µs ± 1% 5.17µs ± 1% +1.77% (p=0.000 n=9+10) CompileOnepass/^(?:(?:(?:a*)+))$-6 6.86µs ± 1% 6.85µs ± 0% ~ (p=0.190 n=10+9) CompileOnepass/^[a-c]+$-6 5.14µs ± 1% 5.11µs ± 0% -0.53% (p=0.041 n=10+10) CompileOnepass/^[a-c]*$-6 5.62µs ± 1% 5.63µs ± 1% ~ (p=0.382 n=10+10) CompileOnepass/^(?:a*)$-6 5.76µs ± 1% 5.73µs ± 1% -0.41% (p=0.008 n=9+10) CompileOnepass/^(?:(?:aa)|a)$-6 7.89µs ± 1% 7.84µs ± 1% -0.66% (p=0.020 n=10+10) CompileOnepass/^...$-6 5.38µs ± 1% 5.38µs ± 1% ~ (p=0.857 n=9+10) CompileOnepass/^(?:a|(?:aa))$-6 7.80µs ± 2% 7.82µs ± 1% ~ (p=0.342 n=10+10) CompileOnepass/^a((b))c$-6 7.75µs ± 1% 7.78µs ± 1% ~ (p=0.172 n=10+10) CompileOnepass/^a.[l-nA-Cg-j]?e$-6 8.39µs ± 1% 8.42µs ± 1% ~ (p=0.138 n=10+10) CompileOnepass/^a((b))$-6 6.92µs ± 1% 6.95µs ± 1% ~ (p=0.159 n=10+10) CompileOnepass/^a(?:(b)|(c))c$-6 10.0µs ± 1% 10.0µs ± 1% ~ (p=0.896 n=10+10) CompileOnepass/^a(?:b|c)$-6 5.62µs ± 1% 5.66µs ± 1% +0.71% (p=0.023 n=10+10) CompileOnepass/^a(?:b?|c)$-6 8.49µs ± 1% 8.43µs ± 1% -0.69% (p=0.010 n=10+10) CompileOnepass/^a(?:b?|c+)$-6 9.26µs ± 1% 9.28µs ± 1% ~ (p=0.448 n=10+10) CompileOnepass/^a(?:bc)+$-6 6.52µs ± 1% 6.46µs ± 2% -1.02% (p=0.003 n=10+10) CompileOnepass/^a(?:[bcd])+$-6 6.29µs ± 1% 6.32µs ± 1% ~ (p=0.256 n=10+10) CompileOnepass/^a((?:[bcd])+)$-6 7.77µs ± 1% 7.79µs ± 1% ~ (p=0.105 n=10+10) CompileOnepass/^a(:?b|c)*d$-6 14.0µs ± 1% 13.9µs ± 1% -0.69% (p=0.003 n=10+10) CompileOnepass/^.bc(d|e)*$-6 8.96µs ± 1% 9.06µs ± 1% +1.20% (p=0.000 n=10+9) CompileOnepass/^loooooooooooooooooo...-6 219µs ± 1% 220µs ± 1% +0.63% (p=0.006 n=9+10) [Geo mean] 31.6µs 31.1µs -1.82% name old speed new speed delta QuoteMetaAll-6 65.5MB/s ± 2% 64.8MB/s ± 3% ~ (p=0.315 n=10+10) QuoteMetaNone-6 290MB/s ± 1% 290MB/s ± 1% ~ (p=0.755 n=10+10) Match/Easy0/32-6 250MB/s ± 0% 251MB/s ± 1% ~ (p=0.277 n=8+9) Match/Easy0/1K-6 1.81GB/s ± 0% 1.81GB/s ± 0% ~ (p=0.408 n=8+10) Match/Easy0/32K-6 3.52GB/s ± 1% 3.53GB/s ± 1% ~ (p=0.529 n=10+10) Match/Easy0/1M-6 2.28GB/s ± 1% 2.28GB/s ± 1% ~ (p=0.853 n=10+10) Match/Easy0/32M-6 2.24GB/s ± 0% 2.23GB/s ± 0% -0.76% (p=0.000 n=9+8) Match/Easy0i/32-6 15.2MB/s ± 1% 16.2MB/s ± 0% +6.43% (p=0.000 n=10+9) Match/Easy0i/1K-6 16.6MB/s ± 0% 17.9MB/s ± 0% +7.48% (p=0.000 n=10+9) Match/Easy0i/32K-6 11.9MB/s ± 0% 12.0MB/s ± 0% +1.11% (p=0.000 n=9+9) Match/Easy0i/1M-6 11.9MB/s ± 0% 12.1MB/s ± 1% +1.31% (p=0.000 n=8+10) Match/Easy0i/32M-6 11.9MB/s ± 0% 12.1MB/s ± 1% +1.84% (p=0.000 n=8+10) Match/Easy1/32-6 260MB/s ± 1% 258MB/s ± 1% -0.91% (p=0.001 n=10+10) Match/Easy1/1K-6 601MB/s ± 1% 621MB/s ± 0% +3.28% (p=0.000 n=9+10) Match/Easy1/32K-6 474MB/s ± 0% 479MB/s ± 1% +0.96% (p=0.000 n=8+10) Match/Easy1/1M-6 426MB/s ± 1% 433MB/s ± 1% +1.68% (p=0.000 n=10+10) Match/Easy1/32M-6 428MB/s ± 1% 433MB/s ± 0% +1.09% (p=0.000 n=10+9) Match/Medium/32-6 15.4MB/s ± 1% 16.7MB/s ± 1% +8.23% (p=0.000 n=10+9) Match/Medium/1K-6 16.3MB/s ± 1% 17.7MB/s ± 1% +8.43% (p=0.000 n=9+10) Match/Medium/32K-6 12.5MB/s ± 1% 12.7MB/s ± 1% +2.15% (p=0.000 n=10+10) Match/Medium/1M-6 12.4MB/s ± 0% 12.7MB/s ± 0% +2.44% (p=0.000 n=8+9) Match/Medium/32M-6 12.4MB/s ± 0% 12.7MB/s ± 0% +2.52% (p=0.000 n=10+9) Match/Hard/32-6 9.82MB/s ± 1% 10.73MB/s ± 1% +9.29% (p=0.000 n=10+10) Match/Hard/1K-6 10.2MB/s ± 0% 11.3MB/s ± 1% +10.56% (p=0.000 n=9+10) Match/Hard/32K-6 8.58MB/s ± 0% 8.58MB/s ± 1% ~ (p=0.554 n=8+10) Match/Hard/1M-6 8.59MB/s ± 1% 8.53MB/s ± 0% -0.70% (p=0.000 n=10+8) Match/Hard/32M-6 8.62MB/s ± 1% 8.59MB/s ± 1% ~ (p=0.098 n=10+10) Match/Hard1/32-6 1.77MB/s ± 1% 1.99MB/s ± 1% +12.40% (p=0.000 n=10+8) Match/Hard1/1K-6 1.81MB/s ± 1% 2.08MB/s ± 1% +14.55% (p=0.000 n=10+10) Match/Hard1/32K-6 1.74MB/s ± 0% 1.74MB/s ± 0% ~ (p=0.108 n=9+10) Match/Hard1/1M-6 1.74MB/s ± 0% 1.74MB/s ± 1% ~ (p=1.000 n=9+10) Match/Hard1/32M-6 1.75MB/s ± 0% 1.75MB/s ± 1% ~ (p=0.157 n=9+10) Match_onepass_regex/32-6 5.05MB/s ± 0% 5.05MB/s ± 1% ~ (p=0.262 n=8+10) Match_onepass_regex/1K-6 5.02MB/s ± 1% 5.02MB/s ± 1% ~ (p=0.677 n=9+10) Match_onepass_regex/32K-6 5.02MB/s ± 0% 4.99MB/s ± 0% -0.47% (p=0.000 n=10+9) Match_onepass_regex/1M-6 5.01MB/s ± 0% 5.04MB/s ± 1% +0.68% (p=0.017 n=8+10) Match_onepass_regex/32M-6 4.99MB/s ± 0% 5.03MB/s ± 1% +0.74% (p=0.000 n=10+10) [Geo mean] 29.1MB/s 29.8MB/s +2.44% go1 data for reference name old time/op new time/op delta BinaryTree17-6 4.39s ± 1% 4.37s ± 0% -0.58% (p=0.006 n=9+9) Fannkuch11-6 5.13s ± 0% 5.18s ± 0% +0.87% (p=0.000 n=8+8) FmtFprintfEmpty-6 74.2ns ± 0% 71.7ns ± 3% -3.41% (p=0.000 n=10+10) FmtFprintfString-6 120ns ± 1% 122ns ± 2% ~ (p=0.333 n=10+10) FmtFprintfInt-6 127ns ± 1% 127ns ± 1% ~ (p=0.809 n=10+10) FmtFprintfIntInt-6 186ns ± 0% 188ns ± 1% +1.02% (p=0.002 n=8+10) FmtFprintfPrefixedInt-6 223ns ± 1% 222ns ± 2% ~ (p=0.421 n=10+10) FmtFprintfFloat-6 374ns ± 0% 376ns ± 1% +0.43% (p=0.030 n=8+10) FmtManyArgs-6 795ns ± 0% 788ns ± 1% -0.79% (p=0.000 n=8+9) GobDecode-6 10.9ms ± 1% 10.9ms ± 0% ~ (p=0.079 n=10+9) GobEncode-6 8.60ms ± 1% 8.56ms ± 0% -0.52% (p=0.004 n=10+10) Gzip-6 378ms ± 1% 386ms ± 1% +2.28% (p=0.000 n=10+10) Gunzip-6 63.7ms ± 0% 62.3ms ± 0% -2.22% (p=0.000 n=9+8) HTTPClientServer-6 120µs ± 3% 114µs ± 3% -4.99% (p=0.000 n=10+10) JSONEncode-6 20.3ms ± 1% 19.9ms ± 0% -1.90% (p=0.000 n=9+10) JSONDecode-6 84.3ms ± 0% 83.7ms ± 0% -0.76% (p=0.000 n=8+8) Mandelbrot200-6 6.91ms ± 0% 6.89ms ± 0% -0.31% (p=0.000 n=9+8) GoParse-6 5.49ms ± 0% 5.47ms ± 1% ~ (p=0.101 n=8+10) RegexpMatchEasy0_32-6 130ns ± 0% 128ns ± 0% -1.54% (p=0.002 n=8+10) RegexpMatchEasy0_1K-6 322ns ± 1% 322ns ± 0% ~ (p=0.525 n=10+9) RegexpMatchEasy1_32-6 124ns ± 0% 124ns ± 0% -0.32% (p=0.046 n=8+10) RegexpMatchEasy1_1K-6 570ns ± 0% 548ns ± 1% -3.76% (p=0.000 n=10+10) RegexpMatchMedium_32-6 196ns ± 0% 183ns ± 1% -6.61% (p=0.000 n=8+10) RegexpMatchMedium_1K-6 64.3µs ± 0% 59.0µs ± 1% -8.31% (p=0.000 n=8+10) RegexpMatchHard_32-6 3.08µs ± 0% 2.80µs ± 0% -8.96% (p=0.000 n=8+9) RegexpMatchHard_1K-6 93.0µs ± 0% 84.5µs ± 1% -9.17% (p=0.000 n=8+9) Revcomp-6 647ms ± 2% 646ms ± 1% ~ (p=0.720 n=10+9) Template-6 92.3ms ± 0% 91.7ms ± 0% -0.65% (p=0.000 n=8+8) TimeParse-6 490ns ± 0% 488ns ± 0% -0.43% (p=0.000 n=10+10) TimeFormat-6 513ns ± 0% 513ns ± 1% ~ (p=0.144 n=9+10) [Geo mean] 79.1µs 77.7µs -1.73% name old speed new speed delta GobDecode-6 70.1MB/s ± 1% 70.3MB/s ± 0% ~ (p=0.078 n=10+9) GobEncode-6 89.2MB/s ± 1% 89.7MB/s ± 0% +0.52% (p=0.004 n=10+10) Gzip-6 51.4MB/s ± 1% 50.2MB/s ± 1% -2.23% (p=0.000 n=10+10) Gunzip-6 304MB/s ± 0% 311MB/s ± 0% +2.27% (p=0.000 n=9+8) JSONEncode-6 95.8MB/s ± 1% 97.7MB/s ± 0% +1.93% (p=0.000 n=9+10) JSONDecode-6 23.0MB/s ± 0% 23.2MB/s ± 0% +0.76% (p=0.000 n=8+8) GoParse-6 10.6MB/s ± 0% 10.6MB/s ± 1% ~ (p=0.111 n=8+10) RegexpMatchEasy0_32-6 244MB/s ± 0% 249MB/s ± 0% +2.06% (p=0.000 n=9+10) RegexpMatchEasy0_1K-6 3.18GB/s ± 1% 3.17GB/s ± 0% ~ (p=0.211 n=10+9) RegexpMatchEasy1_32-6 257MB/s ± 0% 258MB/s ± 0% +0.37% (p=0.000 n=8+8) RegexpMatchEasy1_1K-6 1.80GB/s ± 0% 1.87GB/s ± 1% +3.91% (p=0.000 n=10+10) RegexpMatchMedium_32-6 5.08MB/s ± 0% 5.43MB/s ± 1% +7.03% (p=0.000 n=8+10) RegexpMatchMedium_1K-6 15.9MB/s ± 0% 17.4MB/s ± 1% +9.08% (p=0.000 n=8+10) RegexpMatchHard_32-6 10.4MB/s ± 0% 11.4MB/s ± 0% +9.82% (p=0.000 n=8+9) RegexpMatchHard_1K-6 11.0MB/s ± 0% 12.1MB/s ± 1% +10.10% (p=0.000 n=8+9) Revcomp-6 393MB/s ± 2% 394MB/s ± 1% ~ (p=0.720 n=10+9) Template-6 21.0MB/s ± 0% 21.2MB/s ± 0% +0.66% (p=0.000 n=8+8) [Geo mean] 74.2MB/s 76.2MB/s +2.70% Updates #21851 Change-Id: Ie88455db925f422a828f8528293790726a9c036b Reviewed-on: https://go-review.googlesource.com/65491 Run-TryBot: Ilya Tocar <ilya.tocar@intel.com> Reviewed-by: Daniel Martí <mvdan@mvdan.cc> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2017-09-22 15:15:23 -05:00
// Only check shouldVisit when arg is false.
// When arg is true, we are continuing a previous visit.
regexp: split bit-state execution out of machine struct This allows the bit-state executions to have their own pool of allocated structures. A step toward eliminating the per-Regexp machine cache. Note especially the -92% on MatchParallelShared. This is real but not a complete story: the other execution engines still need to be de-shared, but the benchmark was only using bit-state. The tiny slowdowns in unrelated code are noise. name old time/op new time/op delta Find-12 264ns ± 3% 254ns ± 0% -3.86% (p=0.000 n=10+9) FindAllNoMatches-12 140ns ± 2% 135ns ± 0% -3.91% (p=0.000 n=10+9) FindString-12 256ns ± 0% 247ns ± 0% -3.52% (p=0.000 n=8+8) FindSubmatch-12 339ns ± 1% 334ns ± 0% -1.41% (p=0.000 n=9+10) FindStringSubmatch-12 322ns ± 0% 321ns ± 0% -0.21% (p=0.005 n=8+9) Literal-12 100ns ± 2% 92ns ± 0% -8.10% (p=0.000 n=10+9) NotLiteral-12 1.50µs ± 0% 1.47µs ± 0% -1.91% (p=0.000 n=8+9) MatchClass-12 2.18µs ± 0% 2.17µs ± 0% -0.20% (p=0.001 n=10+7) MatchClass_InRange-12 2.12µs ± 0% 2.13µs ± 0% +0.23% (p=0.000 n=10+10) ReplaceAll-12 1.41µs ± 0% 1.39µs ± 0% -1.30% (p=0.000 n=7+10) AnchoredLiteralShortNonMatch-12 89.8ns ± 0% 83.2ns ± 0% -7.35% (p=0.000 n=8+8) AnchoredLiteralLongNonMatch-12 105ns ± 3% 105ns ± 0% ~ (p=0.186 n=10+10) AnchoredShortMatch-12 141ns ± 0% 131ns ± 0% -7.09% (p=0.000 n=9+10) AnchoredLongMatch-12 276ns ± 4% 267ns ± 0% -3.23% (p=0.000 n=10+10) OnePassShortA-12 620ns ± 0% 611ns ± 0% -1.39% (p=0.000 n=10+9) NotOnePassShortA-12 575ns ± 3% 552ns ± 0% -3.97% (p=0.000 n=10+8) OnePassShortB-12 493ns ± 0% 491ns ± 0% -0.33% (p=0.000 n=8+8) NotOnePassShortB-12 423ns ± 0% 412ns ± 0% -2.60% (p=0.000 n=8+9) OnePassLongPrefix-12 112ns ± 0% 112ns ± 0% ~ (all equal) OnePassLongNotPrefix-12 405ns ± 0% 410ns ± 0% +1.23% (p=0.000 n=8+9) MatchParallelShared-12 501ns ± 1% 39ns ± 1% -92.27% (p=0.000 n=10+10) MatchParallelCopied-12 39.1ns ± 0% 39.2ns ± 3% ~ (p=0.785 n=6+10) QuoteMetaAll-12 94.6ns ± 0% 94.6ns ± 0% ~ (p=0.439 n=10+8) QuoteMetaNone-12 52.7ns ± 0% 52.7ns ± 0% ~ (all equal) Match/Easy0/32-12 79.1ns ± 0% 72.9ns ± 0% -7.85% (p=0.000 n=9+9) Match/Easy0/1K-12 307ns ± 1% 298ns ± 0% -2.99% (p=0.000 n=10+6) Match/Easy0/32K-12 4.65µs ± 2% 4.60µs ± 2% ~ (p=0.159 n=10+10) Match/Easy0/1M-12 234µs ± 0% 235µs ± 0% +0.17% (p=0.003 n=10+10) Match/Easy0/32M-12 7.98ms ± 1% 7.96ms ± 0% ~ (p=0.278 n=9+10) Match/Easy0i/32-12 1.13µs ± 1% 1.09µs ± 0% -3.24% (p=0.000 n=9+8) Match/Easy0i/1K-12 32.5µs ± 0% 31.7µs ± 0% -2.66% (p=0.000 n=9+9) Match/Easy0i/32K-12 1.59ms ± 0% 1.61ms ± 0% +0.75% (p=0.000 n=9+9) Match/Easy0i/1M-12 51.0ms ± 0% 51.4ms ± 0% +0.77% (p=0.000 n=10+8) Match/Easy0i/32M-12 1.63s ± 0% 1.65s ± 1% +1.24% (p=0.000 n=7+9) Match/Easy1/32-12 75.1ns ± 1% 67.9ns ± 0% -9.54% (p=0.000 n=8+8) Match/Easy1/1K-12 861ns ± 0% 884ns ± 0% +2.71% (p=0.000 n=8+9) Match/Easy1/32K-12 39.2µs ± 1% 39.2µs ± 0% ~ (p=0.090 n=10+9) Match/Easy1/1M-12 1.38ms ± 0% 1.39ms ± 0% ~ (p=0.095 n=10+9) Match/Easy1/32M-12 44.2ms ± 1% 44.2ms ± 1% ~ (p=0.218 n=10+10) Match/Medium/32-12 1.04µs ± 1% 1.05µs ± 0% +1.05% (p=0.000 n=9+8) Match/Medium/1K-12 31.3µs ± 0% 31.3µs ± 0% -0.14% (p=0.004 n=9+9) Match/Medium/32K-12 1.44ms ± 0% 1.45ms ± 0% +0.18% (p=0.001 n=8+8) Match/Medium/1M-12 46.1ms ± 0% 46.2ms ± 0% +0.13% (p=0.003 n=6+9) Match/Medium/32M-12 1.48s ± 0% 1.48s ± 0% +0.20% (p=0.002 n=9+8) Match/Hard/32-12 1.54µs ± 1% 1.49µs ± 0% -3.60% (p=0.000 n=9+10) Match/Hard/1K-12 46.4µs ± 1% 45.1µs ± 1% -2.78% (p=0.000 n=9+10) Match/Hard/32K-12 2.19ms ± 0% 2.18ms ± 1% -0.51% (p=0.006 n=8+9) Match/Hard/1M-12 70.1ms ± 0% 69.7ms ± 1% -0.52% (p=0.006 n=8+9) Match/Hard/32M-12 2.24s ± 0% 2.23s ± 1% -0.42% (p=0.046 n=8+9) Match/Hard1/32-12 8.17µs ± 1% 7.89µs ± 0% -3.42% (p=0.000 n=8+9) Match/Hard1/1K-12 254µs ± 2% 244µs ± 0% -3.91% (p=0.000 n=9+9) Match/Hard1/32K-12 9.58ms ± 1% 10.35ms ± 0% +8.00% (p=0.000 n=10+10) Match/Hard1/1M-12 306ms ± 1% 331ms ± 0% +8.27% (p=0.000 n=9+8) Match/Hard1/32M-12 9.79s ± 1% 10.60s ± 0% +8.29% (p=0.000 n=9+8) Match_onepass_regex/32-12 808ns ± 0% 812ns ± 0% +0.47% (p=0.000 n=8+10) Match_onepass_regex/1K-12 27.8µs ± 0% 28.5µs ± 0% +2.32% (p=0.000 n=8+10) Match_onepass_regex/32K-12 925µs ± 0% 936µs ± 0% +1.24% (p=0.000 n=9+10) Match_onepass_regex/1M-12 29.5ms ± 0% 30.2ms ± 0% +2.38% (p=0.000 n=10+10) Match_onepass_regex/32M-12 945ms ± 0% 970ms ± 0% +2.60% (p=0.000 n=9+10) CompileOnepass-12 4.67µs ± 0% 4.63µs ± 1% -0.84% (p=0.000 n=10+10) [Geo mean] 24.5µs 23.3µs -5.04% https://perf.golang.org/search?q=upload:20181004.1 Change-Id: Idbc2b76223718265657819ff38be2d9aba1c54b4 Reviewed-on: https://go-review.googlesource.com/c/139779 Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-09-28 16:37:16 -04:00
if re.prog.Inst[pc].Op != syntax.InstFail && (arg || b.shouldVisit(pc, pos)) {
regexp: make (*bitState).push inlinable By refactoring job.arg from int with 0/1 as the only valid values into bool and simplifying (*bitState).push, we reduce the number of nodes below the inlining threshold. This improves backtracking regexp performance by 5-10% and go1 geomean by 1.7% Full performance data below: name old time/op new time/op delta Find-6 510ns ± 0% 480ns ± 1% -5.90% (p=0.000 n=10+10) FindString-6 504ns ± 1% 479ns ± 1% -5.10% (p=0.000 n=10+10) FindSubmatch-6 689ns ± 1% 659ns ± 1% -4.27% (p=0.000 n=9+10) FindStringSubmatch-6 659ns ± 0% 628ns ± 1% -4.69% (p=0.000 n=8+10) Literal-6 174ns ± 1% 171ns ± 1% -1.50% (p=0.000 n=10+10) NotLiteral-6 2.89µs ± 1% 2.72µs ± 0% -5.84% (p=0.000 n=10+9) MatchClass-6 4.65µs ± 1% 4.28µs ± 1% -7.96% (p=0.000 n=10+10) MatchClass_InRange-6 4.15µs ± 1% 3.80µs ± 0% -8.61% (p=0.000 n=10+8) ReplaceAll-6 2.72µs ± 1% 2.60µs ± 1% -4.68% (p=0.000 n=10+10) AnchoredLiteralShortNonMatch-6 158ns ± 1% 153ns ± 1% -3.03% (p=0.000 n=10+10) AnchoredLiteralLongNonMatch-6 176ns ± 1% 176ns ± 0% ~ (p=1.000 n=10+9) AnchoredShortMatch-6 260ns ± 0% 255ns ± 1% -1.84% (p=0.000 n=9+10) AnchoredLongMatch-6 456ns ± 0% 455ns ± 0% -0.19% (p=0.008 n=8+10) OnePassShortA-6 1.13µs ± 1% 1.12µs ± 0% -0.57% (p=0.046 n=10+8) NotOnePassShortA-6 1.14µs ± 1% 1.14µs ± 1% ~ (p=0.162 n=10+10) OnePassShortB-6 908ns ± 0% 893ns ± 0% -1.60% (p=0.000 n=8+9) NotOnePassShortB-6 857ns ± 0% 803ns ± 1% -6.34% (p=0.000 n=8+10) OnePassLongPrefix-6 190ns ± 0% 190ns ± 1% ~ (p=0.059 n=8+10) OnePassLongNotPrefix-6 722ns ± 1% 722ns ± 1% ~ (p=0.451 n=10+10) MatchParallelShared-6 810ns ± 2% 807ns ± 2% ~ (p=0.643 n=10+10) MatchParallelCopied-6 72.1ns ± 1% 69.4ns ± 1% -3.81% (p=0.000 n=10+10) QuoteMetaAll-6 213ns ± 2% 216ns ± 3% ~ (p=0.284 n=10+10) QuoteMetaNone-6 89.7ns ± 1% 89.8ns ± 1% ~ (p=0.616 n=10+10) Match/Easy0/32-6 127ns ± 1% 127ns ± 1% ~ (p=0.977 n=10+10) Match/Easy0/1K-6 566ns ± 0% 566ns ± 0% ~ (p=1.000 n=8+8) Match/Easy0/32K-6 9.30µs ± 1% 9.28µs ± 1% ~ (p=0.529 n=10+10) Match/Easy0/1M-6 460µs ± 1% 460µs ± 1% ~ (p=0.853 n=10+10) Match/Easy0/32M-6 15.0ms ± 0% 15.1ms ± 0% +0.77% (p=0.000 n=9+8) Match/Easy0i/32-6 2.10µs ± 1% 1.98µs ± 0% -6.02% (p=0.000 n=10+8) Match/Easy0i/1K-6 61.5µs ± 0% 57.2µs ± 0% -6.97% (p=0.000 n=10+9) Match/Easy0i/32K-6 2.75ms ± 0% 2.72ms ± 0% -1.10% (p=0.000 n=9+9) Match/Easy0i/1M-6 88.0ms ± 0% 86.9ms ± 1% -1.29% (p=0.000 n=8+10) Match/Easy0i/32M-6 2.82s ± 0% 2.77s ± 1% -1.81% (p=0.000 n=8+10) Match/Easy1/32-6 123ns ± 1% 124ns ± 1% +0.90% (p=0.001 n=10+10) Match/Easy1/1K-6 1.70µs ± 1% 1.65µs ± 0% -3.18% (p=0.000 n=9+10) Match/Easy1/32K-6 69.1µs ± 0% 68.4µs ± 1% -0.95% (p=0.000 n=8+10) Match/Easy1/1M-6 2.46ms ± 1% 2.42ms ± 1% -1.66% (p=0.000 n=10+10) Match/Easy1/32M-6 78.4ms ± 1% 77.5ms ± 0% -1.08% (p=0.000 n=10+9) Match/Medium/32-6 2.07µs ± 1% 1.91µs ± 1% -7.69% (p=0.000 n=10+10) Match/Medium/1K-6 62.8µs ± 0% 58.0µs ± 1% -7.70% (p=0.000 n=8+10) Match/Medium/32K-6 2.63ms ± 1% 2.58ms ± 1% -2.14% (p=0.000 n=10+10) Match/Medium/1M-6 84.6ms ± 0% 82.5ms ± 0% -2.37% (p=0.000 n=8+9) Match/Medium/32M-6 2.71s ± 0% 2.64s ± 0% -2.46% (p=0.000 n=10+9) Match/Hard/32-6 3.26µs ± 1% 2.98µs ± 1% -8.49% (p=0.000 n=10+10) Match/Hard/1K-6 100µs ± 0% 90µs ± 1% -9.55% (p=0.000 n=9+10) Match/Hard/32K-6 3.82ms ± 0% 3.82ms ± 1% ~ (p=0.515 n=8+10) Match/Hard/1M-6 122ms ± 1% 123ms ± 0% +0.66% (p=0.000 n=10+8) Match/Hard/32M-6 3.89s ± 1% 3.91s ± 1% ~ (p=0.105 n=10+10) Match/Hard1/32-6 18.1µs ± 1% 16.1µs ± 1% -11.31% (p=0.000 n=10+10) Match/Hard1/1K-6 565µs ± 0% 493µs ± 1% -12.65% (p=0.000 n=8+10) Match/Hard1/32K-6 18.8ms ± 0% 18.8ms ± 1% ~ (p=0.905 n=9+10) Match/Hard1/1M-6 602ms ± 1% 602ms ± 1% ~ (p=0.278 n=9+10) Match/Hard1/32M-6 19.1s ± 1% 19.2s ± 1% +0.31% (p=0.035 n=9+10) Match_onepass_regex/32-6 6.32µs ± 1% 6.34µs ± 1% ~ (p=0.060 n=10+10) Match_onepass_regex/1K-6 204µs ± 1% 204µs ± 1% ~ (p=0.842 n=9+10) Match_onepass_regex/32K-6 6.53ms ± 0% 6.55ms ± 1% +0.36% (p=0.005 n=10+10) Match_onepass_regex/1M-6 209ms ± 0% 208ms ± 1% -0.65% (p=0.034 n=8+10) Match_onepass_regex/32M-6 6.72s ± 0% 6.68s ± 1% -0.74% (p=0.000 n=9+10) CompileOnepass/^(?:(?:(?:.(?:$))?))...-6 7.02µs ± 1% 7.02µs ± 1% ~ (p=0.671 n=10+10) CompileOnepass/^abcd$-6 5.65µs ± 1% 5.65µs ± 1% ~ (p=0.411 n=10+9) CompileOnepass/^(?:(?:a{0,})*?)$-6 7.06µs ± 1% 7.06µs ± 1% ~ (p=0.912 n=10+10) CompileOnepass/^(?:(?:a+)*)$-6 6.40µs ± 1% 6.41µs ± 1% ~ (p=0.699 n=10+10) CompileOnepass/^(?:(?:a|(?:aa)))$-6 8.18µs ± 2% 8.16µs ± 1% ~ (p=0.529 n=10+10) CompileOnepass/^(?:[^\s\S])$-6 5.08µs ± 1% 5.17µs ± 1% +1.77% (p=0.000 n=9+10) CompileOnepass/^(?:(?:(?:a*)+))$-6 6.86µs ± 1% 6.85µs ± 0% ~ (p=0.190 n=10+9) CompileOnepass/^[a-c]+$-6 5.14µs ± 1% 5.11µs ± 0% -0.53% (p=0.041 n=10+10) CompileOnepass/^[a-c]*$-6 5.62µs ± 1% 5.63µs ± 1% ~ (p=0.382 n=10+10) CompileOnepass/^(?:a*)$-6 5.76µs ± 1% 5.73µs ± 1% -0.41% (p=0.008 n=9+10) CompileOnepass/^(?:(?:aa)|a)$-6 7.89µs ± 1% 7.84µs ± 1% -0.66% (p=0.020 n=10+10) CompileOnepass/^...$-6 5.38µs ± 1% 5.38µs ± 1% ~ (p=0.857 n=9+10) CompileOnepass/^(?:a|(?:aa))$-6 7.80µs ± 2% 7.82µs ± 1% ~ (p=0.342 n=10+10) CompileOnepass/^a((b))c$-6 7.75µs ± 1% 7.78µs ± 1% ~ (p=0.172 n=10+10) CompileOnepass/^a.[l-nA-Cg-j]?e$-6 8.39µs ± 1% 8.42µs ± 1% ~ (p=0.138 n=10+10) CompileOnepass/^a((b))$-6 6.92µs ± 1% 6.95µs ± 1% ~ (p=0.159 n=10+10) CompileOnepass/^a(?:(b)|(c))c$-6 10.0µs ± 1% 10.0µs ± 1% ~ (p=0.896 n=10+10) CompileOnepass/^a(?:b|c)$-6 5.62µs ± 1% 5.66µs ± 1% +0.71% (p=0.023 n=10+10) CompileOnepass/^a(?:b?|c)$-6 8.49µs ± 1% 8.43µs ± 1% -0.69% (p=0.010 n=10+10) CompileOnepass/^a(?:b?|c+)$-6 9.26µs ± 1% 9.28µs ± 1% ~ (p=0.448 n=10+10) CompileOnepass/^a(?:bc)+$-6 6.52µs ± 1% 6.46µs ± 2% -1.02% (p=0.003 n=10+10) CompileOnepass/^a(?:[bcd])+$-6 6.29µs ± 1% 6.32µs ± 1% ~ (p=0.256 n=10+10) CompileOnepass/^a((?:[bcd])+)$-6 7.77µs ± 1% 7.79µs ± 1% ~ (p=0.105 n=10+10) CompileOnepass/^a(:?b|c)*d$-6 14.0µs ± 1% 13.9µs ± 1% -0.69% (p=0.003 n=10+10) CompileOnepass/^.bc(d|e)*$-6 8.96µs ± 1% 9.06µs ± 1% +1.20% (p=0.000 n=10+9) CompileOnepass/^loooooooooooooooooo...-6 219µs ± 1% 220µs ± 1% +0.63% (p=0.006 n=9+10) [Geo mean] 31.6µs 31.1µs -1.82% name old speed new speed delta QuoteMetaAll-6 65.5MB/s ± 2% 64.8MB/s ± 3% ~ (p=0.315 n=10+10) QuoteMetaNone-6 290MB/s ± 1% 290MB/s ± 1% ~ (p=0.755 n=10+10) Match/Easy0/32-6 250MB/s ± 0% 251MB/s ± 1% ~ (p=0.277 n=8+9) Match/Easy0/1K-6 1.81GB/s ± 0% 1.81GB/s ± 0% ~ (p=0.408 n=8+10) Match/Easy0/32K-6 3.52GB/s ± 1% 3.53GB/s ± 1% ~ (p=0.529 n=10+10) Match/Easy0/1M-6 2.28GB/s ± 1% 2.28GB/s ± 1% ~ (p=0.853 n=10+10) Match/Easy0/32M-6 2.24GB/s ± 0% 2.23GB/s ± 0% -0.76% (p=0.000 n=9+8) Match/Easy0i/32-6 15.2MB/s ± 1% 16.2MB/s ± 0% +6.43% (p=0.000 n=10+9) Match/Easy0i/1K-6 16.6MB/s ± 0% 17.9MB/s ± 0% +7.48% (p=0.000 n=10+9) Match/Easy0i/32K-6 11.9MB/s ± 0% 12.0MB/s ± 0% +1.11% (p=0.000 n=9+9) Match/Easy0i/1M-6 11.9MB/s ± 0% 12.1MB/s ± 1% +1.31% (p=0.000 n=8+10) Match/Easy0i/32M-6 11.9MB/s ± 0% 12.1MB/s ± 1% +1.84% (p=0.000 n=8+10) Match/Easy1/32-6 260MB/s ± 1% 258MB/s ± 1% -0.91% (p=0.001 n=10+10) Match/Easy1/1K-6 601MB/s ± 1% 621MB/s ± 0% +3.28% (p=0.000 n=9+10) Match/Easy1/32K-6 474MB/s ± 0% 479MB/s ± 1% +0.96% (p=0.000 n=8+10) Match/Easy1/1M-6 426MB/s ± 1% 433MB/s ± 1% +1.68% (p=0.000 n=10+10) Match/Easy1/32M-6 428MB/s ± 1% 433MB/s ± 0% +1.09% (p=0.000 n=10+9) Match/Medium/32-6 15.4MB/s ± 1% 16.7MB/s ± 1% +8.23% (p=0.000 n=10+9) Match/Medium/1K-6 16.3MB/s ± 1% 17.7MB/s ± 1% +8.43% (p=0.000 n=9+10) Match/Medium/32K-6 12.5MB/s ± 1% 12.7MB/s ± 1% +2.15% (p=0.000 n=10+10) Match/Medium/1M-6 12.4MB/s ± 0% 12.7MB/s ± 0% +2.44% (p=0.000 n=8+9) Match/Medium/32M-6 12.4MB/s ± 0% 12.7MB/s ± 0% +2.52% (p=0.000 n=10+9) Match/Hard/32-6 9.82MB/s ± 1% 10.73MB/s ± 1% +9.29% (p=0.000 n=10+10) Match/Hard/1K-6 10.2MB/s ± 0% 11.3MB/s ± 1% +10.56% (p=0.000 n=9+10) Match/Hard/32K-6 8.58MB/s ± 0% 8.58MB/s ± 1% ~ (p=0.554 n=8+10) Match/Hard/1M-6 8.59MB/s ± 1% 8.53MB/s ± 0% -0.70% (p=0.000 n=10+8) Match/Hard/32M-6 8.62MB/s ± 1% 8.59MB/s ± 1% ~ (p=0.098 n=10+10) Match/Hard1/32-6 1.77MB/s ± 1% 1.99MB/s ± 1% +12.40% (p=0.000 n=10+8) Match/Hard1/1K-6 1.81MB/s ± 1% 2.08MB/s ± 1% +14.55% (p=0.000 n=10+10) Match/Hard1/32K-6 1.74MB/s ± 0% 1.74MB/s ± 0% ~ (p=0.108 n=9+10) Match/Hard1/1M-6 1.74MB/s ± 0% 1.74MB/s ± 1% ~ (p=1.000 n=9+10) Match/Hard1/32M-6 1.75MB/s ± 0% 1.75MB/s ± 1% ~ (p=0.157 n=9+10) Match_onepass_regex/32-6 5.05MB/s ± 0% 5.05MB/s ± 1% ~ (p=0.262 n=8+10) Match_onepass_regex/1K-6 5.02MB/s ± 1% 5.02MB/s ± 1% ~ (p=0.677 n=9+10) Match_onepass_regex/32K-6 5.02MB/s ± 0% 4.99MB/s ± 0% -0.47% (p=0.000 n=10+9) Match_onepass_regex/1M-6 5.01MB/s ± 0% 5.04MB/s ± 1% +0.68% (p=0.017 n=8+10) Match_onepass_regex/32M-6 4.99MB/s ± 0% 5.03MB/s ± 1% +0.74% (p=0.000 n=10+10) [Geo mean] 29.1MB/s 29.8MB/s +2.44% go1 data for reference name old time/op new time/op delta BinaryTree17-6 4.39s ± 1% 4.37s ± 0% -0.58% (p=0.006 n=9+9) Fannkuch11-6 5.13s ± 0% 5.18s ± 0% +0.87% (p=0.000 n=8+8) FmtFprintfEmpty-6 74.2ns ± 0% 71.7ns ± 3% -3.41% (p=0.000 n=10+10) FmtFprintfString-6 120ns ± 1% 122ns ± 2% ~ (p=0.333 n=10+10) FmtFprintfInt-6 127ns ± 1% 127ns ± 1% ~ (p=0.809 n=10+10) FmtFprintfIntInt-6 186ns ± 0% 188ns ± 1% +1.02% (p=0.002 n=8+10) FmtFprintfPrefixedInt-6 223ns ± 1% 222ns ± 2% ~ (p=0.421 n=10+10) FmtFprintfFloat-6 374ns ± 0% 376ns ± 1% +0.43% (p=0.030 n=8+10) FmtManyArgs-6 795ns ± 0% 788ns ± 1% -0.79% (p=0.000 n=8+9) GobDecode-6 10.9ms ± 1% 10.9ms ± 0% ~ (p=0.079 n=10+9) GobEncode-6 8.60ms ± 1% 8.56ms ± 0% -0.52% (p=0.004 n=10+10) Gzip-6 378ms ± 1% 386ms ± 1% +2.28% (p=0.000 n=10+10) Gunzip-6 63.7ms ± 0% 62.3ms ± 0% -2.22% (p=0.000 n=9+8) HTTPClientServer-6 120µs ± 3% 114µs ± 3% -4.99% (p=0.000 n=10+10) JSONEncode-6 20.3ms ± 1% 19.9ms ± 0% -1.90% (p=0.000 n=9+10) JSONDecode-6 84.3ms ± 0% 83.7ms ± 0% -0.76% (p=0.000 n=8+8) Mandelbrot200-6 6.91ms ± 0% 6.89ms ± 0% -0.31% (p=0.000 n=9+8) GoParse-6 5.49ms ± 0% 5.47ms ± 1% ~ (p=0.101 n=8+10) RegexpMatchEasy0_32-6 130ns ± 0% 128ns ± 0% -1.54% (p=0.002 n=8+10) RegexpMatchEasy0_1K-6 322ns ± 1% 322ns ± 0% ~ (p=0.525 n=10+9) RegexpMatchEasy1_32-6 124ns ± 0% 124ns ± 0% -0.32% (p=0.046 n=8+10) RegexpMatchEasy1_1K-6 570ns ± 0% 548ns ± 1% -3.76% (p=0.000 n=10+10) RegexpMatchMedium_32-6 196ns ± 0% 183ns ± 1% -6.61% (p=0.000 n=8+10) RegexpMatchMedium_1K-6 64.3µs ± 0% 59.0µs ± 1% -8.31% (p=0.000 n=8+10) RegexpMatchHard_32-6 3.08µs ± 0% 2.80µs ± 0% -8.96% (p=0.000 n=8+9) RegexpMatchHard_1K-6 93.0µs ± 0% 84.5µs ± 1% -9.17% (p=0.000 n=8+9) Revcomp-6 647ms ± 2% 646ms ± 1% ~ (p=0.720 n=10+9) Template-6 92.3ms ± 0% 91.7ms ± 0% -0.65% (p=0.000 n=8+8) TimeParse-6 490ns ± 0% 488ns ± 0% -0.43% (p=0.000 n=10+10) TimeFormat-6 513ns ± 0% 513ns ± 1% ~ (p=0.144 n=9+10) [Geo mean] 79.1µs 77.7µs -1.73% name old speed new speed delta GobDecode-6 70.1MB/s ± 1% 70.3MB/s ± 0% ~ (p=0.078 n=10+9) GobEncode-6 89.2MB/s ± 1% 89.7MB/s ± 0% +0.52% (p=0.004 n=10+10) Gzip-6 51.4MB/s ± 1% 50.2MB/s ± 1% -2.23% (p=0.000 n=10+10) Gunzip-6 304MB/s ± 0% 311MB/s ± 0% +2.27% (p=0.000 n=9+8) JSONEncode-6 95.8MB/s ± 1% 97.7MB/s ± 0% +1.93% (p=0.000 n=9+10) JSONDecode-6 23.0MB/s ± 0% 23.2MB/s ± 0% +0.76% (p=0.000 n=8+8) GoParse-6 10.6MB/s ± 0% 10.6MB/s ± 1% ~ (p=0.111 n=8+10) RegexpMatchEasy0_32-6 244MB/s ± 0% 249MB/s ± 0% +2.06% (p=0.000 n=9+10) RegexpMatchEasy0_1K-6 3.18GB/s ± 1% 3.17GB/s ± 0% ~ (p=0.211 n=10+9) RegexpMatchEasy1_32-6 257MB/s ± 0% 258MB/s ± 0% +0.37% (p=0.000 n=8+8) RegexpMatchEasy1_1K-6 1.80GB/s ± 0% 1.87GB/s ± 1% +3.91% (p=0.000 n=10+10) RegexpMatchMedium_32-6 5.08MB/s ± 0% 5.43MB/s ± 1% +7.03% (p=0.000 n=8+10) RegexpMatchMedium_1K-6 15.9MB/s ± 0% 17.4MB/s ± 1% +9.08% (p=0.000 n=8+10) RegexpMatchHard_32-6 10.4MB/s ± 0% 11.4MB/s ± 0% +9.82% (p=0.000 n=8+9) RegexpMatchHard_1K-6 11.0MB/s ± 0% 12.1MB/s ± 1% +10.10% (p=0.000 n=8+9) Revcomp-6 393MB/s ± 2% 394MB/s ± 1% ~ (p=0.720 n=10+9) Template-6 21.0MB/s ± 0% 21.2MB/s ± 0% +0.66% (p=0.000 n=8+8) [Geo mean] 74.2MB/s 76.2MB/s +2.70% Updates #21851 Change-Id: Ie88455db925f422a828f8528293790726a9c036b Reviewed-on: https://go-review.googlesource.com/65491 Run-TryBot: Ilya Tocar <ilya.tocar@intel.com> Reviewed-by: Daniel Martí <mvdan@mvdan.cc> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2017-09-22 15:15:23 -05:00
b.jobs = append(b.jobs, job{pc: pc, arg: arg, pos: pos})
regexp: port RE2's bitstate backtracker to the regexp package This is a port of RE2's bitstate backtracker, which triggers under the same conditions that the RE2 backtracker triggers. However I wasn't sure how to port over some of the optimizations in the RE2 backtracker, and there is a ~2% penalty on benchmarks that don't trigger the backtracker. benchmark old ns/op new ns/op delta BenchmarkLiteral 312 189 -39.42% BenchmarkNotLiteral 4435 3001 -32.33% BenchmarkMatchClass 5758 4378 -23.97% BenchmarkMatchClass_InRange 5385 4084 -24.16% BenchmarkReplaceAll 5291 3505 -33.76% BenchmarkAnchoredLiteralShortNonMatch 190 200 +5.26% BenchmarkAnchoredLiteralLongNonMatch 189 194 +2.65% BenchmarkAnchoredShortMatch 479 304 -36.53% BenchmarkAnchoredLongMatch 478 499 +4.39% BenchmarkOnePassShortA 791 798 +0.88% BenchmarkNotOnePassShortA 3202 1571 -50.94% BenchmarkOnePassShortB 614 633 +3.09% BenchmarkNotOnePassShortB 2685 881 -67.19% BenchmarkOnePassLongPrefix 152 154 +1.32% BenchmarkOnePassLongNotPrefix 505 533 +5.54% BenchmarkMatchEasy0_32 139 171 +23.02% BenchmarkMatchEasy0_1K 653 1797 +175.19% BenchmarkMatchEasy0_32K 12032 13346 +10.92% BenchmarkMatchEasy0_1M 462882 461272 -0.35% BenchmarkMatchEasy0_32M 15015339 15365238 +2.33% BenchmarkMatchEasy1_32 122 168 +37.70% BenchmarkMatchEasy1_1K 3339 2612 -21.77% BenchmarkMatchEasy1_32K 72330 71721 -0.84% BenchmarkMatchEasy1_1M 2545410 2652284 +4.20% BenchmarkMatchEasy1_32M 80072063 82609750 +3.17% BenchmarkMatchMedium_32 2359 1980 -16.07% BenchmarkMatchMedium_1K 75939 58593 -22.84% BenchmarkMatchMedium_32K 2450907 2501106 +2.05% BenchmarkMatchMedium_1M 78707697 80174418 +1.86% BenchmarkMatchMedium_32M 2535146010 2570896441 +1.41% BenchmarkMatchHard_32 4297 2960 -31.11% BenchmarkMatchHard_1K 133592 88997 -33.38% BenchmarkMatchHard_32K 4240445 4336907 +2.27% BenchmarkMatchHard_1M 136187006 139350238 +2.32% BenchmarkMatchHard_32M 4350855890 4478537306 +2.93% benchmark old MB/s new MB/s speedup BenchmarkMatchEasy0_32 228.74 186.11 0.81x BenchmarkMatchEasy0_1K 1565.91 569.64 0.36x BenchmarkMatchEasy0_32K 2723.31 2455.10 0.90x BenchmarkMatchEasy0_1M 2265.32 2273.22 1.00x BenchmarkMatchEasy0_32M 2234.68 2183.79 0.98x BenchmarkMatchEasy1_32 261.08 190.22 0.73x BenchmarkMatchEasy1_1K 306.59 391.91 1.28x BenchmarkMatchEasy1_32K 453.03 456.88 1.01x BenchmarkMatchEasy1_1M 411.95 395.35 0.96x BenchmarkMatchEasy1_32M 419.05 406.18 0.97x BenchmarkMatchMedium_32 13.56 16.16 1.19x BenchmarkMatchMedium_1K 13.48 17.48 1.30x BenchmarkMatchMedium_32K 13.37 13.10 0.98x BenchmarkMatchMedium_1M 13.32 13.08 0.98x BenchmarkMatchMedium_32M 13.24 13.05 0.99x BenchmarkMatchHard_32 7.45 10.81 1.45x BenchmarkMatchHard_1K 7.67 11.51 1.50x BenchmarkMatchHard_32K 7.73 7.56 0.98x BenchmarkMatchHard_1M 7.70 7.52 0.98x BenchmarkMatchHard_32M 7.71 7.49 0.97x Fixes #4154 Change-Id: Iff7fb9507f0872b320d08afc08679751ed1b28bc Reviewed-on: https://go-review.googlesource.com/2153 Reviewed-by: Russ Cox <rsc@golang.org>
2014-12-28 00:17:01 -08:00
}
}
// tryBacktrack runs a backtracking search starting at pos.
regexp: split bit-state execution out of machine struct This allows the bit-state executions to have their own pool of allocated structures. A step toward eliminating the per-Regexp machine cache. Note especially the -92% on MatchParallelShared. This is real but not a complete story: the other execution engines still need to be de-shared, but the benchmark was only using bit-state. The tiny slowdowns in unrelated code are noise. name old time/op new time/op delta Find-12 264ns ± 3% 254ns ± 0% -3.86% (p=0.000 n=10+9) FindAllNoMatches-12 140ns ± 2% 135ns ± 0% -3.91% (p=0.000 n=10+9) FindString-12 256ns ± 0% 247ns ± 0% -3.52% (p=0.000 n=8+8) FindSubmatch-12 339ns ± 1% 334ns ± 0% -1.41% (p=0.000 n=9+10) FindStringSubmatch-12 322ns ± 0% 321ns ± 0% -0.21% (p=0.005 n=8+9) Literal-12 100ns ± 2% 92ns ± 0% -8.10% (p=0.000 n=10+9) NotLiteral-12 1.50µs ± 0% 1.47µs ± 0% -1.91% (p=0.000 n=8+9) MatchClass-12 2.18µs ± 0% 2.17µs ± 0% -0.20% (p=0.001 n=10+7) MatchClass_InRange-12 2.12µs ± 0% 2.13µs ± 0% +0.23% (p=0.000 n=10+10) ReplaceAll-12 1.41µs ± 0% 1.39µs ± 0% -1.30% (p=0.000 n=7+10) AnchoredLiteralShortNonMatch-12 89.8ns ± 0% 83.2ns ± 0% -7.35% (p=0.000 n=8+8) AnchoredLiteralLongNonMatch-12 105ns ± 3% 105ns ± 0% ~ (p=0.186 n=10+10) AnchoredShortMatch-12 141ns ± 0% 131ns ± 0% -7.09% (p=0.000 n=9+10) AnchoredLongMatch-12 276ns ± 4% 267ns ± 0% -3.23% (p=0.000 n=10+10) OnePassShortA-12 620ns ± 0% 611ns ± 0% -1.39% (p=0.000 n=10+9) NotOnePassShortA-12 575ns ± 3% 552ns ± 0% -3.97% (p=0.000 n=10+8) OnePassShortB-12 493ns ± 0% 491ns ± 0% -0.33% (p=0.000 n=8+8) NotOnePassShortB-12 423ns ± 0% 412ns ± 0% -2.60% (p=0.000 n=8+9) OnePassLongPrefix-12 112ns ± 0% 112ns ± 0% ~ (all equal) OnePassLongNotPrefix-12 405ns ± 0% 410ns ± 0% +1.23% (p=0.000 n=8+9) MatchParallelShared-12 501ns ± 1% 39ns ± 1% -92.27% (p=0.000 n=10+10) MatchParallelCopied-12 39.1ns ± 0% 39.2ns ± 3% ~ (p=0.785 n=6+10) QuoteMetaAll-12 94.6ns ± 0% 94.6ns ± 0% ~ (p=0.439 n=10+8) QuoteMetaNone-12 52.7ns ± 0% 52.7ns ± 0% ~ (all equal) Match/Easy0/32-12 79.1ns ± 0% 72.9ns ± 0% -7.85% (p=0.000 n=9+9) Match/Easy0/1K-12 307ns ± 1% 298ns ± 0% -2.99% (p=0.000 n=10+6) Match/Easy0/32K-12 4.65µs ± 2% 4.60µs ± 2% ~ (p=0.159 n=10+10) Match/Easy0/1M-12 234µs ± 0% 235µs ± 0% +0.17% (p=0.003 n=10+10) Match/Easy0/32M-12 7.98ms ± 1% 7.96ms ± 0% ~ (p=0.278 n=9+10) Match/Easy0i/32-12 1.13µs ± 1% 1.09µs ± 0% -3.24% (p=0.000 n=9+8) Match/Easy0i/1K-12 32.5µs ± 0% 31.7µs ± 0% -2.66% (p=0.000 n=9+9) Match/Easy0i/32K-12 1.59ms ± 0% 1.61ms ± 0% +0.75% (p=0.000 n=9+9) Match/Easy0i/1M-12 51.0ms ± 0% 51.4ms ± 0% +0.77% (p=0.000 n=10+8) Match/Easy0i/32M-12 1.63s ± 0% 1.65s ± 1% +1.24% (p=0.000 n=7+9) Match/Easy1/32-12 75.1ns ± 1% 67.9ns ± 0% -9.54% (p=0.000 n=8+8) Match/Easy1/1K-12 861ns ± 0% 884ns ± 0% +2.71% (p=0.000 n=8+9) Match/Easy1/32K-12 39.2µs ± 1% 39.2µs ± 0% ~ (p=0.090 n=10+9) Match/Easy1/1M-12 1.38ms ± 0% 1.39ms ± 0% ~ (p=0.095 n=10+9) Match/Easy1/32M-12 44.2ms ± 1% 44.2ms ± 1% ~ (p=0.218 n=10+10) Match/Medium/32-12 1.04µs ± 1% 1.05µs ± 0% +1.05% (p=0.000 n=9+8) Match/Medium/1K-12 31.3µs ± 0% 31.3µs ± 0% -0.14% (p=0.004 n=9+9) Match/Medium/32K-12 1.44ms ± 0% 1.45ms ± 0% +0.18% (p=0.001 n=8+8) Match/Medium/1M-12 46.1ms ± 0% 46.2ms ± 0% +0.13% (p=0.003 n=6+9) Match/Medium/32M-12 1.48s ± 0% 1.48s ± 0% +0.20% (p=0.002 n=9+8) Match/Hard/32-12 1.54µs ± 1% 1.49µs ± 0% -3.60% (p=0.000 n=9+10) Match/Hard/1K-12 46.4µs ± 1% 45.1µs ± 1% -2.78% (p=0.000 n=9+10) Match/Hard/32K-12 2.19ms ± 0% 2.18ms ± 1% -0.51% (p=0.006 n=8+9) Match/Hard/1M-12 70.1ms ± 0% 69.7ms ± 1% -0.52% (p=0.006 n=8+9) Match/Hard/32M-12 2.24s ± 0% 2.23s ± 1% -0.42% (p=0.046 n=8+9) Match/Hard1/32-12 8.17µs ± 1% 7.89µs ± 0% -3.42% (p=0.000 n=8+9) Match/Hard1/1K-12 254µs ± 2% 244µs ± 0% -3.91% (p=0.000 n=9+9) Match/Hard1/32K-12 9.58ms ± 1% 10.35ms ± 0% +8.00% (p=0.000 n=10+10) Match/Hard1/1M-12 306ms ± 1% 331ms ± 0% +8.27% (p=0.000 n=9+8) Match/Hard1/32M-12 9.79s ± 1% 10.60s ± 0% +8.29% (p=0.000 n=9+8) Match_onepass_regex/32-12 808ns ± 0% 812ns ± 0% +0.47% (p=0.000 n=8+10) Match_onepass_regex/1K-12 27.8µs ± 0% 28.5µs ± 0% +2.32% (p=0.000 n=8+10) Match_onepass_regex/32K-12 925µs ± 0% 936µs ± 0% +1.24% (p=0.000 n=9+10) Match_onepass_regex/1M-12 29.5ms ± 0% 30.2ms ± 0% +2.38% (p=0.000 n=10+10) Match_onepass_regex/32M-12 945ms ± 0% 970ms ± 0% +2.60% (p=0.000 n=9+10) CompileOnepass-12 4.67µs ± 0% 4.63µs ± 1% -0.84% (p=0.000 n=10+10) [Geo mean] 24.5µs 23.3µs -5.04% https://perf.golang.org/search?q=upload:20181004.1 Change-Id: Idbc2b76223718265657819ff38be2d9aba1c54b4 Reviewed-on: https://go-review.googlesource.com/c/139779 Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-09-28 16:37:16 -04:00
func (re *Regexp) tryBacktrack(b *bitState, i input, pc uint32, pos int) bool {
longest := re.longest
regexp: port RE2's bitstate backtracker to the regexp package This is a port of RE2's bitstate backtracker, which triggers under the same conditions that the RE2 backtracker triggers. However I wasn't sure how to port over some of the optimizations in the RE2 backtracker, and there is a ~2% penalty on benchmarks that don't trigger the backtracker. benchmark old ns/op new ns/op delta BenchmarkLiteral 312 189 -39.42% BenchmarkNotLiteral 4435 3001 -32.33% BenchmarkMatchClass 5758 4378 -23.97% BenchmarkMatchClass_InRange 5385 4084 -24.16% BenchmarkReplaceAll 5291 3505 -33.76% BenchmarkAnchoredLiteralShortNonMatch 190 200 +5.26% BenchmarkAnchoredLiteralLongNonMatch 189 194 +2.65% BenchmarkAnchoredShortMatch 479 304 -36.53% BenchmarkAnchoredLongMatch 478 499 +4.39% BenchmarkOnePassShortA 791 798 +0.88% BenchmarkNotOnePassShortA 3202 1571 -50.94% BenchmarkOnePassShortB 614 633 +3.09% BenchmarkNotOnePassShortB 2685 881 -67.19% BenchmarkOnePassLongPrefix 152 154 +1.32% BenchmarkOnePassLongNotPrefix 505 533 +5.54% BenchmarkMatchEasy0_32 139 171 +23.02% BenchmarkMatchEasy0_1K 653 1797 +175.19% BenchmarkMatchEasy0_32K 12032 13346 +10.92% BenchmarkMatchEasy0_1M 462882 461272 -0.35% BenchmarkMatchEasy0_32M 15015339 15365238 +2.33% BenchmarkMatchEasy1_32 122 168 +37.70% BenchmarkMatchEasy1_1K 3339 2612 -21.77% BenchmarkMatchEasy1_32K 72330 71721 -0.84% BenchmarkMatchEasy1_1M 2545410 2652284 +4.20% BenchmarkMatchEasy1_32M 80072063 82609750 +3.17% BenchmarkMatchMedium_32 2359 1980 -16.07% BenchmarkMatchMedium_1K 75939 58593 -22.84% BenchmarkMatchMedium_32K 2450907 2501106 +2.05% BenchmarkMatchMedium_1M 78707697 80174418 +1.86% BenchmarkMatchMedium_32M 2535146010 2570896441 +1.41% BenchmarkMatchHard_32 4297 2960 -31.11% BenchmarkMatchHard_1K 133592 88997 -33.38% BenchmarkMatchHard_32K 4240445 4336907 +2.27% BenchmarkMatchHard_1M 136187006 139350238 +2.32% BenchmarkMatchHard_32M 4350855890 4478537306 +2.93% benchmark old MB/s new MB/s speedup BenchmarkMatchEasy0_32 228.74 186.11 0.81x BenchmarkMatchEasy0_1K 1565.91 569.64 0.36x BenchmarkMatchEasy0_32K 2723.31 2455.10 0.90x BenchmarkMatchEasy0_1M 2265.32 2273.22 1.00x BenchmarkMatchEasy0_32M 2234.68 2183.79 0.98x BenchmarkMatchEasy1_32 261.08 190.22 0.73x BenchmarkMatchEasy1_1K 306.59 391.91 1.28x BenchmarkMatchEasy1_32K 453.03 456.88 1.01x BenchmarkMatchEasy1_1M 411.95 395.35 0.96x BenchmarkMatchEasy1_32M 419.05 406.18 0.97x BenchmarkMatchMedium_32 13.56 16.16 1.19x BenchmarkMatchMedium_1K 13.48 17.48 1.30x BenchmarkMatchMedium_32K 13.37 13.10 0.98x BenchmarkMatchMedium_1M 13.32 13.08 0.98x BenchmarkMatchMedium_32M 13.24 13.05 0.99x BenchmarkMatchHard_32 7.45 10.81 1.45x BenchmarkMatchHard_1K 7.67 11.51 1.50x BenchmarkMatchHard_32K 7.73 7.56 0.98x BenchmarkMatchHard_1M 7.70 7.52 0.98x BenchmarkMatchHard_32M 7.71 7.49 0.97x Fixes #4154 Change-Id: Iff7fb9507f0872b320d08afc08679751ed1b28bc Reviewed-on: https://go-review.googlesource.com/2153 Reviewed-by: Russ Cox <rsc@golang.org>
2014-12-28 00:17:01 -08:00
regexp: split bit-state execution out of machine struct This allows the bit-state executions to have their own pool of allocated structures. A step toward eliminating the per-Regexp machine cache. Note especially the -92% on MatchParallelShared. This is real but not a complete story: the other execution engines still need to be de-shared, but the benchmark was only using bit-state. The tiny slowdowns in unrelated code are noise. name old time/op new time/op delta Find-12 264ns ± 3% 254ns ± 0% -3.86% (p=0.000 n=10+9) FindAllNoMatches-12 140ns ± 2% 135ns ± 0% -3.91% (p=0.000 n=10+9) FindString-12 256ns ± 0% 247ns ± 0% -3.52% (p=0.000 n=8+8) FindSubmatch-12 339ns ± 1% 334ns ± 0% -1.41% (p=0.000 n=9+10) FindStringSubmatch-12 322ns ± 0% 321ns ± 0% -0.21% (p=0.005 n=8+9) Literal-12 100ns ± 2% 92ns ± 0% -8.10% (p=0.000 n=10+9) NotLiteral-12 1.50µs ± 0% 1.47µs ± 0% -1.91% (p=0.000 n=8+9) MatchClass-12 2.18µs ± 0% 2.17µs ± 0% -0.20% (p=0.001 n=10+7) MatchClass_InRange-12 2.12µs ± 0% 2.13µs ± 0% +0.23% (p=0.000 n=10+10) ReplaceAll-12 1.41µs ± 0% 1.39µs ± 0% -1.30% (p=0.000 n=7+10) AnchoredLiteralShortNonMatch-12 89.8ns ± 0% 83.2ns ± 0% -7.35% (p=0.000 n=8+8) AnchoredLiteralLongNonMatch-12 105ns ± 3% 105ns ± 0% ~ (p=0.186 n=10+10) AnchoredShortMatch-12 141ns ± 0% 131ns ± 0% -7.09% (p=0.000 n=9+10) AnchoredLongMatch-12 276ns ± 4% 267ns ± 0% -3.23% (p=0.000 n=10+10) OnePassShortA-12 620ns ± 0% 611ns ± 0% -1.39% (p=0.000 n=10+9) NotOnePassShortA-12 575ns ± 3% 552ns ± 0% -3.97% (p=0.000 n=10+8) OnePassShortB-12 493ns ± 0% 491ns ± 0% -0.33% (p=0.000 n=8+8) NotOnePassShortB-12 423ns ± 0% 412ns ± 0% -2.60% (p=0.000 n=8+9) OnePassLongPrefix-12 112ns ± 0% 112ns ± 0% ~ (all equal) OnePassLongNotPrefix-12 405ns ± 0% 410ns ± 0% +1.23% (p=0.000 n=8+9) MatchParallelShared-12 501ns ± 1% 39ns ± 1% -92.27% (p=0.000 n=10+10) MatchParallelCopied-12 39.1ns ± 0% 39.2ns ± 3% ~ (p=0.785 n=6+10) QuoteMetaAll-12 94.6ns ± 0% 94.6ns ± 0% ~ (p=0.439 n=10+8) QuoteMetaNone-12 52.7ns ± 0% 52.7ns ± 0% ~ (all equal) Match/Easy0/32-12 79.1ns ± 0% 72.9ns ± 0% -7.85% (p=0.000 n=9+9) Match/Easy0/1K-12 307ns ± 1% 298ns ± 0% -2.99% (p=0.000 n=10+6) Match/Easy0/32K-12 4.65µs ± 2% 4.60µs ± 2% ~ (p=0.159 n=10+10) Match/Easy0/1M-12 234µs ± 0% 235µs ± 0% +0.17% (p=0.003 n=10+10) Match/Easy0/32M-12 7.98ms ± 1% 7.96ms ± 0% ~ (p=0.278 n=9+10) Match/Easy0i/32-12 1.13µs ± 1% 1.09µs ± 0% -3.24% (p=0.000 n=9+8) Match/Easy0i/1K-12 32.5µs ± 0% 31.7µs ± 0% -2.66% (p=0.000 n=9+9) Match/Easy0i/32K-12 1.59ms ± 0% 1.61ms ± 0% +0.75% (p=0.000 n=9+9) Match/Easy0i/1M-12 51.0ms ± 0% 51.4ms ± 0% +0.77% (p=0.000 n=10+8) Match/Easy0i/32M-12 1.63s ± 0% 1.65s ± 1% +1.24% (p=0.000 n=7+9) Match/Easy1/32-12 75.1ns ± 1% 67.9ns ± 0% -9.54% (p=0.000 n=8+8) Match/Easy1/1K-12 861ns ± 0% 884ns ± 0% +2.71% (p=0.000 n=8+9) Match/Easy1/32K-12 39.2µs ± 1% 39.2µs ± 0% ~ (p=0.090 n=10+9) Match/Easy1/1M-12 1.38ms ± 0% 1.39ms ± 0% ~ (p=0.095 n=10+9) Match/Easy1/32M-12 44.2ms ± 1% 44.2ms ± 1% ~ (p=0.218 n=10+10) Match/Medium/32-12 1.04µs ± 1% 1.05µs ± 0% +1.05% (p=0.000 n=9+8) Match/Medium/1K-12 31.3µs ± 0% 31.3µs ± 0% -0.14% (p=0.004 n=9+9) Match/Medium/32K-12 1.44ms ± 0% 1.45ms ± 0% +0.18% (p=0.001 n=8+8) Match/Medium/1M-12 46.1ms ± 0% 46.2ms ± 0% +0.13% (p=0.003 n=6+9) Match/Medium/32M-12 1.48s ± 0% 1.48s ± 0% +0.20% (p=0.002 n=9+8) Match/Hard/32-12 1.54µs ± 1% 1.49µs ± 0% -3.60% (p=0.000 n=9+10) Match/Hard/1K-12 46.4µs ± 1% 45.1µs ± 1% -2.78% (p=0.000 n=9+10) Match/Hard/32K-12 2.19ms ± 0% 2.18ms ± 1% -0.51% (p=0.006 n=8+9) Match/Hard/1M-12 70.1ms ± 0% 69.7ms ± 1% -0.52% (p=0.006 n=8+9) Match/Hard/32M-12 2.24s ± 0% 2.23s ± 1% -0.42% (p=0.046 n=8+9) Match/Hard1/32-12 8.17µs ± 1% 7.89µs ± 0% -3.42% (p=0.000 n=8+9) Match/Hard1/1K-12 254µs ± 2% 244µs ± 0% -3.91% (p=0.000 n=9+9) Match/Hard1/32K-12 9.58ms ± 1% 10.35ms ± 0% +8.00% (p=0.000 n=10+10) Match/Hard1/1M-12 306ms ± 1% 331ms ± 0% +8.27% (p=0.000 n=9+8) Match/Hard1/32M-12 9.79s ± 1% 10.60s ± 0% +8.29% (p=0.000 n=9+8) Match_onepass_regex/32-12 808ns ± 0% 812ns ± 0% +0.47% (p=0.000 n=8+10) Match_onepass_regex/1K-12 27.8µs ± 0% 28.5µs ± 0% +2.32% (p=0.000 n=8+10) Match_onepass_regex/32K-12 925µs ± 0% 936µs ± 0% +1.24% (p=0.000 n=9+10) Match_onepass_regex/1M-12 29.5ms ± 0% 30.2ms ± 0% +2.38% (p=0.000 n=10+10) Match_onepass_regex/32M-12 945ms ± 0% 970ms ± 0% +2.60% (p=0.000 n=9+10) CompileOnepass-12 4.67µs ± 0% 4.63µs ± 1% -0.84% (p=0.000 n=10+10) [Geo mean] 24.5µs 23.3µs -5.04% https://perf.golang.org/search?q=upload:20181004.1 Change-Id: Idbc2b76223718265657819ff38be2d9aba1c54b4 Reviewed-on: https://go-review.googlesource.com/c/139779 Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-09-28 16:37:16 -04:00
b.push(re, pc, pos, false)
regexp: port RE2's bitstate backtracker to the regexp package This is a port of RE2's bitstate backtracker, which triggers under the same conditions that the RE2 backtracker triggers. However I wasn't sure how to port over some of the optimizations in the RE2 backtracker, and there is a ~2% penalty on benchmarks that don't trigger the backtracker. benchmark old ns/op new ns/op delta BenchmarkLiteral 312 189 -39.42% BenchmarkNotLiteral 4435 3001 -32.33% BenchmarkMatchClass 5758 4378 -23.97% BenchmarkMatchClass_InRange 5385 4084 -24.16% BenchmarkReplaceAll 5291 3505 -33.76% BenchmarkAnchoredLiteralShortNonMatch 190 200 +5.26% BenchmarkAnchoredLiteralLongNonMatch 189 194 +2.65% BenchmarkAnchoredShortMatch 479 304 -36.53% BenchmarkAnchoredLongMatch 478 499 +4.39% BenchmarkOnePassShortA 791 798 +0.88% BenchmarkNotOnePassShortA 3202 1571 -50.94% BenchmarkOnePassShortB 614 633 +3.09% BenchmarkNotOnePassShortB 2685 881 -67.19% BenchmarkOnePassLongPrefix 152 154 +1.32% BenchmarkOnePassLongNotPrefix 505 533 +5.54% BenchmarkMatchEasy0_32 139 171 +23.02% BenchmarkMatchEasy0_1K 653 1797 +175.19% BenchmarkMatchEasy0_32K 12032 13346 +10.92% BenchmarkMatchEasy0_1M 462882 461272 -0.35% BenchmarkMatchEasy0_32M 15015339 15365238 +2.33% BenchmarkMatchEasy1_32 122 168 +37.70% BenchmarkMatchEasy1_1K 3339 2612 -21.77% BenchmarkMatchEasy1_32K 72330 71721 -0.84% BenchmarkMatchEasy1_1M 2545410 2652284 +4.20% BenchmarkMatchEasy1_32M 80072063 82609750 +3.17% BenchmarkMatchMedium_32 2359 1980 -16.07% BenchmarkMatchMedium_1K 75939 58593 -22.84% BenchmarkMatchMedium_32K 2450907 2501106 +2.05% BenchmarkMatchMedium_1M 78707697 80174418 +1.86% BenchmarkMatchMedium_32M 2535146010 2570896441 +1.41% BenchmarkMatchHard_32 4297 2960 -31.11% BenchmarkMatchHard_1K 133592 88997 -33.38% BenchmarkMatchHard_32K 4240445 4336907 +2.27% BenchmarkMatchHard_1M 136187006 139350238 +2.32% BenchmarkMatchHard_32M 4350855890 4478537306 +2.93% benchmark old MB/s new MB/s speedup BenchmarkMatchEasy0_32 228.74 186.11 0.81x BenchmarkMatchEasy0_1K 1565.91 569.64 0.36x BenchmarkMatchEasy0_32K 2723.31 2455.10 0.90x BenchmarkMatchEasy0_1M 2265.32 2273.22 1.00x BenchmarkMatchEasy0_32M 2234.68 2183.79 0.98x BenchmarkMatchEasy1_32 261.08 190.22 0.73x BenchmarkMatchEasy1_1K 306.59 391.91 1.28x BenchmarkMatchEasy1_32K 453.03 456.88 1.01x BenchmarkMatchEasy1_1M 411.95 395.35 0.96x BenchmarkMatchEasy1_32M 419.05 406.18 0.97x BenchmarkMatchMedium_32 13.56 16.16 1.19x BenchmarkMatchMedium_1K 13.48 17.48 1.30x BenchmarkMatchMedium_32K 13.37 13.10 0.98x BenchmarkMatchMedium_1M 13.32 13.08 0.98x BenchmarkMatchMedium_32M 13.24 13.05 0.99x BenchmarkMatchHard_32 7.45 10.81 1.45x BenchmarkMatchHard_1K 7.67 11.51 1.50x BenchmarkMatchHard_32K 7.73 7.56 0.98x BenchmarkMatchHard_1M 7.70 7.52 0.98x BenchmarkMatchHard_32M 7.71 7.49 0.97x Fixes #4154 Change-Id: Iff7fb9507f0872b320d08afc08679751ed1b28bc Reviewed-on: https://go-review.googlesource.com/2153 Reviewed-by: Russ Cox <rsc@golang.org>
2014-12-28 00:17:01 -08:00
for len(b.jobs) > 0 {
l := len(b.jobs) - 1
// Pop job off the stack.
pc := b.jobs[l].pc
pos := b.jobs[l].pos
arg := b.jobs[l].arg
b.jobs = b.jobs[:l]
// Optimization: rather than push and pop,
// code that is going to Push and continue
// the loop simply updates ip, p, and arg
// and jumps to CheckAndLoop. We have to
regexp: port RE2's bitstate backtracker to the regexp package This is a port of RE2's bitstate backtracker, which triggers under the same conditions that the RE2 backtracker triggers. However I wasn't sure how to port over some of the optimizations in the RE2 backtracker, and there is a ~2% penalty on benchmarks that don't trigger the backtracker. benchmark old ns/op new ns/op delta BenchmarkLiteral 312 189 -39.42% BenchmarkNotLiteral 4435 3001 -32.33% BenchmarkMatchClass 5758 4378 -23.97% BenchmarkMatchClass_InRange 5385 4084 -24.16% BenchmarkReplaceAll 5291 3505 -33.76% BenchmarkAnchoredLiteralShortNonMatch 190 200 +5.26% BenchmarkAnchoredLiteralLongNonMatch 189 194 +2.65% BenchmarkAnchoredShortMatch 479 304 -36.53% BenchmarkAnchoredLongMatch 478 499 +4.39% BenchmarkOnePassShortA 791 798 +0.88% BenchmarkNotOnePassShortA 3202 1571 -50.94% BenchmarkOnePassShortB 614 633 +3.09% BenchmarkNotOnePassShortB 2685 881 -67.19% BenchmarkOnePassLongPrefix 152 154 +1.32% BenchmarkOnePassLongNotPrefix 505 533 +5.54% BenchmarkMatchEasy0_32 139 171 +23.02% BenchmarkMatchEasy0_1K 653 1797 +175.19% BenchmarkMatchEasy0_32K 12032 13346 +10.92% BenchmarkMatchEasy0_1M 462882 461272 -0.35% BenchmarkMatchEasy0_32M 15015339 15365238 +2.33% BenchmarkMatchEasy1_32 122 168 +37.70% BenchmarkMatchEasy1_1K 3339 2612 -21.77% BenchmarkMatchEasy1_32K 72330 71721 -0.84% BenchmarkMatchEasy1_1M 2545410 2652284 +4.20% BenchmarkMatchEasy1_32M 80072063 82609750 +3.17% BenchmarkMatchMedium_32 2359 1980 -16.07% BenchmarkMatchMedium_1K 75939 58593 -22.84% BenchmarkMatchMedium_32K 2450907 2501106 +2.05% BenchmarkMatchMedium_1M 78707697 80174418 +1.86% BenchmarkMatchMedium_32M 2535146010 2570896441 +1.41% BenchmarkMatchHard_32 4297 2960 -31.11% BenchmarkMatchHard_1K 133592 88997 -33.38% BenchmarkMatchHard_32K 4240445 4336907 +2.27% BenchmarkMatchHard_1M 136187006 139350238 +2.32% BenchmarkMatchHard_32M 4350855890 4478537306 +2.93% benchmark old MB/s new MB/s speedup BenchmarkMatchEasy0_32 228.74 186.11 0.81x BenchmarkMatchEasy0_1K 1565.91 569.64 0.36x BenchmarkMatchEasy0_32K 2723.31 2455.10 0.90x BenchmarkMatchEasy0_1M 2265.32 2273.22 1.00x BenchmarkMatchEasy0_32M 2234.68 2183.79 0.98x BenchmarkMatchEasy1_32 261.08 190.22 0.73x BenchmarkMatchEasy1_1K 306.59 391.91 1.28x BenchmarkMatchEasy1_32K 453.03 456.88 1.01x BenchmarkMatchEasy1_1M 411.95 395.35 0.96x BenchmarkMatchEasy1_32M 419.05 406.18 0.97x BenchmarkMatchMedium_32 13.56 16.16 1.19x BenchmarkMatchMedium_1K 13.48 17.48 1.30x BenchmarkMatchMedium_32K 13.37 13.10 0.98x BenchmarkMatchMedium_1M 13.32 13.08 0.98x BenchmarkMatchMedium_32M 13.24 13.05 0.99x BenchmarkMatchHard_32 7.45 10.81 1.45x BenchmarkMatchHard_1K 7.67 11.51 1.50x BenchmarkMatchHard_32K 7.73 7.56 0.98x BenchmarkMatchHard_1M 7.70 7.52 0.98x BenchmarkMatchHard_32M 7.71 7.49 0.97x Fixes #4154 Change-Id: Iff7fb9507f0872b320d08afc08679751ed1b28bc Reviewed-on: https://go-review.googlesource.com/2153 Reviewed-by: Russ Cox <rsc@golang.org>
2014-12-28 00:17:01 -08:00
// do the ShouldVisit check that Push
// would have, but we avoid the stack
// manipulation.
goto Skip
CheckAndLoop:
if !b.shouldVisit(pc, pos) {
continue
}
Skip:
regexp: split bit-state execution out of machine struct This allows the bit-state executions to have their own pool of allocated structures. A step toward eliminating the per-Regexp machine cache. Note especially the -92% on MatchParallelShared. This is real but not a complete story: the other execution engines still need to be de-shared, but the benchmark was only using bit-state. The tiny slowdowns in unrelated code are noise. name old time/op new time/op delta Find-12 264ns ± 3% 254ns ± 0% -3.86% (p=0.000 n=10+9) FindAllNoMatches-12 140ns ± 2% 135ns ± 0% -3.91% (p=0.000 n=10+9) FindString-12 256ns ± 0% 247ns ± 0% -3.52% (p=0.000 n=8+8) FindSubmatch-12 339ns ± 1% 334ns ± 0% -1.41% (p=0.000 n=9+10) FindStringSubmatch-12 322ns ± 0% 321ns ± 0% -0.21% (p=0.005 n=8+9) Literal-12 100ns ± 2% 92ns ± 0% -8.10% (p=0.000 n=10+9) NotLiteral-12 1.50µs ± 0% 1.47µs ± 0% -1.91% (p=0.000 n=8+9) MatchClass-12 2.18µs ± 0% 2.17µs ± 0% -0.20% (p=0.001 n=10+7) MatchClass_InRange-12 2.12µs ± 0% 2.13µs ± 0% +0.23% (p=0.000 n=10+10) ReplaceAll-12 1.41µs ± 0% 1.39µs ± 0% -1.30% (p=0.000 n=7+10) AnchoredLiteralShortNonMatch-12 89.8ns ± 0% 83.2ns ± 0% -7.35% (p=0.000 n=8+8) AnchoredLiteralLongNonMatch-12 105ns ± 3% 105ns ± 0% ~ (p=0.186 n=10+10) AnchoredShortMatch-12 141ns ± 0% 131ns ± 0% -7.09% (p=0.000 n=9+10) AnchoredLongMatch-12 276ns ± 4% 267ns ± 0% -3.23% (p=0.000 n=10+10) OnePassShortA-12 620ns ± 0% 611ns ± 0% -1.39% (p=0.000 n=10+9) NotOnePassShortA-12 575ns ± 3% 552ns ± 0% -3.97% (p=0.000 n=10+8) OnePassShortB-12 493ns ± 0% 491ns ± 0% -0.33% (p=0.000 n=8+8) NotOnePassShortB-12 423ns ± 0% 412ns ± 0% -2.60% (p=0.000 n=8+9) OnePassLongPrefix-12 112ns ± 0% 112ns ± 0% ~ (all equal) OnePassLongNotPrefix-12 405ns ± 0% 410ns ± 0% +1.23% (p=0.000 n=8+9) MatchParallelShared-12 501ns ± 1% 39ns ± 1% -92.27% (p=0.000 n=10+10) MatchParallelCopied-12 39.1ns ± 0% 39.2ns ± 3% ~ (p=0.785 n=6+10) QuoteMetaAll-12 94.6ns ± 0% 94.6ns ± 0% ~ (p=0.439 n=10+8) QuoteMetaNone-12 52.7ns ± 0% 52.7ns ± 0% ~ (all equal) Match/Easy0/32-12 79.1ns ± 0% 72.9ns ± 0% -7.85% (p=0.000 n=9+9) Match/Easy0/1K-12 307ns ± 1% 298ns ± 0% -2.99% (p=0.000 n=10+6) Match/Easy0/32K-12 4.65µs ± 2% 4.60µs ± 2% ~ (p=0.159 n=10+10) Match/Easy0/1M-12 234µs ± 0% 235µs ± 0% +0.17% (p=0.003 n=10+10) Match/Easy0/32M-12 7.98ms ± 1% 7.96ms ± 0% ~ (p=0.278 n=9+10) Match/Easy0i/32-12 1.13µs ± 1% 1.09µs ± 0% -3.24% (p=0.000 n=9+8) Match/Easy0i/1K-12 32.5µs ± 0% 31.7µs ± 0% -2.66% (p=0.000 n=9+9) Match/Easy0i/32K-12 1.59ms ± 0% 1.61ms ± 0% +0.75% (p=0.000 n=9+9) Match/Easy0i/1M-12 51.0ms ± 0% 51.4ms ± 0% +0.77% (p=0.000 n=10+8) Match/Easy0i/32M-12 1.63s ± 0% 1.65s ± 1% +1.24% (p=0.000 n=7+9) Match/Easy1/32-12 75.1ns ± 1% 67.9ns ± 0% -9.54% (p=0.000 n=8+8) Match/Easy1/1K-12 861ns ± 0% 884ns ± 0% +2.71% (p=0.000 n=8+9) Match/Easy1/32K-12 39.2µs ± 1% 39.2µs ± 0% ~ (p=0.090 n=10+9) Match/Easy1/1M-12 1.38ms ± 0% 1.39ms ± 0% ~ (p=0.095 n=10+9) Match/Easy1/32M-12 44.2ms ± 1% 44.2ms ± 1% ~ (p=0.218 n=10+10) Match/Medium/32-12 1.04µs ± 1% 1.05µs ± 0% +1.05% (p=0.000 n=9+8) Match/Medium/1K-12 31.3µs ± 0% 31.3µs ± 0% -0.14% (p=0.004 n=9+9) Match/Medium/32K-12 1.44ms ± 0% 1.45ms ± 0% +0.18% (p=0.001 n=8+8) Match/Medium/1M-12 46.1ms ± 0% 46.2ms ± 0% +0.13% (p=0.003 n=6+9) Match/Medium/32M-12 1.48s ± 0% 1.48s ± 0% +0.20% (p=0.002 n=9+8) Match/Hard/32-12 1.54µs ± 1% 1.49µs ± 0% -3.60% (p=0.000 n=9+10) Match/Hard/1K-12 46.4µs ± 1% 45.1µs ± 1% -2.78% (p=0.000 n=9+10) Match/Hard/32K-12 2.19ms ± 0% 2.18ms ± 1% -0.51% (p=0.006 n=8+9) Match/Hard/1M-12 70.1ms ± 0% 69.7ms ± 1% -0.52% (p=0.006 n=8+9) Match/Hard/32M-12 2.24s ± 0% 2.23s ± 1% -0.42% (p=0.046 n=8+9) Match/Hard1/32-12 8.17µs ± 1% 7.89µs ± 0% -3.42% (p=0.000 n=8+9) Match/Hard1/1K-12 254µs ± 2% 244µs ± 0% -3.91% (p=0.000 n=9+9) Match/Hard1/32K-12 9.58ms ± 1% 10.35ms ± 0% +8.00% (p=0.000 n=10+10) Match/Hard1/1M-12 306ms ± 1% 331ms ± 0% +8.27% (p=0.000 n=9+8) Match/Hard1/32M-12 9.79s ± 1% 10.60s ± 0% +8.29% (p=0.000 n=9+8) Match_onepass_regex/32-12 808ns ± 0% 812ns ± 0% +0.47% (p=0.000 n=8+10) Match_onepass_regex/1K-12 27.8µs ± 0% 28.5µs ± 0% +2.32% (p=0.000 n=8+10) Match_onepass_regex/32K-12 925µs ± 0% 936µs ± 0% +1.24% (p=0.000 n=9+10) Match_onepass_regex/1M-12 29.5ms ± 0% 30.2ms ± 0% +2.38% (p=0.000 n=10+10) Match_onepass_regex/32M-12 945ms ± 0% 970ms ± 0% +2.60% (p=0.000 n=9+10) CompileOnepass-12 4.67µs ± 0% 4.63µs ± 1% -0.84% (p=0.000 n=10+10) [Geo mean] 24.5µs 23.3µs -5.04% https://perf.golang.org/search?q=upload:20181004.1 Change-Id: Idbc2b76223718265657819ff38be2d9aba1c54b4 Reviewed-on: https://go-review.googlesource.com/c/139779 Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-09-28 16:37:16 -04:00
inst := re.prog.Inst[pc]
regexp: port RE2's bitstate backtracker to the regexp package This is a port of RE2's bitstate backtracker, which triggers under the same conditions that the RE2 backtracker triggers. However I wasn't sure how to port over some of the optimizations in the RE2 backtracker, and there is a ~2% penalty on benchmarks that don't trigger the backtracker. benchmark old ns/op new ns/op delta BenchmarkLiteral 312 189 -39.42% BenchmarkNotLiteral 4435 3001 -32.33% BenchmarkMatchClass 5758 4378 -23.97% BenchmarkMatchClass_InRange 5385 4084 -24.16% BenchmarkReplaceAll 5291 3505 -33.76% BenchmarkAnchoredLiteralShortNonMatch 190 200 +5.26% BenchmarkAnchoredLiteralLongNonMatch 189 194 +2.65% BenchmarkAnchoredShortMatch 479 304 -36.53% BenchmarkAnchoredLongMatch 478 499 +4.39% BenchmarkOnePassShortA 791 798 +0.88% BenchmarkNotOnePassShortA 3202 1571 -50.94% BenchmarkOnePassShortB 614 633 +3.09% BenchmarkNotOnePassShortB 2685 881 -67.19% BenchmarkOnePassLongPrefix 152 154 +1.32% BenchmarkOnePassLongNotPrefix 505 533 +5.54% BenchmarkMatchEasy0_32 139 171 +23.02% BenchmarkMatchEasy0_1K 653 1797 +175.19% BenchmarkMatchEasy0_32K 12032 13346 +10.92% BenchmarkMatchEasy0_1M 462882 461272 -0.35% BenchmarkMatchEasy0_32M 15015339 15365238 +2.33% BenchmarkMatchEasy1_32 122 168 +37.70% BenchmarkMatchEasy1_1K 3339 2612 -21.77% BenchmarkMatchEasy1_32K 72330 71721 -0.84% BenchmarkMatchEasy1_1M 2545410 2652284 +4.20% BenchmarkMatchEasy1_32M 80072063 82609750 +3.17% BenchmarkMatchMedium_32 2359 1980 -16.07% BenchmarkMatchMedium_1K 75939 58593 -22.84% BenchmarkMatchMedium_32K 2450907 2501106 +2.05% BenchmarkMatchMedium_1M 78707697 80174418 +1.86% BenchmarkMatchMedium_32M 2535146010 2570896441 +1.41% BenchmarkMatchHard_32 4297 2960 -31.11% BenchmarkMatchHard_1K 133592 88997 -33.38% BenchmarkMatchHard_32K 4240445 4336907 +2.27% BenchmarkMatchHard_1M 136187006 139350238 +2.32% BenchmarkMatchHard_32M 4350855890 4478537306 +2.93% benchmark old MB/s new MB/s speedup BenchmarkMatchEasy0_32 228.74 186.11 0.81x BenchmarkMatchEasy0_1K 1565.91 569.64 0.36x BenchmarkMatchEasy0_32K 2723.31 2455.10 0.90x BenchmarkMatchEasy0_1M 2265.32 2273.22 1.00x BenchmarkMatchEasy0_32M 2234.68 2183.79 0.98x BenchmarkMatchEasy1_32 261.08 190.22 0.73x BenchmarkMatchEasy1_1K 306.59 391.91 1.28x BenchmarkMatchEasy1_32K 453.03 456.88 1.01x BenchmarkMatchEasy1_1M 411.95 395.35 0.96x BenchmarkMatchEasy1_32M 419.05 406.18 0.97x BenchmarkMatchMedium_32 13.56 16.16 1.19x BenchmarkMatchMedium_1K 13.48 17.48 1.30x BenchmarkMatchMedium_32K 13.37 13.10 0.98x BenchmarkMatchMedium_1M 13.32 13.08 0.98x BenchmarkMatchMedium_32M 13.24 13.05 0.99x BenchmarkMatchHard_32 7.45 10.81 1.45x BenchmarkMatchHard_1K 7.67 11.51 1.50x BenchmarkMatchHard_32K 7.73 7.56 0.98x BenchmarkMatchHard_1M 7.70 7.52 0.98x BenchmarkMatchHard_32M 7.71 7.49 0.97x Fixes #4154 Change-Id: Iff7fb9507f0872b320d08afc08679751ed1b28bc Reviewed-on: https://go-review.googlesource.com/2153 Reviewed-by: Russ Cox <rsc@golang.org>
2014-12-28 00:17:01 -08:00
switch inst.Op {
default:
panic("bad inst")
case syntax.InstFail:
panic("unexpected InstFail")
case syntax.InstAlt:
// Cannot just
regexp: make (*bitState).push inlinable By refactoring job.arg from int with 0/1 as the only valid values into bool and simplifying (*bitState).push, we reduce the number of nodes below the inlining threshold. This improves backtracking regexp performance by 5-10% and go1 geomean by 1.7% Full performance data below: name old time/op new time/op delta Find-6 510ns ± 0% 480ns ± 1% -5.90% (p=0.000 n=10+10) FindString-6 504ns ± 1% 479ns ± 1% -5.10% (p=0.000 n=10+10) FindSubmatch-6 689ns ± 1% 659ns ± 1% -4.27% (p=0.000 n=9+10) FindStringSubmatch-6 659ns ± 0% 628ns ± 1% -4.69% (p=0.000 n=8+10) Literal-6 174ns ± 1% 171ns ± 1% -1.50% (p=0.000 n=10+10) NotLiteral-6 2.89µs ± 1% 2.72µs ± 0% -5.84% (p=0.000 n=10+9) MatchClass-6 4.65µs ± 1% 4.28µs ± 1% -7.96% (p=0.000 n=10+10) MatchClass_InRange-6 4.15µs ± 1% 3.80µs ± 0% -8.61% (p=0.000 n=10+8) ReplaceAll-6 2.72µs ± 1% 2.60µs ± 1% -4.68% (p=0.000 n=10+10) AnchoredLiteralShortNonMatch-6 158ns ± 1% 153ns ± 1% -3.03% (p=0.000 n=10+10) AnchoredLiteralLongNonMatch-6 176ns ± 1% 176ns ± 0% ~ (p=1.000 n=10+9) AnchoredShortMatch-6 260ns ± 0% 255ns ± 1% -1.84% (p=0.000 n=9+10) AnchoredLongMatch-6 456ns ± 0% 455ns ± 0% -0.19% (p=0.008 n=8+10) OnePassShortA-6 1.13µs ± 1% 1.12µs ± 0% -0.57% (p=0.046 n=10+8) NotOnePassShortA-6 1.14µs ± 1% 1.14µs ± 1% ~ (p=0.162 n=10+10) OnePassShortB-6 908ns ± 0% 893ns ± 0% -1.60% (p=0.000 n=8+9) NotOnePassShortB-6 857ns ± 0% 803ns ± 1% -6.34% (p=0.000 n=8+10) OnePassLongPrefix-6 190ns ± 0% 190ns ± 1% ~ (p=0.059 n=8+10) OnePassLongNotPrefix-6 722ns ± 1% 722ns ± 1% ~ (p=0.451 n=10+10) MatchParallelShared-6 810ns ± 2% 807ns ± 2% ~ (p=0.643 n=10+10) MatchParallelCopied-6 72.1ns ± 1% 69.4ns ± 1% -3.81% (p=0.000 n=10+10) QuoteMetaAll-6 213ns ± 2% 216ns ± 3% ~ (p=0.284 n=10+10) QuoteMetaNone-6 89.7ns ± 1% 89.8ns ± 1% ~ (p=0.616 n=10+10) Match/Easy0/32-6 127ns ± 1% 127ns ± 1% ~ (p=0.977 n=10+10) Match/Easy0/1K-6 566ns ± 0% 566ns ± 0% ~ (p=1.000 n=8+8) Match/Easy0/32K-6 9.30µs ± 1% 9.28µs ± 1% ~ (p=0.529 n=10+10) Match/Easy0/1M-6 460µs ± 1% 460µs ± 1% ~ (p=0.853 n=10+10) Match/Easy0/32M-6 15.0ms ± 0% 15.1ms ± 0% +0.77% (p=0.000 n=9+8) Match/Easy0i/32-6 2.10µs ± 1% 1.98µs ± 0% -6.02% (p=0.000 n=10+8) Match/Easy0i/1K-6 61.5µs ± 0% 57.2µs ± 0% -6.97% (p=0.000 n=10+9) Match/Easy0i/32K-6 2.75ms ± 0% 2.72ms ± 0% -1.10% (p=0.000 n=9+9) Match/Easy0i/1M-6 88.0ms ± 0% 86.9ms ± 1% -1.29% (p=0.000 n=8+10) Match/Easy0i/32M-6 2.82s ± 0% 2.77s ± 1% -1.81% (p=0.000 n=8+10) Match/Easy1/32-6 123ns ± 1% 124ns ± 1% +0.90% (p=0.001 n=10+10) Match/Easy1/1K-6 1.70µs ± 1% 1.65µs ± 0% -3.18% (p=0.000 n=9+10) Match/Easy1/32K-6 69.1µs ± 0% 68.4µs ± 1% -0.95% (p=0.000 n=8+10) Match/Easy1/1M-6 2.46ms ± 1% 2.42ms ± 1% -1.66% (p=0.000 n=10+10) Match/Easy1/32M-6 78.4ms ± 1% 77.5ms ± 0% -1.08% (p=0.000 n=10+9) Match/Medium/32-6 2.07µs ± 1% 1.91µs ± 1% -7.69% (p=0.000 n=10+10) Match/Medium/1K-6 62.8µs ± 0% 58.0µs ± 1% -7.70% (p=0.000 n=8+10) Match/Medium/32K-6 2.63ms ± 1% 2.58ms ± 1% -2.14% (p=0.000 n=10+10) Match/Medium/1M-6 84.6ms ± 0% 82.5ms ± 0% -2.37% (p=0.000 n=8+9) Match/Medium/32M-6 2.71s ± 0% 2.64s ± 0% -2.46% (p=0.000 n=10+9) Match/Hard/32-6 3.26µs ± 1% 2.98µs ± 1% -8.49% (p=0.000 n=10+10) Match/Hard/1K-6 100µs ± 0% 90µs ± 1% -9.55% (p=0.000 n=9+10) Match/Hard/32K-6 3.82ms ± 0% 3.82ms ± 1% ~ (p=0.515 n=8+10) Match/Hard/1M-6 122ms ± 1% 123ms ± 0% +0.66% (p=0.000 n=10+8) Match/Hard/32M-6 3.89s ± 1% 3.91s ± 1% ~ (p=0.105 n=10+10) Match/Hard1/32-6 18.1µs ± 1% 16.1µs ± 1% -11.31% (p=0.000 n=10+10) Match/Hard1/1K-6 565µs ± 0% 493µs ± 1% -12.65% (p=0.000 n=8+10) Match/Hard1/32K-6 18.8ms ± 0% 18.8ms ± 1% ~ (p=0.905 n=9+10) Match/Hard1/1M-6 602ms ± 1% 602ms ± 1% ~ (p=0.278 n=9+10) Match/Hard1/32M-6 19.1s ± 1% 19.2s ± 1% +0.31% (p=0.035 n=9+10) Match_onepass_regex/32-6 6.32µs ± 1% 6.34µs ± 1% ~ (p=0.060 n=10+10) Match_onepass_regex/1K-6 204µs ± 1% 204µs ± 1% ~ (p=0.842 n=9+10) Match_onepass_regex/32K-6 6.53ms ± 0% 6.55ms ± 1% +0.36% (p=0.005 n=10+10) Match_onepass_regex/1M-6 209ms ± 0% 208ms ± 1% -0.65% (p=0.034 n=8+10) Match_onepass_regex/32M-6 6.72s ± 0% 6.68s ± 1% -0.74% (p=0.000 n=9+10) CompileOnepass/^(?:(?:(?:.(?:$))?))...-6 7.02µs ± 1% 7.02µs ± 1% ~ (p=0.671 n=10+10) CompileOnepass/^abcd$-6 5.65µs ± 1% 5.65µs ± 1% ~ (p=0.411 n=10+9) CompileOnepass/^(?:(?:a{0,})*?)$-6 7.06µs ± 1% 7.06µs ± 1% ~ (p=0.912 n=10+10) CompileOnepass/^(?:(?:a+)*)$-6 6.40µs ± 1% 6.41µs ± 1% ~ (p=0.699 n=10+10) CompileOnepass/^(?:(?:a|(?:aa)))$-6 8.18µs ± 2% 8.16µs ± 1% ~ (p=0.529 n=10+10) CompileOnepass/^(?:[^\s\S])$-6 5.08µs ± 1% 5.17µs ± 1% +1.77% (p=0.000 n=9+10) CompileOnepass/^(?:(?:(?:a*)+))$-6 6.86µs ± 1% 6.85µs ± 0% ~ (p=0.190 n=10+9) CompileOnepass/^[a-c]+$-6 5.14µs ± 1% 5.11µs ± 0% -0.53% (p=0.041 n=10+10) CompileOnepass/^[a-c]*$-6 5.62µs ± 1% 5.63µs ± 1% ~ (p=0.382 n=10+10) CompileOnepass/^(?:a*)$-6 5.76µs ± 1% 5.73µs ± 1% -0.41% (p=0.008 n=9+10) CompileOnepass/^(?:(?:aa)|a)$-6 7.89µs ± 1% 7.84µs ± 1% -0.66% (p=0.020 n=10+10) CompileOnepass/^...$-6 5.38µs ± 1% 5.38µs ± 1% ~ (p=0.857 n=9+10) CompileOnepass/^(?:a|(?:aa))$-6 7.80µs ± 2% 7.82µs ± 1% ~ (p=0.342 n=10+10) CompileOnepass/^a((b))c$-6 7.75µs ± 1% 7.78µs ± 1% ~ (p=0.172 n=10+10) CompileOnepass/^a.[l-nA-Cg-j]?e$-6 8.39µs ± 1% 8.42µs ± 1% ~ (p=0.138 n=10+10) CompileOnepass/^a((b))$-6 6.92µs ± 1% 6.95µs ± 1% ~ (p=0.159 n=10+10) CompileOnepass/^a(?:(b)|(c))c$-6 10.0µs ± 1% 10.0µs ± 1% ~ (p=0.896 n=10+10) CompileOnepass/^a(?:b|c)$-6 5.62µs ± 1% 5.66µs ± 1% +0.71% (p=0.023 n=10+10) CompileOnepass/^a(?:b?|c)$-6 8.49µs ± 1% 8.43µs ± 1% -0.69% (p=0.010 n=10+10) CompileOnepass/^a(?:b?|c+)$-6 9.26µs ± 1% 9.28µs ± 1% ~ (p=0.448 n=10+10) CompileOnepass/^a(?:bc)+$-6 6.52µs ± 1% 6.46µs ± 2% -1.02% (p=0.003 n=10+10) CompileOnepass/^a(?:[bcd])+$-6 6.29µs ± 1% 6.32µs ± 1% ~ (p=0.256 n=10+10) CompileOnepass/^a((?:[bcd])+)$-6 7.77µs ± 1% 7.79µs ± 1% ~ (p=0.105 n=10+10) CompileOnepass/^a(:?b|c)*d$-6 14.0µs ± 1% 13.9µs ± 1% -0.69% (p=0.003 n=10+10) CompileOnepass/^.bc(d|e)*$-6 8.96µs ± 1% 9.06µs ± 1% +1.20% (p=0.000 n=10+9) CompileOnepass/^loooooooooooooooooo...-6 219µs ± 1% 220µs ± 1% +0.63% (p=0.006 n=9+10) [Geo mean] 31.6µs 31.1µs -1.82% name old speed new speed delta QuoteMetaAll-6 65.5MB/s ± 2% 64.8MB/s ± 3% ~ (p=0.315 n=10+10) QuoteMetaNone-6 290MB/s ± 1% 290MB/s ± 1% ~ (p=0.755 n=10+10) Match/Easy0/32-6 250MB/s ± 0% 251MB/s ± 1% ~ (p=0.277 n=8+9) Match/Easy0/1K-6 1.81GB/s ± 0% 1.81GB/s ± 0% ~ (p=0.408 n=8+10) Match/Easy0/32K-6 3.52GB/s ± 1% 3.53GB/s ± 1% ~ (p=0.529 n=10+10) Match/Easy0/1M-6 2.28GB/s ± 1% 2.28GB/s ± 1% ~ (p=0.853 n=10+10) Match/Easy0/32M-6 2.24GB/s ± 0% 2.23GB/s ± 0% -0.76% (p=0.000 n=9+8) Match/Easy0i/32-6 15.2MB/s ± 1% 16.2MB/s ± 0% +6.43% (p=0.000 n=10+9) Match/Easy0i/1K-6 16.6MB/s ± 0% 17.9MB/s ± 0% +7.48% (p=0.000 n=10+9) Match/Easy0i/32K-6 11.9MB/s ± 0% 12.0MB/s ± 0% +1.11% (p=0.000 n=9+9) Match/Easy0i/1M-6 11.9MB/s ± 0% 12.1MB/s ± 1% +1.31% (p=0.000 n=8+10) Match/Easy0i/32M-6 11.9MB/s ± 0% 12.1MB/s ± 1% +1.84% (p=0.000 n=8+10) Match/Easy1/32-6 260MB/s ± 1% 258MB/s ± 1% -0.91% (p=0.001 n=10+10) Match/Easy1/1K-6 601MB/s ± 1% 621MB/s ± 0% +3.28% (p=0.000 n=9+10) Match/Easy1/32K-6 474MB/s ± 0% 479MB/s ± 1% +0.96% (p=0.000 n=8+10) Match/Easy1/1M-6 426MB/s ± 1% 433MB/s ± 1% +1.68% (p=0.000 n=10+10) Match/Easy1/32M-6 428MB/s ± 1% 433MB/s ± 0% +1.09% (p=0.000 n=10+9) Match/Medium/32-6 15.4MB/s ± 1% 16.7MB/s ± 1% +8.23% (p=0.000 n=10+9) Match/Medium/1K-6 16.3MB/s ± 1% 17.7MB/s ± 1% +8.43% (p=0.000 n=9+10) Match/Medium/32K-6 12.5MB/s ± 1% 12.7MB/s ± 1% +2.15% (p=0.000 n=10+10) Match/Medium/1M-6 12.4MB/s ± 0% 12.7MB/s ± 0% +2.44% (p=0.000 n=8+9) Match/Medium/32M-6 12.4MB/s ± 0% 12.7MB/s ± 0% +2.52% (p=0.000 n=10+9) Match/Hard/32-6 9.82MB/s ± 1% 10.73MB/s ± 1% +9.29% (p=0.000 n=10+10) Match/Hard/1K-6 10.2MB/s ± 0% 11.3MB/s ± 1% +10.56% (p=0.000 n=9+10) Match/Hard/32K-6 8.58MB/s ± 0% 8.58MB/s ± 1% ~ (p=0.554 n=8+10) Match/Hard/1M-6 8.59MB/s ± 1% 8.53MB/s ± 0% -0.70% (p=0.000 n=10+8) Match/Hard/32M-6 8.62MB/s ± 1% 8.59MB/s ± 1% ~ (p=0.098 n=10+10) Match/Hard1/32-6 1.77MB/s ± 1% 1.99MB/s ± 1% +12.40% (p=0.000 n=10+8) Match/Hard1/1K-6 1.81MB/s ± 1% 2.08MB/s ± 1% +14.55% (p=0.000 n=10+10) Match/Hard1/32K-6 1.74MB/s ± 0% 1.74MB/s ± 0% ~ (p=0.108 n=9+10) Match/Hard1/1M-6 1.74MB/s ± 0% 1.74MB/s ± 1% ~ (p=1.000 n=9+10) Match/Hard1/32M-6 1.75MB/s ± 0% 1.75MB/s ± 1% ~ (p=0.157 n=9+10) Match_onepass_regex/32-6 5.05MB/s ± 0% 5.05MB/s ± 1% ~ (p=0.262 n=8+10) Match_onepass_regex/1K-6 5.02MB/s ± 1% 5.02MB/s ± 1% ~ (p=0.677 n=9+10) Match_onepass_regex/32K-6 5.02MB/s ± 0% 4.99MB/s ± 0% -0.47% (p=0.000 n=10+9) Match_onepass_regex/1M-6 5.01MB/s ± 0% 5.04MB/s ± 1% +0.68% (p=0.017 n=8+10) Match_onepass_regex/32M-6 4.99MB/s ± 0% 5.03MB/s ± 1% +0.74% (p=0.000 n=10+10) [Geo mean] 29.1MB/s 29.8MB/s +2.44% go1 data for reference name old time/op new time/op delta BinaryTree17-6 4.39s ± 1% 4.37s ± 0% -0.58% (p=0.006 n=9+9) Fannkuch11-6 5.13s ± 0% 5.18s ± 0% +0.87% (p=0.000 n=8+8) FmtFprintfEmpty-6 74.2ns ± 0% 71.7ns ± 3% -3.41% (p=0.000 n=10+10) FmtFprintfString-6 120ns ± 1% 122ns ± 2% ~ (p=0.333 n=10+10) FmtFprintfInt-6 127ns ± 1% 127ns ± 1% ~ (p=0.809 n=10+10) FmtFprintfIntInt-6 186ns ± 0% 188ns ± 1% +1.02% (p=0.002 n=8+10) FmtFprintfPrefixedInt-6 223ns ± 1% 222ns ± 2% ~ (p=0.421 n=10+10) FmtFprintfFloat-6 374ns ± 0% 376ns ± 1% +0.43% (p=0.030 n=8+10) FmtManyArgs-6 795ns ± 0% 788ns ± 1% -0.79% (p=0.000 n=8+9) GobDecode-6 10.9ms ± 1% 10.9ms ± 0% ~ (p=0.079 n=10+9) GobEncode-6 8.60ms ± 1% 8.56ms ± 0% -0.52% (p=0.004 n=10+10) Gzip-6 378ms ± 1% 386ms ± 1% +2.28% (p=0.000 n=10+10) Gunzip-6 63.7ms ± 0% 62.3ms ± 0% -2.22% (p=0.000 n=9+8) HTTPClientServer-6 120µs ± 3% 114µs ± 3% -4.99% (p=0.000 n=10+10) JSONEncode-6 20.3ms ± 1% 19.9ms ± 0% -1.90% (p=0.000 n=9+10) JSONDecode-6 84.3ms ± 0% 83.7ms ± 0% -0.76% (p=0.000 n=8+8) Mandelbrot200-6 6.91ms ± 0% 6.89ms ± 0% -0.31% (p=0.000 n=9+8) GoParse-6 5.49ms ± 0% 5.47ms ± 1% ~ (p=0.101 n=8+10) RegexpMatchEasy0_32-6 130ns ± 0% 128ns ± 0% -1.54% (p=0.002 n=8+10) RegexpMatchEasy0_1K-6 322ns ± 1% 322ns ± 0% ~ (p=0.525 n=10+9) RegexpMatchEasy1_32-6 124ns ± 0% 124ns ± 0% -0.32% (p=0.046 n=8+10) RegexpMatchEasy1_1K-6 570ns ± 0% 548ns ± 1% -3.76% (p=0.000 n=10+10) RegexpMatchMedium_32-6 196ns ± 0% 183ns ± 1% -6.61% (p=0.000 n=8+10) RegexpMatchMedium_1K-6 64.3µs ± 0% 59.0µs ± 1% -8.31% (p=0.000 n=8+10) RegexpMatchHard_32-6 3.08µs ± 0% 2.80µs ± 0% -8.96% (p=0.000 n=8+9) RegexpMatchHard_1K-6 93.0µs ± 0% 84.5µs ± 1% -9.17% (p=0.000 n=8+9) Revcomp-6 647ms ± 2% 646ms ± 1% ~ (p=0.720 n=10+9) Template-6 92.3ms ± 0% 91.7ms ± 0% -0.65% (p=0.000 n=8+8) TimeParse-6 490ns ± 0% 488ns ± 0% -0.43% (p=0.000 n=10+10) TimeFormat-6 513ns ± 0% 513ns ± 1% ~ (p=0.144 n=9+10) [Geo mean] 79.1µs 77.7µs -1.73% name old speed new speed delta GobDecode-6 70.1MB/s ± 1% 70.3MB/s ± 0% ~ (p=0.078 n=10+9) GobEncode-6 89.2MB/s ± 1% 89.7MB/s ± 0% +0.52% (p=0.004 n=10+10) Gzip-6 51.4MB/s ± 1% 50.2MB/s ± 1% -2.23% (p=0.000 n=10+10) Gunzip-6 304MB/s ± 0% 311MB/s ± 0% +2.27% (p=0.000 n=9+8) JSONEncode-6 95.8MB/s ± 1% 97.7MB/s ± 0% +1.93% (p=0.000 n=9+10) JSONDecode-6 23.0MB/s ± 0% 23.2MB/s ± 0% +0.76% (p=0.000 n=8+8) GoParse-6 10.6MB/s ± 0% 10.6MB/s ± 1% ~ (p=0.111 n=8+10) RegexpMatchEasy0_32-6 244MB/s ± 0% 249MB/s ± 0% +2.06% (p=0.000 n=9+10) RegexpMatchEasy0_1K-6 3.18GB/s ± 1% 3.17GB/s ± 0% ~ (p=0.211 n=10+9) RegexpMatchEasy1_32-6 257MB/s ± 0% 258MB/s ± 0% +0.37% (p=0.000 n=8+8) RegexpMatchEasy1_1K-6 1.80GB/s ± 0% 1.87GB/s ± 1% +3.91% (p=0.000 n=10+10) RegexpMatchMedium_32-6 5.08MB/s ± 0% 5.43MB/s ± 1% +7.03% (p=0.000 n=8+10) RegexpMatchMedium_1K-6 15.9MB/s ± 0% 17.4MB/s ± 1% +9.08% (p=0.000 n=8+10) RegexpMatchHard_32-6 10.4MB/s ± 0% 11.4MB/s ± 0% +9.82% (p=0.000 n=8+9) RegexpMatchHard_1K-6 11.0MB/s ± 0% 12.1MB/s ± 1% +10.10% (p=0.000 n=8+9) Revcomp-6 393MB/s ± 2% 394MB/s ± 1% ~ (p=0.720 n=10+9) Template-6 21.0MB/s ± 0% 21.2MB/s ± 0% +0.66% (p=0.000 n=8+8) [Geo mean] 74.2MB/s 76.2MB/s +2.70% Updates #21851 Change-Id: Ie88455db925f422a828f8528293790726a9c036b Reviewed-on: https://go-review.googlesource.com/65491 Run-TryBot: Ilya Tocar <ilya.tocar@intel.com> Reviewed-by: Daniel Martí <mvdan@mvdan.cc> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2017-09-22 15:15:23 -05:00
// b.push(inst.Out, pos, false)
// b.push(inst.Arg, pos, false)
regexp: port RE2's bitstate backtracker to the regexp package This is a port of RE2's bitstate backtracker, which triggers under the same conditions that the RE2 backtracker triggers. However I wasn't sure how to port over some of the optimizations in the RE2 backtracker, and there is a ~2% penalty on benchmarks that don't trigger the backtracker. benchmark old ns/op new ns/op delta BenchmarkLiteral 312 189 -39.42% BenchmarkNotLiteral 4435 3001 -32.33% BenchmarkMatchClass 5758 4378 -23.97% BenchmarkMatchClass_InRange 5385 4084 -24.16% BenchmarkReplaceAll 5291 3505 -33.76% BenchmarkAnchoredLiteralShortNonMatch 190 200 +5.26% BenchmarkAnchoredLiteralLongNonMatch 189 194 +2.65% BenchmarkAnchoredShortMatch 479 304 -36.53% BenchmarkAnchoredLongMatch 478 499 +4.39% BenchmarkOnePassShortA 791 798 +0.88% BenchmarkNotOnePassShortA 3202 1571 -50.94% BenchmarkOnePassShortB 614 633 +3.09% BenchmarkNotOnePassShortB 2685 881 -67.19% BenchmarkOnePassLongPrefix 152 154 +1.32% BenchmarkOnePassLongNotPrefix 505 533 +5.54% BenchmarkMatchEasy0_32 139 171 +23.02% BenchmarkMatchEasy0_1K 653 1797 +175.19% BenchmarkMatchEasy0_32K 12032 13346 +10.92% BenchmarkMatchEasy0_1M 462882 461272 -0.35% BenchmarkMatchEasy0_32M 15015339 15365238 +2.33% BenchmarkMatchEasy1_32 122 168 +37.70% BenchmarkMatchEasy1_1K 3339 2612 -21.77% BenchmarkMatchEasy1_32K 72330 71721 -0.84% BenchmarkMatchEasy1_1M 2545410 2652284 +4.20% BenchmarkMatchEasy1_32M 80072063 82609750 +3.17% BenchmarkMatchMedium_32 2359 1980 -16.07% BenchmarkMatchMedium_1K 75939 58593 -22.84% BenchmarkMatchMedium_32K 2450907 2501106 +2.05% BenchmarkMatchMedium_1M 78707697 80174418 +1.86% BenchmarkMatchMedium_32M 2535146010 2570896441 +1.41% BenchmarkMatchHard_32 4297 2960 -31.11% BenchmarkMatchHard_1K 133592 88997 -33.38% BenchmarkMatchHard_32K 4240445 4336907 +2.27% BenchmarkMatchHard_1M 136187006 139350238 +2.32% BenchmarkMatchHard_32M 4350855890 4478537306 +2.93% benchmark old MB/s new MB/s speedup BenchmarkMatchEasy0_32 228.74 186.11 0.81x BenchmarkMatchEasy0_1K 1565.91 569.64 0.36x BenchmarkMatchEasy0_32K 2723.31 2455.10 0.90x BenchmarkMatchEasy0_1M 2265.32 2273.22 1.00x BenchmarkMatchEasy0_32M 2234.68 2183.79 0.98x BenchmarkMatchEasy1_32 261.08 190.22 0.73x BenchmarkMatchEasy1_1K 306.59 391.91 1.28x BenchmarkMatchEasy1_32K 453.03 456.88 1.01x BenchmarkMatchEasy1_1M 411.95 395.35 0.96x BenchmarkMatchEasy1_32M 419.05 406.18 0.97x BenchmarkMatchMedium_32 13.56 16.16 1.19x BenchmarkMatchMedium_1K 13.48 17.48 1.30x BenchmarkMatchMedium_32K 13.37 13.10 0.98x BenchmarkMatchMedium_1M 13.32 13.08 0.98x BenchmarkMatchMedium_32M 13.24 13.05 0.99x BenchmarkMatchHard_32 7.45 10.81 1.45x BenchmarkMatchHard_1K 7.67 11.51 1.50x BenchmarkMatchHard_32K 7.73 7.56 0.98x BenchmarkMatchHard_1M 7.70 7.52 0.98x BenchmarkMatchHard_32M 7.71 7.49 0.97x Fixes #4154 Change-Id: Iff7fb9507f0872b320d08afc08679751ed1b28bc Reviewed-on: https://go-review.googlesource.com/2153 Reviewed-by: Russ Cox <rsc@golang.org>
2014-12-28 00:17:01 -08:00
// If during the processing of inst.Out, we encounter
// inst.Arg via another path, we want to process it then.
// Pushing it here will inhibit that. Instead, re-push
regexp: make (*bitState).push inlinable By refactoring job.arg from int with 0/1 as the only valid values into bool and simplifying (*bitState).push, we reduce the number of nodes below the inlining threshold. This improves backtracking regexp performance by 5-10% and go1 geomean by 1.7% Full performance data below: name old time/op new time/op delta Find-6 510ns ± 0% 480ns ± 1% -5.90% (p=0.000 n=10+10) FindString-6 504ns ± 1% 479ns ± 1% -5.10% (p=0.000 n=10+10) FindSubmatch-6 689ns ± 1% 659ns ± 1% -4.27% (p=0.000 n=9+10) FindStringSubmatch-6 659ns ± 0% 628ns ± 1% -4.69% (p=0.000 n=8+10) Literal-6 174ns ± 1% 171ns ± 1% -1.50% (p=0.000 n=10+10) NotLiteral-6 2.89µs ± 1% 2.72µs ± 0% -5.84% (p=0.000 n=10+9) MatchClass-6 4.65µs ± 1% 4.28µs ± 1% -7.96% (p=0.000 n=10+10) MatchClass_InRange-6 4.15µs ± 1% 3.80µs ± 0% -8.61% (p=0.000 n=10+8) ReplaceAll-6 2.72µs ± 1% 2.60µs ± 1% -4.68% (p=0.000 n=10+10) AnchoredLiteralShortNonMatch-6 158ns ± 1% 153ns ± 1% -3.03% (p=0.000 n=10+10) AnchoredLiteralLongNonMatch-6 176ns ± 1% 176ns ± 0% ~ (p=1.000 n=10+9) AnchoredShortMatch-6 260ns ± 0% 255ns ± 1% -1.84% (p=0.000 n=9+10) AnchoredLongMatch-6 456ns ± 0% 455ns ± 0% -0.19% (p=0.008 n=8+10) OnePassShortA-6 1.13µs ± 1% 1.12µs ± 0% -0.57% (p=0.046 n=10+8) NotOnePassShortA-6 1.14µs ± 1% 1.14µs ± 1% ~ (p=0.162 n=10+10) OnePassShortB-6 908ns ± 0% 893ns ± 0% -1.60% (p=0.000 n=8+9) NotOnePassShortB-6 857ns ± 0% 803ns ± 1% -6.34% (p=0.000 n=8+10) OnePassLongPrefix-6 190ns ± 0% 190ns ± 1% ~ (p=0.059 n=8+10) OnePassLongNotPrefix-6 722ns ± 1% 722ns ± 1% ~ (p=0.451 n=10+10) MatchParallelShared-6 810ns ± 2% 807ns ± 2% ~ (p=0.643 n=10+10) MatchParallelCopied-6 72.1ns ± 1% 69.4ns ± 1% -3.81% (p=0.000 n=10+10) QuoteMetaAll-6 213ns ± 2% 216ns ± 3% ~ (p=0.284 n=10+10) QuoteMetaNone-6 89.7ns ± 1% 89.8ns ± 1% ~ (p=0.616 n=10+10) Match/Easy0/32-6 127ns ± 1% 127ns ± 1% ~ (p=0.977 n=10+10) Match/Easy0/1K-6 566ns ± 0% 566ns ± 0% ~ (p=1.000 n=8+8) Match/Easy0/32K-6 9.30µs ± 1% 9.28µs ± 1% ~ (p=0.529 n=10+10) Match/Easy0/1M-6 460µs ± 1% 460µs ± 1% ~ (p=0.853 n=10+10) Match/Easy0/32M-6 15.0ms ± 0% 15.1ms ± 0% +0.77% (p=0.000 n=9+8) Match/Easy0i/32-6 2.10µs ± 1% 1.98µs ± 0% -6.02% (p=0.000 n=10+8) Match/Easy0i/1K-6 61.5µs ± 0% 57.2µs ± 0% -6.97% (p=0.000 n=10+9) Match/Easy0i/32K-6 2.75ms ± 0% 2.72ms ± 0% -1.10% (p=0.000 n=9+9) Match/Easy0i/1M-6 88.0ms ± 0% 86.9ms ± 1% -1.29% (p=0.000 n=8+10) Match/Easy0i/32M-6 2.82s ± 0% 2.77s ± 1% -1.81% (p=0.000 n=8+10) Match/Easy1/32-6 123ns ± 1% 124ns ± 1% +0.90% (p=0.001 n=10+10) Match/Easy1/1K-6 1.70µs ± 1% 1.65µs ± 0% -3.18% (p=0.000 n=9+10) Match/Easy1/32K-6 69.1µs ± 0% 68.4µs ± 1% -0.95% (p=0.000 n=8+10) Match/Easy1/1M-6 2.46ms ± 1% 2.42ms ± 1% -1.66% (p=0.000 n=10+10) Match/Easy1/32M-6 78.4ms ± 1% 77.5ms ± 0% -1.08% (p=0.000 n=10+9) Match/Medium/32-6 2.07µs ± 1% 1.91µs ± 1% -7.69% (p=0.000 n=10+10) Match/Medium/1K-6 62.8µs ± 0% 58.0µs ± 1% -7.70% (p=0.000 n=8+10) Match/Medium/32K-6 2.63ms ± 1% 2.58ms ± 1% -2.14% (p=0.000 n=10+10) Match/Medium/1M-6 84.6ms ± 0% 82.5ms ± 0% -2.37% (p=0.000 n=8+9) Match/Medium/32M-6 2.71s ± 0% 2.64s ± 0% -2.46% (p=0.000 n=10+9) Match/Hard/32-6 3.26µs ± 1% 2.98µs ± 1% -8.49% (p=0.000 n=10+10) Match/Hard/1K-6 100µs ± 0% 90µs ± 1% -9.55% (p=0.000 n=9+10) Match/Hard/32K-6 3.82ms ± 0% 3.82ms ± 1% ~ (p=0.515 n=8+10) Match/Hard/1M-6 122ms ± 1% 123ms ± 0% +0.66% (p=0.000 n=10+8) Match/Hard/32M-6 3.89s ± 1% 3.91s ± 1% ~ (p=0.105 n=10+10) Match/Hard1/32-6 18.1µs ± 1% 16.1µs ± 1% -11.31% (p=0.000 n=10+10) Match/Hard1/1K-6 565µs ± 0% 493µs ± 1% -12.65% (p=0.000 n=8+10) Match/Hard1/32K-6 18.8ms ± 0% 18.8ms ± 1% ~ (p=0.905 n=9+10) Match/Hard1/1M-6 602ms ± 1% 602ms ± 1% ~ (p=0.278 n=9+10) Match/Hard1/32M-6 19.1s ± 1% 19.2s ± 1% +0.31% (p=0.035 n=9+10) Match_onepass_regex/32-6 6.32µs ± 1% 6.34µs ± 1% ~ (p=0.060 n=10+10) Match_onepass_regex/1K-6 204µs ± 1% 204µs ± 1% ~ (p=0.842 n=9+10) Match_onepass_regex/32K-6 6.53ms ± 0% 6.55ms ± 1% +0.36% (p=0.005 n=10+10) Match_onepass_regex/1M-6 209ms ± 0% 208ms ± 1% -0.65% (p=0.034 n=8+10) Match_onepass_regex/32M-6 6.72s ± 0% 6.68s ± 1% -0.74% (p=0.000 n=9+10) CompileOnepass/^(?:(?:(?:.(?:$))?))...-6 7.02µs ± 1% 7.02µs ± 1% ~ (p=0.671 n=10+10) CompileOnepass/^abcd$-6 5.65µs ± 1% 5.65µs ± 1% ~ (p=0.411 n=10+9) CompileOnepass/^(?:(?:a{0,})*?)$-6 7.06µs ± 1% 7.06µs ± 1% ~ (p=0.912 n=10+10) CompileOnepass/^(?:(?:a+)*)$-6 6.40µs ± 1% 6.41µs ± 1% ~ (p=0.699 n=10+10) CompileOnepass/^(?:(?:a|(?:aa)))$-6 8.18µs ± 2% 8.16µs ± 1% ~ (p=0.529 n=10+10) CompileOnepass/^(?:[^\s\S])$-6 5.08µs ± 1% 5.17µs ± 1% +1.77% (p=0.000 n=9+10) CompileOnepass/^(?:(?:(?:a*)+))$-6 6.86µs ± 1% 6.85µs ± 0% ~ (p=0.190 n=10+9) CompileOnepass/^[a-c]+$-6 5.14µs ± 1% 5.11µs ± 0% -0.53% (p=0.041 n=10+10) CompileOnepass/^[a-c]*$-6 5.62µs ± 1% 5.63µs ± 1% ~ (p=0.382 n=10+10) CompileOnepass/^(?:a*)$-6 5.76µs ± 1% 5.73µs ± 1% -0.41% (p=0.008 n=9+10) CompileOnepass/^(?:(?:aa)|a)$-6 7.89µs ± 1% 7.84µs ± 1% -0.66% (p=0.020 n=10+10) CompileOnepass/^...$-6 5.38µs ± 1% 5.38µs ± 1% ~ (p=0.857 n=9+10) CompileOnepass/^(?:a|(?:aa))$-6 7.80µs ± 2% 7.82µs ± 1% ~ (p=0.342 n=10+10) CompileOnepass/^a((b))c$-6 7.75µs ± 1% 7.78µs ± 1% ~ (p=0.172 n=10+10) CompileOnepass/^a.[l-nA-Cg-j]?e$-6 8.39µs ± 1% 8.42µs ± 1% ~ (p=0.138 n=10+10) CompileOnepass/^a((b))$-6 6.92µs ± 1% 6.95µs ± 1% ~ (p=0.159 n=10+10) CompileOnepass/^a(?:(b)|(c))c$-6 10.0µs ± 1% 10.0µs ± 1% ~ (p=0.896 n=10+10) CompileOnepass/^a(?:b|c)$-6 5.62µs ± 1% 5.66µs ± 1% +0.71% (p=0.023 n=10+10) CompileOnepass/^a(?:b?|c)$-6 8.49µs ± 1% 8.43µs ± 1% -0.69% (p=0.010 n=10+10) CompileOnepass/^a(?:b?|c+)$-6 9.26µs ± 1% 9.28µs ± 1% ~ (p=0.448 n=10+10) CompileOnepass/^a(?:bc)+$-6 6.52µs ± 1% 6.46µs ± 2% -1.02% (p=0.003 n=10+10) CompileOnepass/^a(?:[bcd])+$-6 6.29µs ± 1% 6.32µs ± 1% ~ (p=0.256 n=10+10) CompileOnepass/^a((?:[bcd])+)$-6 7.77µs ± 1% 7.79µs ± 1% ~ (p=0.105 n=10+10) CompileOnepass/^a(:?b|c)*d$-6 14.0µs ± 1% 13.9µs ± 1% -0.69% (p=0.003 n=10+10) CompileOnepass/^.bc(d|e)*$-6 8.96µs ± 1% 9.06µs ± 1% +1.20% (p=0.000 n=10+9) CompileOnepass/^loooooooooooooooooo...-6 219µs ± 1% 220µs ± 1% +0.63% (p=0.006 n=9+10) [Geo mean] 31.6µs 31.1µs -1.82% name old speed new speed delta QuoteMetaAll-6 65.5MB/s ± 2% 64.8MB/s ± 3% ~ (p=0.315 n=10+10) QuoteMetaNone-6 290MB/s ± 1% 290MB/s ± 1% ~ (p=0.755 n=10+10) Match/Easy0/32-6 250MB/s ± 0% 251MB/s ± 1% ~ (p=0.277 n=8+9) Match/Easy0/1K-6 1.81GB/s ± 0% 1.81GB/s ± 0% ~ (p=0.408 n=8+10) Match/Easy0/32K-6 3.52GB/s ± 1% 3.53GB/s ± 1% ~ (p=0.529 n=10+10) Match/Easy0/1M-6 2.28GB/s ± 1% 2.28GB/s ± 1% ~ (p=0.853 n=10+10) Match/Easy0/32M-6 2.24GB/s ± 0% 2.23GB/s ± 0% -0.76% (p=0.000 n=9+8) Match/Easy0i/32-6 15.2MB/s ± 1% 16.2MB/s ± 0% +6.43% (p=0.000 n=10+9) Match/Easy0i/1K-6 16.6MB/s ± 0% 17.9MB/s ± 0% +7.48% (p=0.000 n=10+9) Match/Easy0i/32K-6 11.9MB/s ± 0% 12.0MB/s ± 0% +1.11% (p=0.000 n=9+9) Match/Easy0i/1M-6 11.9MB/s ± 0% 12.1MB/s ± 1% +1.31% (p=0.000 n=8+10) Match/Easy0i/32M-6 11.9MB/s ± 0% 12.1MB/s ± 1% +1.84% (p=0.000 n=8+10) Match/Easy1/32-6 260MB/s ± 1% 258MB/s ± 1% -0.91% (p=0.001 n=10+10) Match/Easy1/1K-6 601MB/s ± 1% 621MB/s ± 0% +3.28% (p=0.000 n=9+10) Match/Easy1/32K-6 474MB/s ± 0% 479MB/s ± 1% +0.96% (p=0.000 n=8+10) Match/Easy1/1M-6 426MB/s ± 1% 433MB/s ± 1% +1.68% (p=0.000 n=10+10) Match/Easy1/32M-6 428MB/s ± 1% 433MB/s ± 0% +1.09% (p=0.000 n=10+9) Match/Medium/32-6 15.4MB/s ± 1% 16.7MB/s ± 1% +8.23% (p=0.000 n=10+9) Match/Medium/1K-6 16.3MB/s ± 1% 17.7MB/s ± 1% +8.43% (p=0.000 n=9+10) Match/Medium/32K-6 12.5MB/s ± 1% 12.7MB/s ± 1% +2.15% (p=0.000 n=10+10) Match/Medium/1M-6 12.4MB/s ± 0% 12.7MB/s ± 0% +2.44% (p=0.000 n=8+9) Match/Medium/32M-6 12.4MB/s ± 0% 12.7MB/s ± 0% +2.52% (p=0.000 n=10+9) Match/Hard/32-6 9.82MB/s ± 1% 10.73MB/s ± 1% +9.29% (p=0.000 n=10+10) Match/Hard/1K-6 10.2MB/s ± 0% 11.3MB/s ± 1% +10.56% (p=0.000 n=9+10) Match/Hard/32K-6 8.58MB/s ± 0% 8.58MB/s ± 1% ~ (p=0.554 n=8+10) Match/Hard/1M-6 8.59MB/s ± 1% 8.53MB/s ± 0% -0.70% (p=0.000 n=10+8) Match/Hard/32M-6 8.62MB/s ± 1% 8.59MB/s ± 1% ~ (p=0.098 n=10+10) Match/Hard1/32-6 1.77MB/s ± 1% 1.99MB/s ± 1% +12.40% (p=0.000 n=10+8) Match/Hard1/1K-6 1.81MB/s ± 1% 2.08MB/s ± 1% +14.55% (p=0.000 n=10+10) Match/Hard1/32K-6 1.74MB/s ± 0% 1.74MB/s ± 0% ~ (p=0.108 n=9+10) Match/Hard1/1M-6 1.74MB/s ± 0% 1.74MB/s ± 1% ~ (p=1.000 n=9+10) Match/Hard1/32M-6 1.75MB/s ± 0% 1.75MB/s ± 1% ~ (p=0.157 n=9+10) Match_onepass_regex/32-6 5.05MB/s ± 0% 5.05MB/s ± 1% ~ (p=0.262 n=8+10) Match_onepass_regex/1K-6 5.02MB/s ± 1% 5.02MB/s ± 1% ~ (p=0.677 n=9+10) Match_onepass_regex/32K-6 5.02MB/s ± 0% 4.99MB/s ± 0% -0.47% (p=0.000 n=10+9) Match_onepass_regex/1M-6 5.01MB/s ± 0% 5.04MB/s ± 1% +0.68% (p=0.017 n=8+10) Match_onepass_regex/32M-6 4.99MB/s ± 0% 5.03MB/s ± 1% +0.74% (p=0.000 n=10+10) [Geo mean] 29.1MB/s 29.8MB/s +2.44% go1 data for reference name old time/op new time/op delta BinaryTree17-6 4.39s ± 1% 4.37s ± 0% -0.58% (p=0.006 n=9+9) Fannkuch11-6 5.13s ± 0% 5.18s ± 0% +0.87% (p=0.000 n=8+8) FmtFprintfEmpty-6 74.2ns ± 0% 71.7ns ± 3% -3.41% (p=0.000 n=10+10) FmtFprintfString-6 120ns ± 1% 122ns ± 2% ~ (p=0.333 n=10+10) FmtFprintfInt-6 127ns ± 1% 127ns ± 1% ~ (p=0.809 n=10+10) FmtFprintfIntInt-6 186ns ± 0% 188ns ± 1% +1.02% (p=0.002 n=8+10) FmtFprintfPrefixedInt-6 223ns ± 1% 222ns ± 2% ~ (p=0.421 n=10+10) FmtFprintfFloat-6 374ns ± 0% 376ns ± 1% +0.43% (p=0.030 n=8+10) FmtManyArgs-6 795ns ± 0% 788ns ± 1% -0.79% (p=0.000 n=8+9) GobDecode-6 10.9ms ± 1% 10.9ms ± 0% ~ (p=0.079 n=10+9) GobEncode-6 8.60ms ± 1% 8.56ms ± 0% -0.52% (p=0.004 n=10+10) Gzip-6 378ms ± 1% 386ms ± 1% +2.28% (p=0.000 n=10+10) Gunzip-6 63.7ms ± 0% 62.3ms ± 0% -2.22% (p=0.000 n=9+8) HTTPClientServer-6 120µs ± 3% 114µs ± 3% -4.99% (p=0.000 n=10+10) JSONEncode-6 20.3ms ± 1% 19.9ms ± 0% -1.90% (p=0.000 n=9+10) JSONDecode-6 84.3ms ± 0% 83.7ms ± 0% -0.76% (p=0.000 n=8+8) Mandelbrot200-6 6.91ms ± 0% 6.89ms ± 0% -0.31% (p=0.000 n=9+8) GoParse-6 5.49ms ± 0% 5.47ms ± 1% ~ (p=0.101 n=8+10) RegexpMatchEasy0_32-6 130ns ± 0% 128ns ± 0% -1.54% (p=0.002 n=8+10) RegexpMatchEasy0_1K-6 322ns ± 1% 322ns ± 0% ~ (p=0.525 n=10+9) RegexpMatchEasy1_32-6 124ns ± 0% 124ns ± 0% -0.32% (p=0.046 n=8+10) RegexpMatchEasy1_1K-6 570ns ± 0% 548ns ± 1% -3.76% (p=0.000 n=10+10) RegexpMatchMedium_32-6 196ns ± 0% 183ns ± 1% -6.61% (p=0.000 n=8+10) RegexpMatchMedium_1K-6 64.3µs ± 0% 59.0µs ± 1% -8.31% (p=0.000 n=8+10) RegexpMatchHard_32-6 3.08µs ± 0% 2.80µs ± 0% -8.96% (p=0.000 n=8+9) RegexpMatchHard_1K-6 93.0µs ± 0% 84.5µs ± 1% -9.17% (p=0.000 n=8+9) Revcomp-6 647ms ± 2% 646ms ± 1% ~ (p=0.720 n=10+9) Template-6 92.3ms ± 0% 91.7ms ± 0% -0.65% (p=0.000 n=8+8) TimeParse-6 490ns ± 0% 488ns ± 0% -0.43% (p=0.000 n=10+10) TimeFormat-6 513ns ± 0% 513ns ± 1% ~ (p=0.144 n=9+10) [Geo mean] 79.1µs 77.7µs -1.73% name old speed new speed delta GobDecode-6 70.1MB/s ± 1% 70.3MB/s ± 0% ~ (p=0.078 n=10+9) GobEncode-6 89.2MB/s ± 1% 89.7MB/s ± 0% +0.52% (p=0.004 n=10+10) Gzip-6 51.4MB/s ± 1% 50.2MB/s ± 1% -2.23% (p=0.000 n=10+10) Gunzip-6 304MB/s ± 0% 311MB/s ± 0% +2.27% (p=0.000 n=9+8) JSONEncode-6 95.8MB/s ± 1% 97.7MB/s ± 0% +1.93% (p=0.000 n=9+10) JSONDecode-6 23.0MB/s ± 0% 23.2MB/s ± 0% +0.76% (p=0.000 n=8+8) GoParse-6 10.6MB/s ± 0% 10.6MB/s ± 1% ~ (p=0.111 n=8+10) RegexpMatchEasy0_32-6 244MB/s ± 0% 249MB/s ± 0% +2.06% (p=0.000 n=9+10) RegexpMatchEasy0_1K-6 3.18GB/s ± 1% 3.17GB/s ± 0% ~ (p=0.211 n=10+9) RegexpMatchEasy1_32-6 257MB/s ± 0% 258MB/s ± 0% +0.37% (p=0.000 n=8+8) RegexpMatchEasy1_1K-6 1.80GB/s ± 0% 1.87GB/s ± 1% +3.91% (p=0.000 n=10+10) RegexpMatchMedium_32-6 5.08MB/s ± 0% 5.43MB/s ± 1% +7.03% (p=0.000 n=8+10) RegexpMatchMedium_1K-6 15.9MB/s ± 0% 17.4MB/s ± 1% +9.08% (p=0.000 n=8+10) RegexpMatchHard_32-6 10.4MB/s ± 0% 11.4MB/s ± 0% +9.82% (p=0.000 n=8+9) RegexpMatchHard_1K-6 11.0MB/s ± 0% 12.1MB/s ± 1% +10.10% (p=0.000 n=8+9) Revcomp-6 393MB/s ± 2% 394MB/s ± 1% ~ (p=0.720 n=10+9) Template-6 21.0MB/s ± 0% 21.2MB/s ± 0% +0.66% (p=0.000 n=8+8) [Geo mean] 74.2MB/s 76.2MB/s +2.70% Updates #21851 Change-Id: Ie88455db925f422a828f8528293790726a9c036b Reviewed-on: https://go-review.googlesource.com/65491 Run-TryBot: Ilya Tocar <ilya.tocar@intel.com> Reviewed-by: Daniel Martí <mvdan@mvdan.cc> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2017-09-22 15:15:23 -05:00
// inst with arg==true as a reminder to push inst.Arg out
regexp: port RE2's bitstate backtracker to the regexp package This is a port of RE2's bitstate backtracker, which triggers under the same conditions that the RE2 backtracker triggers. However I wasn't sure how to port over some of the optimizations in the RE2 backtracker, and there is a ~2% penalty on benchmarks that don't trigger the backtracker. benchmark old ns/op new ns/op delta BenchmarkLiteral 312 189 -39.42% BenchmarkNotLiteral 4435 3001 -32.33% BenchmarkMatchClass 5758 4378 -23.97% BenchmarkMatchClass_InRange 5385 4084 -24.16% BenchmarkReplaceAll 5291 3505 -33.76% BenchmarkAnchoredLiteralShortNonMatch 190 200 +5.26% BenchmarkAnchoredLiteralLongNonMatch 189 194 +2.65% BenchmarkAnchoredShortMatch 479 304 -36.53% BenchmarkAnchoredLongMatch 478 499 +4.39% BenchmarkOnePassShortA 791 798 +0.88% BenchmarkNotOnePassShortA 3202 1571 -50.94% BenchmarkOnePassShortB 614 633 +3.09% BenchmarkNotOnePassShortB 2685 881 -67.19% BenchmarkOnePassLongPrefix 152 154 +1.32% BenchmarkOnePassLongNotPrefix 505 533 +5.54% BenchmarkMatchEasy0_32 139 171 +23.02% BenchmarkMatchEasy0_1K 653 1797 +175.19% BenchmarkMatchEasy0_32K 12032 13346 +10.92% BenchmarkMatchEasy0_1M 462882 461272 -0.35% BenchmarkMatchEasy0_32M 15015339 15365238 +2.33% BenchmarkMatchEasy1_32 122 168 +37.70% BenchmarkMatchEasy1_1K 3339 2612 -21.77% BenchmarkMatchEasy1_32K 72330 71721 -0.84% BenchmarkMatchEasy1_1M 2545410 2652284 +4.20% BenchmarkMatchEasy1_32M 80072063 82609750 +3.17% BenchmarkMatchMedium_32 2359 1980 -16.07% BenchmarkMatchMedium_1K 75939 58593 -22.84% BenchmarkMatchMedium_32K 2450907 2501106 +2.05% BenchmarkMatchMedium_1M 78707697 80174418 +1.86% BenchmarkMatchMedium_32M 2535146010 2570896441 +1.41% BenchmarkMatchHard_32 4297 2960 -31.11% BenchmarkMatchHard_1K 133592 88997 -33.38% BenchmarkMatchHard_32K 4240445 4336907 +2.27% BenchmarkMatchHard_1M 136187006 139350238 +2.32% BenchmarkMatchHard_32M 4350855890 4478537306 +2.93% benchmark old MB/s new MB/s speedup BenchmarkMatchEasy0_32 228.74 186.11 0.81x BenchmarkMatchEasy0_1K 1565.91 569.64 0.36x BenchmarkMatchEasy0_32K 2723.31 2455.10 0.90x BenchmarkMatchEasy0_1M 2265.32 2273.22 1.00x BenchmarkMatchEasy0_32M 2234.68 2183.79 0.98x BenchmarkMatchEasy1_32 261.08 190.22 0.73x BenchmarkMatchEasy1_1K 306.59 391.91 1.28x BenchmarkMatchEasy1_32K 453.03 456.88 1.01x BenchmarkMatchEasy1_1M 411.95 395.35 0.96x BenchmarkMatchEasy1_32M 419.05 406.18 0.97x BenchmarkMatchMedium_32 13.56 16.16 1.19x BenchmarkMatchMedium_1K 13.48 17.48 1.30x BenchmarkMatchMedium_32K 13.37 13.10 0.98x BenchmarkMatchMedium_1M 13.32 13.08 0.98x BenchmarkMatchMedium_32M 13.24 13.05 0.99x BenchmarkMatchHard_32 7.45 10.81 1.45x BenchmarkMatchHard_1K 7.67 11.51 1.50x BenchmarkMatchHard_32K 7.73 7.56 0.98x BenchmarkMatchHard_1M 7.70 7.52 0.98x BenchmarkMatchHard_32M 7.71 7.49 0.97x Fixes #4154 Change-Id: Iff7fb9507f0872b320d08afc08679751ed1b28bc Reviewed-on: https://go-review.googlesource.com/2153 Reviewed-by: Russ Cox <rsc@golang.org>
2014-12-28 00:17:01 -08:00
// later.
regexp: make (*bitState).push inlinable By refactoring job.arg from int with 0/1 as the only valid values into bool and simplifying (*bitState).push, we reduce the number of nodes below the inlining threshold. This improves backtracking regexp performance by 5-10% and go1 geomean by 1.7% Full performance data below: name old time/op new time/op delta Find-6 510ns ± 0% 480ns ± 1% -5.90% (p=0.000 n=10+10) FindString-6 504ns ± 1% 479ns ± 1% -5.10% (p=0.000 n=10+10) FindSubmatch-6 689ns ± 1% 659ns ± 1% -4.27% (p=0.000 n=9+10) FindStringSubmatch-6 659ns ± 0% 628ns ± 1% -4.69% (p=0.000 n=8+10) Literal-6 174ns ± 1% 171ns ± 1% -1.50% (p=0.000 n=10+10) NotLiteral-6 2.89µs ± 1% 2.72µs ± 0% -5.84% (p=0.000 n=10+9) MatchClass-6 4.65µs ± 1% 4.28µs ± 1% -7.96% (p=0.000 n=10+10) MatchClass_InRange-6 4.15µs ± 1% 3.80µs ± 0% -8.61% (p=0.000 n=10+8) ReplaceAll-6 2.72µs ± 1% 2.60µs ± 1% -4.68% (p=0.000 n=10+10) AnchoredLiteralShortNonMatch-6 158ns ± 1% 153ns ± 1% -3.03% (p=0.000 n=10+10) AnchoredLiteralLongNonMatch-6 176ns ± 1% 176ns ± 0% ~ (p=1.000 n=10+9) AnchoredShortMatch-6 260ns ± 0% 255ns ± 1% -1.84% (p=0.000 n=9+10) AnchoredLongMatch-6 456ns ± 0% 455ns ± 0% -0.19% (p=0.008 n=8+10) OnePassShortA-6 1.13µs ± 1% 1.12µs ± 0% -0.57% (p=0.046 n=10+8) NotOnePassShortA-6 1.14µs ± 1% 1.14µs ± 1% ~ (p=0.162 n=10+10) OnePassShortB-6 908ns ± 0% 893ns ± 0% -1.60% (p=0.000 n=8+9) NotOnePassShortB-6 857ns ± 0% 803ns ± 1% -6.34% (p=0.000 n=8+10) OnePassLongPrefix-6 190ns ± 0% 190ns ± 1% ~ (p=0.059 n=8+10) OnePassLongNotPrefix-6 722ns ± 1% 722ns ± 1% ~ (p=0.451 n=10+10) MatchParallelShared-6 810ns ± 2% 807ns ± 2% ~ (p=0.643 n=10+10) MatchParallelCopied-6 72.1ns ± 1% 69.4ns ± 1% -3.81% (p=0.000 n=10+10) QuoteMetaAll-6 213ns ± 2% 216ns ± 3% ~ (p=0.284 n=10+10) QuoteMetaNone-6 89.7ns ± 1% 89.8ns ± 1% ~ (p=0.616 n=10+10) Match/Easy0/32-6 127ns ± 1% 127ns ± 1% ~ (p=0.977 n=10+10) Match/Easy0/1K-6 566ns ± 0% 566ns ± 0% ~ (p=1.000 n=8+8) Match/Easy0/32K-6 9.30µs ± 1% 9.28µs ± 1% ~ (p=0.529 n=10+10) Match/Easy0/1M-6 460µs ± 1% 460µs ± 1% ~ (p=0.853 n=10+10) Match/Easy0/32M-6 15.0ms ± 0% 15.1ms ± 0% +0.77% (p=0.000 n=9+8) Match/Easy0i/32-6 2.10µs ± 1% 1.98µs ± 0% -6.02% (p=0.000 n=10+8) Match/Easy0i/1K-6 61.5µs ± 0% 57.2µs ± 0% -6.97% (p=0.000 n=10+9) Match/Easy0i/32K-6 2.75ms ± 0% 2.72ms ± 0% -1.10% (p=0.000 n=9+9) Match/Easy0i/1M-6 88.0ms ± 0% 86.9ms ± 1% -1.29% (p=0.000 n=8+10) Match/Easy0i/32M-6 2.82s ± 0% 2.77s ± 1% -1.81% (p=0.000 n=8+10) Match/Easy1/32-6 123ns ± 1% 124ns ± 1% +0.90% (p=0.001 n=10+10) Match/Easy1/1K-6 1.70µs ± 1% 1.65µs ± 0% -3.18% (p=0.000 n=9+10) Match/Easy1/32K-6 69.1µs ± 0% 68.4µs ± 1% -0.95% (p=0.000 n=8+10) Match/Easy1/1M-6 2.46ms ± 1% 2.42ms ± 1% -1.66% (p=0.000 n=10+10) Match/Easy1/32M-6 78.4ms ± 1% 77.5ms ± 0% -1.08% (p=0.000 n=10+9) Match/Medium/32-6 2.07µs ± 1% 1.91µs ± 1% -7.69% (p=0.000 n=10+10) Match/Medium/1K-6 62.8µs ± 0% 58.0µs ± 1% -7.70% (p=0.000 n=8+10) Match/Medium/32K-6 2.63ms ± 1% 2.58ms ± 1% -2.14% (p=0.000 n=10+10) Match/Medium/1M-6 84.6ms ± 0% 82.5ms ± 0% -2.37% (p=0.000 n=8+9) Match/Medium/32M-6 2.71s ± 0% 2.64s ± 0% -2.46% (p=0.000 n=10+9) Match/Hard/32-6 3.26µs ± 1% 2.98µs ± 1% -8.49% (p=0.000 n=10+10) Match/Hard/1K-6 100µs ± 0% 90µs ± 1% -9.55% (p=0.000 n=9+10) Match/Hard/32K-6 3.82ms ± 0% 3.82ms ± 1% ~ (p=0.515 n=8+10) Match/Hard/1M-6 122ms ± 1% 123ms ± 0% +0.66% (p=0.000 n=10+8) Match/Hard/32M-6 3.89s ± 1% 3.91s ± 1% ~ (p=0.105 n=10+10) Match/Hard1/32-6 18.1µs ± 1% 16.1µs ± 1% -11.31% (p=0.000 n=10+10) Match/Hard1/1K-6 565µs ± 0% 493µs ± 1% -12.65% (p=0.000 n=8+10) Match/Hard1/32K-6 18.8ms ± 0% 18.8ms ± 1% ~ (p=0.905 n=9+10) Match/Hard1/1M-6 602ms ± 1% 602ms ± 1% ~ (p=0.278 n=9+10) Match/Hard1/32M-6 19.1s ± 1% 19.2s ± 1% +0.31% (p=0.035 n=9+10) Match_onepass_regex/32-6 6.32µs ± 1% 6.34µs ± 1% ~ (p=0.060 n=10+10) Match_onepass_regex/1K-6 204µs ± 1% 204µs ± 1% ~ (p=0.842 n=9+10) Match_onepass_regex/32K-6 6.53ms ± 0% 6.55ms ± 1% +0.36% (p=0.005 n=10+10) Match_onepass_regex/1M-6 209ms ± 0% 208ms ± 1% -0.65% (p=0.034 n=8+10) Match_onepass_regex/32M-6 6.72s ± 0% 6.68s ± 1% -0.74% (p=0.000 n=9+10) CompileOnepass/^(?:(?:(?:.(?:$))?))...-6 7.02µs ± 1% 7.02µs ± 1% ~ (p=0.671 n=10+10) CompileOnepass/^abcd$-6 5.65µs ± 1% 5.65µs ± 1% ~ (p=0.411 n=10+9) CompileOnepass/^(?:(?:a{0,})*?)$-6 7.06µs ± 1% 7.06µs ± 1% ~ (p=0.912 n=10+10) CompileOnepass/^(?:(?:a+)*)$-6 6.40µs ± 1% 6.41µs ± 1% ~ (p=0.699 n=10+10) CompileOnepass/^(?:(?:a|(?:aa)))$-6 8.18µs ± 2% 8.16µs ± 1% ~ (p=0.529 n=10+10) CompileOnepass/^(?:[^\s\S])$-6 5.08µs ± 1% 5.17µs ± 1% +1.77% (p=0.000 n=9+10) CompileOnepass/^(?:(?:(?:a*)+))$-6 6.86µs ± 1% 6.85µs ± 0% ~ (p=0.190 n=10+9) CompileOnepass/^[a-c]+$-6 5.14µs ± 1% 5.11µs ± 0% -0.53% (p=0.041 n=10+10) CompileOnepass/^[a-c]*$-6 5.62µs ± 1% 5.63µs ± 1% ~ (p=0.382 n=10+10) CompileOnepass/^(?:a*)$-6 5.76µs ± 1% 5.73µs ± 1% -0.41% (p=0.008 n=9+10) CompileOnepass/^(?:(?:aa)|a)$-6 7.89µs ± 1% 7.84µs ± 1% -0.66% (p=0.020 n=10+10) CompileOnepass/^...$-6 5.38µs ± 1% 5.38µs ± 1% ~ (p=0.857 n=9+10) CompileOnepass/^(?:a|(?:aa))$-6 7.80µs ± 2% 7.82µs ± 1% ~ (p=0.342 n=10+10) CompileOnepass/^a((b))c$-6 7.75µs ± 1% 7.78µs ± 1% ~ (p=0.172 n=10+10) CompileOnepass/^a.[l-nA-Cg-j]?e$-6 8.39µs ± 1% 8.42µs ± 1% ~ (p=0.138 n=10+10) CompileOnepass/^a((b))$-6 6.92µs ± 1% 6.95µs ± 1% ~ (p=0.159 n=10+10) CompileOnepass/^a(?:(b)|(c))c$-6 10.0µs ± 1% 10.0µs ± 1% ~ (p=0.896 n=10+10) CompileOnepass/^a(?:b|c)$-6 5.62µs ± 1% 5.66µs ± 1% +0.71% (p=0.023 n=10+10) CompileOnepass/^a(?:b?|c)$-6 8.49µs ± 1% 8.43µs ± 1% -0.69% (p=0.010 n=10+10) CompileOnepass/^a(?:b?|c+)$-6 9.26µs ± 1% 9.28µs ± 1% ~ (p=0.448 n=10+10) CompileOnepass/^a(?:bc)+$-6 6.52µs ± 1% 6.46µs ± 2% -1.02% (p=0.003 n=10+10) CompileOnepass/^a(?:[bcd])+$-6 6.29µs ± 1% 6.32µs ± 1% ~ (p=0.256 n=10+10) CompileOnepass/^a((?:[bcd])+)$-6 7.77µs ± 1% 7.79µs ± 1% ~ (p=0.105 n=10+10) CompileOnepass/^a(:?b|c)*d$-6 14.0µs ± 1% 13.9µs ± 1% -0.69% (p=0.003 n=10+10) CompileOnepass/^.bc(d|e)*$-6 8.96µs ± 1% 9.06µs ± 1% +1.20% (p=0.000 n=10+9) CompileOnepass/^loooooooooooooooooo...-6 219µs ± 1% 220µs ± 1% +0.63% (p=0.006 n=9+10) [Geo mean] 31.6µs 31.1µs -1.82% name old speed new speed delta QuoteMetaAll-6 65.5MB/s ± 2% 64.8MB/s ± 3% ~ (p=0.315 n=10+10) QuoteMetaNone-6 290MB/s ± 1% 290MB/s ± 1% ~ (p=0.755 n=10+10) Match/Easy0/32-6 250MB/s ± 0% 251MB/s ± 1% ~ (p=0.277 n=8+9) Match/Easy0/1K-6 1.81GB/s ± 0% 1.81GB/s ± 0% ~ (p=0.408 n=8+10) Match/Easy0/32K-6 3.52GB/s ± 1% 3.53GB/s ± 1% ~ (p=0.529 n=10+10) Match/Easy0/1M-6 2.28GB/s ± 1% 2.28GB/s ± 1% ~ (p=0.853 n=10+10) Match/Easy0/32M-6 2.24GB/s ± 0% 2.23GB/s ± 0% -0.76% (p=0.000 n=9+8) Match/Easy0i/32-6 15.2MB/s ± 1% 16.2MB/s ± 0% +6.43% (p=0.000 n=10+9) Match/Easy0i/1K-6 16.6MB/s ± 0% 17.9MB/s ± 0% +7.48% (p=0.000 n=10+9) Match/Easy0i/32K-6 11.9MB/s ± 0% 12.0MB/s ± 0% +1.11% (p=0.000 n=9+9) Match/Easy0i/1M-6 11.9MB/s ± 0% 12.1MB/s ± 1% +1.31% (p=0.000 n=8+10) Match/Easy0i/32M-6 11.9MB/s ± 0% 12.1MB/s ± 1% +1.84% (p=0.000 n=8+10) Match/Easy1/32-6 260MB/s ± 1% 258MB/s ± 1% -0.91% (p=0.001 n=10+10) Match/Easy1/1K-6 601MB/s ± 1% 621MB/s ± 0% +3.28% (p=0.000 n=9+10) Match/Easy1/32K-6 474MB/s ± 0% 479MB/s ± 1% +0.96% (p=0.000 n=8+10) Match/Easy1/1M-6 426MB/s ± 1% 433MB/s ± 1% +1.68% (p=0.000 n=10+10) Match/Easy1/32M-6 428MB/s ± 1% 433MB/s ± 0% +1.09% (p=0.000 n=10+9) Match/Medium/32-6 15.4MB/s ± 1% 16.7MB/s ± 1% +8.23% (p=0.000 n=10+9) Match/Medium/1K-6 16.3MB/s ± 1% 17.7MB/s ± 1% +8.43% (p=0.000 n=9+10) Match/Medium/32K-6 12.5MB/s ± 1% 12.7MB/s ± 1% +2.15% (p=0.000 n=10+10) Match/Medium/1M-6 12.4MB/s ± 0% 12.7MB/s ± 0% +2.44% (p=0.000 n=8+9) Match/Medium/32M-6 12.4MB/s ± 0% 12.7MB/s ± 0% +2.52% (p=0.000 n=10+9) Match/Hard/32-6 9.82MB/s ± 1% 10.73MB/s ± 1% +9.29% (p=0.000 n=10+10) Match/Hard/1K-6 10.2MB/s ± 0% 11.3MB/s ± 1% +10.56% (p=0.000 n=9+10) Match/Hard/32K-6 8.58MB/s ± 0% 8.58MB/s ± 1% ~ (p=0.554 n=8+10) Match/Hard/1M-6 8.59MB/s ± 1% 8.53MB/s ± 0% -0.70% (p=0.000 n=10+8) Match/Hard/32M-6 8.62MB/s ± 1% 8.59MB/s ± 1% ~ (p=0.098 n=10+10) Match/Hard1/32-6 1.77MB/s ± 1% 1.99MB/s ± 1% +12.40% (p=0.000 n=10+8) Match/Hard1/1K-6 1.81MB/s ± 1% 2.08MB/s ± 1% +14.55% (p=0.000 n=10+10) Match/Hard1/32K-6 1.74MB/s ± 0% 1.74MB/s ± 0% ~ (p=0.108 n=9+10) Match/Hard1/1M-6 1.74MB/s ± 0% 1.74MB/s ± 1% ~ (p=1.000 n=9+10) Match/Hard1/32M-6 1.75MB/s ± 0% 1.75MB/s ± 1% ~ (p=0.157 n=9+10) Match_onepass_regex/32-6 5.05MB/s ± 0% 5.05MB/s ± 1% ~ (p=0.262 n=8+10) Match_onepass_regex/1K-6 5.02MB/s ± 1% 5.02MB/s ± 1% ~ (p=0.677 n=9+10) Match_onepass_regex/32K-6 5.02MB/s ± 0% 4.99MB/s ± 0% -0.47% (p=0.000 n=10+9) Match_onepass_regex/1M-6 5.01MB/s ± 0% 5.04MB/s ± 1% +0.68% (p=0.017 n=8+10) Match_onepass_regex/32M-6 4.99MB/s ± 0% 5.03MB/s ± 1% +0.74% (p=0.000 n=10+10) [Geo mean] 29.1MB/s 29.8MB/s +2.44% go1 data for reference name old time/op new time/op delta BinaryTree17-6 4.39s ± 1% 4.37s ± 0% -0.58% (p=0.006 n=9+9) Fannkuch11-6 5.13s ± 0% 5.18s ± 0% +0.87% (p=0.000 n=8+8) FmtFprintfEmpty-6 74.2ns ± 0% 71.7ns ± 3% -3.41% (p=0.000 n=10+10) FmtFprintfString-6 120ns ± 1% 122ns ± 2% ~ (p=0.333 n=10+10) FmtFprintfInt-6 127ns ± 1% 127ns ± 1% ~ (p=0.809 n=10+10) FmtFprintfIntInt-6 186ns ± 0% 188ns ± 1% +1.02% (p=0.002 n=8+10) FmtFprintfPrefixedInt-6 223ns ± 1% 222ns ± 2% ~ (p=0.421 n=10+10) FmtFprintfFloat-6 374ns ± 0% 376ns ± 1% +0.43% (p=0.030 n=8+10) FmtManyArgs-6 795ns ± 0% 788ns ± 1% -0.79% (p=0.000 n=8+9) GobDecode-6 10.9ms ± 1% 10.9ms ± 0% ~ (p=0.079 n=10+9) GobEncode-6 8.60ms ± 1% 8.56ms ± 0% -0.52% (p=0.004 n=10+10) Gzip-6 378ms ± 1% 386ms ± 1% +2.28% (p=0.000 n=10+10) Gunzip-6 63.7ms ± 0% 62.3ms ± 0% -2.22% (p=0.000 n=9+8) HTTPClientServer-6 120µs ± 3% 114µs ± 3% -4.99% (p=0.000 n=10+10) JSONEncode-6 20.3ms ± 1% 19.9ms ± 0% -1.90% (p=0.000 n=9+10) JSONDecode-6 84.3ms ± 0% 83.7ms ± 0% -0.76% (p=0.000 n=8+8) Mandelbrot200-6 6.91ms ± 0% 6.89ms ± 0% -0.31% (p=0.000 n=9+8) GoParse-6 5.49ms ± 0% 5.47ms ± 1% ~ (p=0.101 n=8+10) RegexpMatchEasy0_32-6 130ns ± 0% 128ns ± 0% -1.54% (p=0.002 n=8+10) RegexpMatchEasy0_1K-6 322ns ± 1% 322ns ± 0% ~ (p=0.525 n=10+9) RegexpMatchEasy1_32-6 124ns ± 0% 124ns ± 0% -0.32% (p=0.046 n=8+10) RegexpMatchEasy1_1K-6 570ns ± 0% 548ns ± 1% -3.76% (p=0.000 n=10+10) RegexpMatchMedium_32-6 196ns ± 0% 183ns ± 1% -6.61% (p=0.000 n=8+10) RegexpMatchMedium_1K-6 64.3µs ± 0% 59.0µs ± 1% -8.31% (p=0.000 n=8+10) RegexpMatchHard_32-6 3.08µs ± 0% 2.80µs ± 0% -8.96% (p=0.000 n=8+9) RegexpMatchHard_1K-6 93.0µs ± 0% 84.5µs ± 1% -9.17% (p=0.000 n=8+9) Revcomp-6 647ms ± 2% 646ms ± 1% ~ (p=0.720 n=10+9) Template-6 92.3ms ± 0% 91.7ms ± 0% -0.65% (p=0.000 n=8+8) TimeParse-6 490ns ± 0% 488ns ± 0% -0.43% (p=0.000 n=10+10) TimeFormat-6 513ns ± 0% 513ns ± 1% ~ (p=0.144 n=9+10) [Geo mean] 79.1µs 77.7µs -1.73% name old speed new speed delta GobDecode-6 70.1MB/s ± 1% 70.3MB/s ± 0% ~ (p=0.078 n=10+9) GobEncode-6 89.2MB/s ± 1% 89.7MB/s ± 0% +0.52% (p=0.004 n=10+10) Gzip-6 51.4MB/s ± 1% 50.2MB/s ± 1% -2.23% (p=0.000 n=10+10) Gunzip-6 304MB/s ± 0% 311MB/s ± 0% +2.27% (p=0.000 n=9+8) JSONEncode-6 95.8MB/s ± 1% 97.7MB/s ± 0% +1.93% (p=0.000 n=9+10) JSONDecode-6 23.0MB/s ± 0% 23.2MB/s ± 0% +0.76% (p=0.000 n=8+8) GoParse-6 10.6MB/s ± 0% 10.6MB/s ± 1% ~ (p=0.111 n=8+10) RegexpMatchEasy0_32-6 244MB/s ± 0% 249MB/s ± 0% +2.06% (p=0.000 n=9+10) RegexpMatchEasy0_1K-6 3.18GB/s ± 1% 3.17GB/s ± 0% ~ (p=0.211 n=10+9) RegexpMatchEasy1_32-6 257MB/s ± 0% 258MB/s ± 0% +0.37% (p=0.000 n=8+8) RegexpMatchEasy1_1K-6 1.80GB/s ± 0% 1.87GB/s ± 1% +3.91% (p=0.000 n=10+10) RegexpMatchMedium_32-6 5.08MB/s ± 0% 5.43MB/s ± 1% +7.03% (p=0.000 n=8+10) RegexpMatchMedium_1K-6 15.9MB/s ± 0% 17.4MB/s ± 1% +9.08% (p=0.000 n=8+10) RegexpMatchHard_32-6 10.4MB/s ± 0% 11.4MB/s ± 0% +9.82% (p=0.000 n=8+9) RegexpMatchHard_1K-6 11.0MB/s ± 0% 12.1MB/s ± 1% +10.10% (p=0.000 n=8+9) Revcomp-6 393MB/s ± 2% 394MB/s ± 1% ~ (p=0.720 n=10+9) Template-6 21.0MB/s ± 0% 21.2MB/s ± 0% +0.66% (p=0.000 n=8+8) [Geo mean] 74.2MB/s 76.2MB/s +2.70% Updates #21851 Change-Id: Ie88455db925f422a828f8528293790726a9c036b Reviewed-on: https://go-review.googlesource.com/65491 Run-TryBot: Ilya Tocar <ilya.tocar@intel.com> Reviewed-by: Daniel Martí <mvdan@mvdan.cc> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2017-09-22 15:15:23 -05:00
if arg {
regexp: port RE2's bitstate backtracker to the regexp package This is a port of RE2's bitstate backtracker, which triggers under the same conditions that the RE2 backtracker triggers. However I wasn't sure how to port over some of the optimizations in the RE2 backtracker, and there is a ~2% penalty on benchmarks that don't trigger the backtracker. benchmark old ns/op new ns/op delta BenchmarkLiteral 312 189 -39.42% BenchmarkNotLiteral 4435 3001 -32.33% BenchmarkMatchClass 5758 4378 -23.97% BenchmarkMatchClass_InRange 5385 4084 -24.16% BenchmarkReplaceAll 5291 3505 -33.76% BenchmarkAnchoredLiteralShortNonMatch 190 200 +5.26% BenchmarkAnchoredLiteralLongNonMatch 189 194 +2.65% BenchmarkAnchoredShortMatch 479 304 -36.53% BenchmarkAnchoredLongMatch 478 499 +4.39% BenchmarkOnePassShortA 791 798 +0.88% BenchmarkNotOnePassShortA 3202 1571 -50.94% BenchmarkOnePassShortB 614 633 +3.09% BenchmarkNotOnePassShortB 2685 881 -67.19% BenchmarkOnePassLongPrefix 152 154 +1.32% BenchmarkOnePassLongNotPrefix 505 533 +5.54% BenchmarkMatchEasy0_32 139 171 +23.02% BenchmarkMatchEasy0_1K 653 1797 +175.19% BenchmarkMatchEasy0_32K 12032 13346 +10.92% BenchmarkMatchEasy0_1M 462882 461272 -0.35% BenchmarkMatchEasy0_32M 15015339 15365238 +2.33% BenchmarkMatchEasy1_32 122 168 +37.70% BenchmarkMatchEasy1_1K 3339 2612 -21.77% BenchmarkMatchEasy1_32K 72330 71721 -0.84% BenchmarkMatchEasy1_1M 2545410 2652284 +4.20% BenchmarkMatchEasy1_32M 80072063 82609750 +3.17% BenchmarkMatchMedium_32 2359 1980 -16.07% BenchmarkMatchMedium_1K 75939 58593 -22.84% BenchmarkMatchMedium_32K 2450907 2501106 +2.05% BenchmarkMatchMedium_1M 78707697 80174418 +1.86% BenchmarkMatchMedium_32M 2535146010 2570896441 +1.41% BenchmarkMatchHard_32 4297 2960 -31.11% BenchmarkMatchHard_1K 133592 88997 -33.38% BenchmarkMatchHard_32K 4240445 4336907 +2.27% BenchmarkMatchHard_1M 136187006 139350238 +2.32% BenchmarkMatchHard_32M 4350855890 4478537306 +2.93% benchmark old MB/s new MB/s speedup BenchmarkMatchEasy0_32 228.74 186.11 0.81x BenchmarkMatchEasy0_1K 1565.91 569.64 0.36x BenchmarkMatchEasy0_32K 2723.31 2455.10 0.90x BenchmarkMatchEasy0_1M 2265.32 2273.22 1.00x BenchmarkMatchEasy0_32M 2234.68 2183.79 0.98x BenchmarkMatchEasy1_32 261.08 190.22 0.73x BenchmarkMatchEasy1_1K 306.59 391.91 1.28x BenchmarkMatchEasy1_32K 453.03 456.88 1.01x BenchmarkMatchEasy1_1M 411.95 395.35 0.96x BenchmarkMatchEasy1_32M 419.05 406.18 0.97x BenchmarkMatchMedium_32 13.56 16.16 1.19x BenchmarkMatchMedium_1K 13.48 17.48 1.30x BenchmarkMatchMedium_32K 13.37 13.10 0.98x BenchmarkMatchMedium_1M 13.32 13.08 0.98x BenchmarkMatchMedium_32M 13.24 13.05 0.99x BenchmarkMatchHard_32 7.45 10.81 1.45x BenchmarkMatchHard_1K 7.67 11.51 1.50x BenchmarkMatchHard_32K 7.73 7.56 0.98x BenchmarkMatchHard_1M 7.70 7.52 0.98x BenchmarkMatchHard_32M 7.71 7.49 0.97x Fixes #4154 Change-Id: Iff7fb9507f0872b320d08afc08679751ed1b28bc Reviewed-on: https://go-review.googlesource.com/2153 Reviewed-by: Russ Cox <rsc@golang.org>
2014-12-28 00:17:01 -08:00
// Finished inst.Out; try inst.Arg.
regexp: make (*bitState).push inlinable By refactoring job.arg from int with 0/1 as the only valid values into bool and simplifying (*bitState).push, we reduce the number of nodes below the inlining threshold. This improves backtracking regexp performance by 5-10% and go1 geomean by 1.7% Full performance data below: name old time/op new time/op delta Find-6 510ns ± 0% 480ns ± 1% -5.90% (p=0.000 n=10+10) FindString-6 504ns ± 1% 479ns ± 1% -5.10% (p=0.000 n=10+10) FindSubmatch-6 689ns ± 1% 659ns ± 1% -4.27% (p=0.000 n=9+10) FindStringSubmatch-6 659ns ± 0% 628ns ± 1% -4.69% (p=0.000 n=8+10) Literal-6 174ns ± 1% 171ns ± 1% -1.50% (p=0.000 n=10+10) NotLiteral-6 2.89µs ± 1% 2.72µs ± 0% -5.84% (p=0.000 n=10+9) MatchClass-6 4.65µs ± 1% 4.28µs ± 1% -7.96% (p=0.000 n=10+10) MatchClass_InRange-6 4.15µs ± 1% 3.80µs ± 0% -8.61% (p=0.000 n=10+8) ReplaceAll-6 2.72µs ± 1% 2.60µs ± 1% -4.68% (p=0.000 n=10+10) AnchoredLiteralShortNonMatch-6 158ns ± 1% 153ns ± 1% -3.03% (p=0.000 n=10+10) AnchoredLiteralLongNonMatch-6 176ns ± 1% 176ns ± 0% ~ (p=1.000 n=10+9) AnchoredShortMatch-6 260ns ± 0% 255ns ± 1% -1.84% (p=0.000 n=9+10) AnchoredLongMatch-6 456ns ± 0% 455ns ± 0% -0.19% (p=0.008 n=8+10) OnePassShortA-6 1.13µs ± 1% 1.12µs ± 0% -0.57% (p=0.046 n=10+8) NotOnePassShortA-6 1.14µs ± 1% 1.14µs ± 1% ~ (p=0.162 n=10+10) OnePassShortB-6 908ns ± 0% 893ns ± 0% -1.60% (p=0.000 n=8+9) NotOnePassShortB-6 857ns ± 0% 803ns ± 1% -6.34% (p=0.000 n=8+10) OnePassLongPrefix-6 190ns ± 0% 190ns ± 1% ~ (p=0.059 n=8+10) OnePassLongNotPrefix-6 722ns ± 1% 722ns ± 1% ~ (p=0.451 n=10+10) MatchParallelShared-6 810ns ± 2% 807ns ± 2% ~ (p=0.643 n=10+10) MatchParallelCopied-6 72.1ns ± 1% 69.4ns ± 1% -3.81% (p=0.000 n=10+10) QuoteMetaAll-6 213ns ± 2% 216ns ± 3% ~ (p=0.284 n=10+10) QuoteMetaNone-6 89.7ns ± 1% 89.8ns ± 1% ~ (p=0.616 n=10+10) Match/Easy0/32-6 127ns ± 1% 127ns ± 1% ~ (p=0.977 n=10+10) Match/Easy0/1K-6 566ns ± 0% 566ns ± 0% ~ (p=1.000 n=8+8) Match/Easy0/32K-6 9.30µs ± 1% 9.28µs ± 1% ~ (p=0.529 n=10+10) Match/Easy0/1M-6 460µs ± 1% 460µs ± 1% ~ (p=0.853 n=10+10) Match/Easy0/32M-6 15.0ms ± 0% 15.1ms ± 0% +0.77% (p=0.000 n=9+8) Match/Easy0i/32-6 2.10µs ± 1% 1.98µs ± 0% -6.02% (p=0.000 n=10+8) Match/Easy0i/1K-6 61.5µs ± 0% 57.2µs ± 0% -6.97% (p=0.000 n=10+9) Match/Easy0i/32K-6 2.75ms ± 0% 2.72ms ± 0% -1.10% (p=0.000 n=9+9) Match/Easy0i/1M-6 88.0ms ± 0% 86.9ms ± 1% -1.29% (p=0.000 n=8+10) Match/Easy0i/32M-6 2.82s ± 0% 2.77s ± 1% -1.81% (p=0.000 n=8+10) Match/Easy1/32-6 123ns ± 1% 124ns ± 1% +0.90% (p=0.001 n=10+10) Match/Easy1/1K-6 1.70µs ± 1% 1.65µs ± 0% -3.18% (p=0.000 n=9+10) Match/Easy1/32K-6 69.1µs ± 0% 68.4µs ± 1% -0.95% (p=0.000 n=8+10) Match/Easy1/1M-6 2.46ms ± 1% 2.42ms ± 1% -1.66% (p=0.000 n=10+10) Match/Easy1/32M-6 78.4ms ± 1% 77.5ms ± 0% -1.08% (p=0.000 n=10+9) Match/Medium/32-6 2.07µs ± 1% 1.91µs ± 1% -7.69% (p=0.000 n=10+10) Match/Medium/1K-6 62.8µs ± 0% 58.0µs ± 1% -7.70% (p=0.000 n=8+10) Match/Medium/32K-6 2.63ms ± 1% 2.58ms ± 1% -2.14% (p=0.000 n=10+10) Match/Medium/1M-6 84.6ms ± 0% 82.5ms ± 0% -2.37% (p=0.000 n=8+9) Match/Medium/32M-6 2.71s ± 0% 2.64s ± 0% -2.46% (p=0.000 n=10+9) Match/Hard/32-6 3.26µs ± 1% 2.98µs ± 1% -8.49% (p=0.000 n=10+10) Match/Hard/1K-6 100µs ± 0% 90µs ± 1% -9.55% (p=0.000 n=9+10) Match/Hard/32K-6 3.82ms ± 0% 3.82ms ± 1% ~ (p=0.515 n=8+10) Match/Hard/1M-6 122ms ± 1% 123ms ± 0% +0.66% (p=0.000 n=10+8) Match/Hard/32M-6 3.89s ± 1% 3.91s ± 1% ~ (p=0.105 n=10+10) Match/Hard1/32-6 18.1µs ± 1% 16.1µs ± 1% -11.31% (p=0.000 n=10+10) Match/Hard1/1K-6 565µs ± 0% 493µs ± 1% -12.65% (p=0.000 n=8+10) Match/Hard1/32K-6 18.8ms ± 0% 18.8ms ± 1% ~ (p=0.905 n=9+10) Match/Hard1/1M-6 602ms ± 1% 602ms ± 1% ~ (p=0.278 n=9+10) Match/Hard1/32M-6 19.1s ± 1% 19.2s ± 1% +0.31% (p=0.035 n=9+10) Match_onepass_regex/32-6 6.32µs ± 1% 6.34µs ± 1% ~ (p=0.060 n=10+10) Match_onepass_regex/1K-6 204µs ± 1% 204µs ± 1% ~ (p=0.842 n=9+10) Match_onepass_regex/32K-6 6.53ms ± 0% 6.55ms ± 1% +0.36% (p=0.005 n=10+10) Match_onepass_regex/1M-6 209ms ± 0% 208ms ± 1% -0.65% (p=0.034 n=8+10) Match_onepass_regex/32M-6 6.72s ± 0% 6.68s ± 1% -0.74% (p=0.000 n=9+10) CompileOnepass/^(?:(?:(?:.(?:$))?))...-6 7.02µs ± 1% 7.02µs ± 1% ~ (p=0.671 n=10+10) CompileOnepass/^abcd$-6 5.65µs ± 1% 5.65µs ± 1% ~ (p=0.411 n=10+9) CompileOnepass/^(?:(?:a{0,})*?)$-6 7.06µs ± 1% 7.06µs ± 1% ~ (p=0.912 n=10+10) CompileOnepass/^(?:(?:a+)*)$-6 6.40µs ± 1% 6.41µs ± 1% ~ (p=0.699 n=10+10) CompileOnepass/^(?:(?:a|(?:aa)))$-6 8.18µs ± 2% 8.16µs ± 1% ~ (p=0.529 n=10+10) CompileOnepass/^(?:[^\s\S])$-6 5.08µs ± 1% 5.17µs ± 1% +1.77% (p=0.000 n=9+10) CompileOnepass/^(?:(?:(?:a*)+))$-6 6.86µs ± 1% 6.85µs ± 0% ~ (p=0.190 n=10+9) CompileOnepass/^[a-c]+$-6 5.14µs ± 1% 5.11µs ± 0% -0.53% (p=0.041 n=10+10) CompileOnepass/^[a-c]*$-6 5.62µs ± 1% 5.63µs ± 1% ~ (p=0.382 n=10+10) CompileOnepass/^(?:a*)$-6 5.76µs ± 1% 5.73µs ± 1% -0.41% (p=0.008 n=9+10) CompileOnepass/^(?:(?:aa)|a)$-6 7.89µs ± 1% 7.84µs ± 1% -0.66% (p=0.020 n=10+10) CompileOnepass/^...$-6 5.38µs ± 1% 5.38µs ± 1% ~ (p=0.857 n=9+10) CompileOnepass/^(?:a|(?:aa))$-6 7.80µs ± 2% 7.82µs ± 1% ~ (p=0.342 n=10+10) CompileOnepass/^a((b))c$-6 7.75µs ± 1% 7.78µs ± 1% ~ (p=0.172 n=10+10) CompileOnepass/^a.[l-nA-Cg-j]?e$-6 8.39µs ± 1% 8.42µs ± 1% ~ (p=0.138 n=10+10) CompileOnepass/^a((b))$-6 6.92µs ± 1% 6.95µs ± 1% ~ (p=0.159 n=10+10) CompileOnepass/^a(?:(b)|(c))c$-6 10.0µs ± 1% 10.0µs ± 1% ~ (p=0.896 n=10+10) CompileOnepass/^a(?:b|c)$-6 5.62µs ± 1% 5.66µs ± 1% +0.71% (p=0.023 n=10+10) CompileOnepass/^a(?:b?|c)$-6 8.49µs ± 1% 8.43µs ± 1% -0.69% (p=0.010 n=10+10) CompileOnepass/^a(?:b?|c+)$-6 9.26µs ± 1% 9.28µs ± 1% ~ (p=0.448 n=10+10) CompileOnepass/^a(?:bc)+$-6 6.52µs ± 1% 6.46µs ± 2% -1.02% (p=0.003 n=10+10) CompileOnepass/^a(?:[bcd])+$-6 6.29µs ± 1% 6.32µs ± 1% ~ (p=0.256 n=10+10) CompileOnepass/^a((?:[bcd])+)$-6 7.77µs ± 1% 7.79µs ± 1% ~ (p=0.105 n=10+10) CompileOnepass/^a(:?b|c)*d$-6 14.0µs ± 1% 13.9µs ± 1% -0.69% (p=0.003 n=10+10) CompileOnepass/^.bc(d|e)*$-6 8.96µs ± 1% 9.06µs ± 1% +1.20% (p=0.000 n=10+9) CompileOnepass/^loooooooooooooooooo...-6 219µs ± 1% 220µs ± 1% +0.63% (p=0.006 n=9+10) [Geo mean] 31.6µs 31.1µs -1.82% name old speed new speed delta QuoteMetaAll-6 65.5MB/s ± 2% 64.8MB/s ± 3% ~ (p=0.315 n=10+10) QuoteMetaNone-6 290MB/s ± 1% 290MB/s ± 1% ~ (p=0.755 n=10+10) Match/Easy0/32-6 250MB/s ± 0% 251MB/s ± 1% ~ (p=0.277 n=8+9) Match/Easy0/1K-6 1.81GB/s ± 0% 1.81GB/s ± 0% ~ (p=0.408 n=8+10) Match/Easy0/32K-6 3.52GB/s ± 1% 3.53GB/s ± 1% ~ (p=0.529 n=10+10) Match/Easy0/1M-6 2.28GB/s ± 1% 2.28GB/s ± 1% ~ (p=0.853 n=10+10) Match/Easy0/32M-6 2.24GB/s ± 0% 2.23GB/s ± 0% -0.76% (p=0.000 n=9+8) Match/Easy0i/32-6 15.2MB/s ± 1% 16.2MB/s ± 0% +6.43% (p=0.000 n=10+9) Match/Easy0i/1K-6 16.6MB/s ± 0% 17.9MB/s ± 0% +7.48% (p=0.000 n=10+9) Match/Easy0i/32K-6 11.9MB/s ± 0% 12.0MB/s ± 0% +1.11% (p=0.000 n=9+9) Match/Easy0i/1M-6 11.9MB/s ± 0% 12.1MB/s ± 1% +1.31% (p=0.000 n=8+10) Match/Easy0i/32M-6 11.9MB/s ± 0% 12.1MB/s ± 1% +1.84% (p=0.000 n=8+10) Match/Easy1/32-6 260MB/s ± 1% 258MB/s ± 1% -0.91% (p=0.001 n=10+10) Match/Easy1/1K-6 601MB/s ± 1% 621MB/s ± 0% +3.28% (p=0.000 n=9+10) Match/Easy1/32K-6 474MB/s ± 0% 479MB/s ± 1% +0.96% (p=0.000 n=8+10) Match/Easy1/1M-6 426MB/s ± 1% 433MB/s ± 1% +1.68% (p=0.000 n=10+10) Match/Easy1/32M-6 428MB/s ± 1% 433MB/s ± 0% +1.09% (p=0.000 n=10+9) Match/Medium/32-6 15.4MB/s ± 1% 16.7MB/s ± 1% +8.23% (p=0.000 n=10+9) Match/Medium/1K-6 16.3MB/s ± 1% 17.7MB/s ± 1% +8.43% (p=0.000 n=9+10) Match/Medium/32K-6 12.5MB/s ± 1% 12.7MB/s ± 1% +2.15% (p=0.000 n=10+10) Match/Medium/1M-6 12.4MB/s ± 0% 12.7MB/s ± 0% +2.44% (p=0.000 n=8+9) Match/Medium/32M-6 12.4MB/s ± 0% 12.7MB/s ± 0% +2.52% (p=0.000 n=10+9) Match/Hard/32-6 9.82MB/s ± 1% 10.73MB/s ± 1% +9.29% (p=0.000 n=10+10) Match/Hard/1K-6 10.2MB/s ± 0% 11.3MB/s ± 1% +10.56% (p=0.000 n=9+10) Match/Hard/32K-6 8.58MB/s ± 0% 8.58MB/s ± 1% ~ (p=0.554 n=8+10) Match/Hard/1M-6 8.59MB/s ± 1% 8.53MB/s ± 0% -0.70% (p=0.000 n=10+8) Match/Hard/32M-6 8.62MB/s ± 1% 8.59MB/s ± 1% ~ (p=0.098 n=10+10) Match/Hard1/32-6 1.77MB/s ± 1% 1.99MB/s ± 1% +12.40% (p=0.000 n=10+8) Match/Hard1/1K-6 1.81MB/s ± 1% 2.08MB/s ± 1% +14.55% (p=0.000 n=10+10) Match/Hard1/32K-6 1.74MB/s ± 0% 1.74MB/s ± 0% ~ (p=0.108 n=9+10) Match/Hard1/1M-6 1.74MB/s ± 0% 1.74MB/s ± 1% ~ (p=1.000 n=9+10) Match/Hard1/32M-6 1.75MB/s ± 0% 1.75MB/s ± 1% ~ (p=0.157 n=9+10) Match_onepass_regex/32-6 5.05MB/s ± 0% 5.05MB/s ± 1% ~ (p=0.262 n=8+10) Match_onepass_regex/1K-6 5.02MB/s ± 1% 5.02MB/s ± 1% ~ (p=0.677 n=9+10) Match_onepass_regex/32K-6 5.02MB/s ± 0% 4.99MB/s ± 0% -0.47% (p=0.000 n=10+9) Match_onepass_regex/1M-6 5.01MB/s ± 0% 5.04MB/s ± 1% +0.68% (p=0.017 n=8+10) Match_onepass_regex/32M-6 4.99MB/s ± 0% 5.03MB/s ± 1% +0.74% (p=0.000 n=10+10) [Geo mean] 29.1MB/s 29.8MB/s +2.44% go1 data for reference name old time/op new time/op delta BinaryTree17-6 4.39s ± 1% 4.37s ± 0% -0.58% (p=0.006 n=9+9) Fannkuch11-6 5.13s ± 0% 5.18s ± 0% +0.87% (p=0.000 n=8+8) FmtFprintfEmpty-6 74.2ns ± 0% 71.7ns ± 3% -3.41% (p=0.000 n=10+10) FmtFprintfString-6 120ns ± 1% 122ns ± 2% ~ (p=0.333 n=10+10) FmtFprintfInt-6 127ns ± 1% 127ns ± 1% ~ (p=0.809 n=10+10) FmtFprintfIntInt-6 186ns ± 0% 188ns ± 1% +1.02% (p=0.002 n=8+10) FmtFprintfPrefixedInt-6 223ns ± 1% 222ns ± 2% ~ (p=0.421 n=10+10) FmtFprintfFloat-6 374ns ± 0% 376ns ± 1% +0.43% (p=0.030 n=8+10) FmtManyArgs-6 795ns ± 0% 788ns ± 1% -0.79% (p=0.000 n=8+9) GobDecode-6 10.9ms ± 1% 10.9ms ± 0% ~ (p=0.079 n=10+9) GobEncode-6 8.60ms ± 1% 8.56ms ± 0% -0.52% (p=0.004 n=10+10) Gzip-6 378ms ± 1% 386ms ± 1% +2.28% (p=0.000 n=10+10) Gunzip-6 63.7ms ± 0% 62.3ms ± 0% -2.22% (p=0.000 n=9+8) HTTPClientServer-6 120µs ± 3% 114µs ± 3% -4.99% (p=0.000 n=10+10) JSONEncode-6 20.3ms ± 1% 19.9ms ± 0% -1.90% (p=0.000 n=9+10) JSONDecode-6 84.3ms ± 0% 83.7ms ± 0% -0.76% (p=0.000 n=8+8) Mandelbrot200-6 6.91ms ± 0% 6.89ms ± 0% -0.31% (p=0.000 n=9+8) GoParse-6 5.49ms ± 0% 5.47ms ± 1% ~ (p=0.101 n=8+10) RegexpMatchEasy0_32-6 130ns ± 0% 128ns ± 0% -1.54% (p=0.002 n=8+10) RegexpMatchEasy0_1K-6 322ns ± 1% 322ns ± 0% ~ (p=0.525 n=10+9) RegexpMatchEasy1_32-6 124ns ± 0% 124ns ± 0% -0.32% (p=0.046 n=8+10) RegexpMatchEasy1_1K-6 570ns ± 0% 548ns ± 1% -3.76% (p=0.000 n=10+10) RegexpMatchMedium_32-6 196ns ± 0% 183ns ± 1% -6.61% (p=0.000 n=8+10) RegexpMatchMedium_1K-6 64.3µs ± 0% 59.0µs ± 1% -8.31% (p=0.000 n=8+10) RegexpMatchHard_32-6 3.08µs ± 0% 2.80µs ± 0% -8.96% (p=0.000 n=8+9) RegexpMatchHard_1K-6 93.0µs ± 0% 84.5µs ± 1% -9.17% (p=0.000 n=8+9) Revcomp-6 647ms ± 2% 646ms ± 1% ~ (p=0.720 n=10+9) Template-6 92.3ms ± 0% 91.7ms ± 0% -0.65% (p=0.000 n=8+8) TimeParse-6 490ns ± 0% 488ns ± 0% -0.43% (p=0.000 n=10+10) TimeFormat-6 513ns ± 0% 513ns ± 1% ~ (p=0.144 n=9+10) [Geo mean] 79.1µs 77.7µs -1.73% name old speed new speed delta GobDecode-6 70.1MB/s ± 1% 70.3MB/s ± 0% ~ (p=0.078 n=10+9) GobEncode-6 89.2MB/s ± 1% 89.7MB/s ± 0% +0.52% (p=0.004 n=10+10) Gzip-6 51.4MB/s ± 1% 50.2MB/s ± 1% -2.23% (p=0.000 n=10+10) Gunzip-6 304MB/s ± 0% 311MB/s ± 0% +2.27% (p=0.000 n=9+8) JSONEncode-6 95.8MB/s ± 1% 97.7MB/s ± 0% +1.93% (p=0.000 n=9+10) JSONDecode-6 23.0MB/s ± 0% 23.2MB/s ± 0% +0.76% (p=0.000 n=8+8) GoParse-6 10.6MB/s ± 0% 10.6MB/s ± 1% ~ (p=0.111 n=8+10) RegexpMatchEasy0_32-6 244MB/s ± 0% 249MB/s ± 0% +2.06% (p=0.000 n=9+10) RegexpMatchEasy0_1K-6 3.18GB/s ± 1% 3.17GB/s ± 0% ~ (p=0.211 n=10+9) RegexpMatchEasy1_32-6 257MB/s ± 0% 258MB/s ± 0% +0.37% (p=0.000 n=8+8) RegexpMatchEasy1_1K-6 1.80GB/s ± 0% 1.87GB/s ± 1% +3.91% (p=0.000 n=10+10) RegexpMatchMedium_32-6 5.08MB/s ± 0% 5.43MB/s ± 1% +7.03% (p=0.000 n=8+10) RegexpMatchMedium_1K-6 15.9MB/s ± 0% 17.4MB/s ± 1% +9.08% (p=0.000 n=8+10) RegexpMatchHard_32-6 10.4MB/s ± 0% 11.4MB/s ± 0% +9.82% (p=0.000 n=8+9) RegexpMatchHard_1K-6 11.0MB/s ± 0% 12.1MB/s ± 1% +10.10% (p=0.000 n=8+9) Revcomp-6 393MB/s ± 2% 394MB/s ± 1% ~ (p=0.720 n=10+9) Template-6 21.0MB/s ± 0% 21.2MB/s ± 0% +0.66% (p=0.000 n=8+8) [Geo mean] 74.2MB/s 76.2MB/s +2.70% Updates #21851 Change-Id: Ie88455db925f422a828f8528293790726a9c036b Reviewed-on: https://go-review.googlesource.com/65491 Run-TryBot: Ilya Tocar <ilya.tocar@intel.com> Reviewed-by: Daniel Martí <mvdan@mvdan.cc> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2017-09-22 15:15:23 -05:00
arg = false
regexp: port RE2's bitstate backtracker to the regexp package This is a port of RE2's bitstate backtracker, which triggers under the same conditions that the RE2 backtracker triggers. However I wasn't sure how to port over some of the optimizations in the RE2 backtracker, and there is a ~2% penalty on benchmarks that don't trigger the backtracker. benchmark old ns/op new ns/op delta BenchmarkLiteral 312 189 -39.42% BenchmarkNotLiteral 4435 3001 -32.33% BenchmarkMatchClass 5758 4378 -23.97% BenchmarkMatchClass_InRange 5385 4084 -24.16% BenchmarkReplaceAll 5291 3505 -33.76% BenchmarkAnchoredLiteralShortNonMatch 190 200 +5.26% BenchmarkAnchoredLiteralLongNonMatch 189 194 +2.65% BenchmarkAnchoredShortMatch 479 304 -36.53% BenchmarkAnchoredLongMatch 478 499 +4.39% BenchmarkOnePassShortA 791 798 +0.88% BenchmarkNotOnePassShortA 3202 1571 -50.94% BenchmarkOnePassShortB 614 633 +3.09% BenchmarkNotOnePassShortB 2685 881 -67.19% BenchmarkOnePassLongPrefix 152 154 +1.32% BenchmarkOnePassLongNotPrefix 505 533 +5.54% BenchmarkMatchEasy0_32 139 171 +23.02% BenchmarkMatchEasy0_1K 653 1797 +175.19% BenchmarkMatchEasy0_32K 12032 13346 +10.92% BenchmarkMatchEasy0_1M 462882 461272 -0.35% BenchmarkMatchEasy0_32M 15015339 15365238 +2.33% BenchmarkMatchEasy1_32 122 168 +37.70% BenchmarkMatchEasy1_1K 3339 2612 -21.77% BenchmarkMatchEasy1_32K 72330 71721 -0.84% BenchmarkMatchEasy1_1M 2545410 2652284 +4.20% BenchmarkMatchEasy1_32M 80072063 82609750 +3.17% BenchmarkMatchMedium_32 2359 1980 -16.07% BenchmarkMatchMedium_1K 75939 58593 -22.84% BenchmarkMatchMedium_32K 2450907 2501106 +2.05% BenchmarkMatchMedium_1M 78707697 80174418 +1.86% BenchmarkMatchMedium_32M 2535146010 2570896441 +1.41% BenchmarkMatchHard_32 4297 2960 -31.11% BenchmarkMatchHard_1K 133592 88997 -33.38% BenchmarkMatchHard_32K 4240445 4336907 +2.27% BenchmarkMatchHard_1M 136187006 139350238 +2.32% BenchmarkMatchHard_32M 4350855890 4478537306 +2.93% benchmark old MB/s new MB/s speedup BenchmarkMatchEasy0_32 228.74 186.11 0.81x BenchmarkMatchEasy0_1K 1565.91 569.64 0.36x BenchmarkMatchEasy0_32K 2723.31 2455.10 0.90x BenchmarkMatchEasy0_1M 2265.32 2273.22 1.00x BenchmarkMatchEasy0_32M 2234.68 2183.79 0.98x BenchmarkMatchEasy1_32 261.08 190.22 0.73x BenchmarkMatchEasy1_1K 306.59 391.91 1.28x BenchmarkMatchEasy1_32K 453.03 456.88 1.01x BenchmarkMatchEasy1_1M 411.95 395.35 0.96x BenchmarkMatchEasy1_32M 419.05 406.18 0.97x BenchmarkMatchMedium_32 13.56 16.16 1.19x BenchmarkMatchMedium_1K 13.48 17.48 1.30x BenchmarkMatchMedium_32K 13.37 13.10 0.98x BenchmarkMatchMedium_1M 13.32 13.08 0.98x BenchmarkMatchMedium_32M 13.24 13.05 0.99x BenchmarkMatchHard_32 7.45 10.81 1.45x BenchmarkMatchHard_1K 7.67 11.51 1.50x BenchmarkMatchHard_32K 7.73 7.56 0.98x BenchmarkMatchHard_1M 7.70 7.52 0.98x BenchmarkMatchHard_32M 7.71 7.49 0.97x Fixes #4154 Change-Id: Iff7fb9507f0872b320d08afc08679751ed1b28bc Reviewed-on: https://go-review.googlesource.com/2153 Reviewed-by: Russ Cox <rsc@golang.org>
2014-12-28 00:17:01 -08:00
pc = inst.Arg
goto CheckAndLoop
regexp: make (*bitState).push inlinable By refactoring job.arg from int with 0/1 as the only valid values into bool and simplifying (*bitState).push, we reduce the number of nodes below the inlining threshold. This improves backtracking regexp performance by 5-10% and go1 geomean by 1.7% Full performance data below: name old time/op new time/op delta Find-6 510ns ± 0% 480ns ± 1% -5.90% (p=0.000 n=10+10) FindString-6 504ns ± 1% 479ns ± 1% -5.10% (p=0.000 n=10+10) FindSubmatch-6 689ns ± 1% 659ns ± 1% -4.27% (p=0.000 n=9+10) FindStringSubmatch-6 659ns ± 0% 628ns ± 1% -4.69% (p=0.000 n=8+10) Literal-6 174ns ± 1% 171ns ± 1% -1.50% (p=0.000 n=10+10) NotLiteral-6 2.89µs ± 1% 2.72µs ± 0% -5.84% (p=0.000 n=10+9) MatchClass-6 4.65µs ± 1% 4.28µs ± 1% -7.96% (p=0.000 n=10+10) MatchClass_InRange-6 4.15µs ± 1% 3.80µs ± 0% -8.61% (p=0.000 n=10+8) ReplaceAll-6 2.72µs ± 1% 2.60µs ± 1% -4.68% (p=0.000 n=10+10) AnchoredLiteralShortNonMatch-6 158ns ± 1% 153ns ± 1% -3.03% (p=0.000 n=10+10) AnchoredLiteralLongNonMatch-6 176ns ± 1% 176ns ± 0% ~ (p=1.000 n=10+9) AnchoredShortMatch-6 260ns ± 0% 255ns ± 1% -1.84% (p=0.000 n=9+10) AnchoredLongMatch-6 456ns ± 0% 455ns ± 0% -0.19% (p=0.008 n=8+10) OnePassShortA-6 1.13µs ± 1% 1.12µs ± 0% -0.57% (p=0.046 n=10+8) NotOnePassShortA-6 1.14µs ± 1% 1.14µs ± 1% ~ (p=0.162 n=10+10) OnePassShortB-6 908ns ± 0% 893ns ± 0% -1.60% (p=0.000 n=8+9) NotOnePassShortB-6 857ns ± 0% 803ns ± 1% -6.34% (p=0.000 n=8+10) OnePassLongPrefix-6 190ns ± 0% 190ns ± 1% ~ (p=0.059 n=8+10) OnePassLongNotPrefix-6 722ns ± 1% 722ns ± 1% ~ (p=0.451 n=10+10) MatchParallelShared-6 810ns ± 2% 807ns ± 2% ~ (p=0.643 n=10+10) MatchParallelCopied-6 72.1ns ± 1% 69.4ns ± 1% -3.81% (p=0.000 n=10+10) QuoteMetaAll-6 213ns ± 2% 216ns ± 3% ~ (p=0.284 n=10+10) QuoteMetaNone-6 89.7ns ± 1% 89.8ns ± 1% ~ (p=0.616 n=10+10) Match/Easy0/32-6 127ns ± 1% 127ns ± 1% ~ (p=0.977 n=10+10) Match/Easy0/1K-6 566ns ± 0% 566ns ± 0% ~ (p=1.000 n=8+8) Match/Easy0/32K-6 9.30µs ± 1% 9.28µs ± 1% ~ (p=0.529 n=10+10) Match/Easy0/1M-6 460µs ± 1% 460µs ± 1% ~ (p=0.853 n=10+10) Match/Easy0/32M-6 15.0ms ± 0% 15.1ms ± 0% +0.77% (p=0.000 n=9+8) Match/Easy0i/32-6 2.10µs ± 1% 1.98µs ± 0% -6.02% (p=0.000 n=10+8) Match/Easy0i/1K-6 61.5µs ± 0% 57.2µs ± 0% -6.97% (p=0.000 n=10+9) Match/Easy0i/32K-6 2.75ms ± 0% 2.72ms ± 0% -1.10% (p=0.000 n=9+9) Match/Easy0i/1M-6 88.0ms ± 0% 86.9ms ± 1% -1.29% (p=0.000 n=8+10) Match/Easy0i/32M-6 2.82s ± 0% 2.77s ± 1% -1.81% (p=0.000 n=8+10) Match/Easy1/32-6 123ns ± 1% 124ns ± 1% +0.90% (p=0.001 n=10+10) Match/Easy1/1K-6 1.70µs ± 1% 1.65µs ± 0% -3.18% (p=0.000 n=9+10) Match/Easy1/32K-6 69.1µs ± 0% 68.4µs ± 1% -0.95% (p=0.000 n=8+10) Match/Easy1/1M-6 2.46ms ± 1% 2.42ms ± 1% -1.66% (p=0.000 n=10+10) Match/Easy1/32M-6 78.4ms ± 1% 77.5ms ± 0% -1.08% (p=0.000 n=10+9) Match/Medium/32-6 2.07µs ± 1% 1.91µs ± 1% -7.69% (p=0.000 n=10+10) Match/Medium/1K-6 62.8µs ± 0% 58.0µs ± 1% -7.70% (p=0.000 n=8+10) Match/Medium/32K-6 2.63ms ± 1% 2.58ms ± 1% -2.14% (p=0.000 n=10+10) Match/Medium/1M-6 84.6ms ± 0% 82.5ms ± 0% -2.37% (p=0.000 n=8+9) Match/Medium/32M-6 2.71s ± 0% 2.64s ± 0% -2.46% (p=0.000 n=10+9) Match/Hard/32-6 3.26µs ± 1% 2.98µs ± 1% -8.49% (p=0.000 n=10+10) Match/Hard/1K-6 100µs ± 0% 90µs ± 1% -9.55% (p=0.000 n=9+10) Match/Hard/32K-6 3.82ms ± 0% 3.82ms ± 1% ~ (p=0.515 n=8+10) Match/Hard/1M-6 122ms ± 1% 123ms ± 0% +0.66% (p=0.000 n=10+8) Match/Hard/32M-6 3.89s ± 1% 3.91s ± 1% ~ (p=0.105 n=10+10) Match/Hard1/32-6 18.1µs ± 1% 16.1µs ± 1% -11.31% (p=0.000 n=10+10) Match/Hard1/1K-6 565µs ± 0% 493µs ± 1% -12.65% (p=0.000 n=8+10) Match/Hard1/32K-6 18.8ms ± 0% 18.8ms ± 1% ~ (p=0.905 n=9+10) Match/Hard1/1M-6 602ms ± 1% 602ms ± 1% ~ (p=0.278 n=9+10) Match/Hard1/32M-6 19.1s ± 1% 19.2s ± 1% +0.31% (p=0.035 n=9+10) Match_onepass_regex/32-6 6.32µs ± 1% 6.34µs ± 1% ~ (p=0.060 n=10+10) Match_onepass_regex/1K-6 204µs ± 1% 204µs ± 1% ~ (p=0.842 n=9+10) Match_onepass_regex/32K-6 6.53ms ± 0% 6.55ms ± 1% +0.36% (p=0.005 n=10+10) Match_onepass_regex/1M-6 209ms ± 0% 208ms ± 1% -0.65% (p=0.034 n=8+10) Match_onepass_regex/32M-6 6.72s ± 0% 6.68s ± 1% -0.74% (p=0.000 n=9+10) CompileOnepass/^(?:(?:(?:.(?:$))?))...-6 7.02µs ± 1% 7.02µs ± 1% ~ (p=0.671 n=10+10) CompileOnepass/^abcd$-6 5.65µs ± 1% 5.65µs ± 1% ~ (p=0.411 n=10+9) CompileOnepass/^(?:(?:a{0,})*?)$-6 7.06µs ± 1% 7.06µs ± 1% ~ (p=0.912 n=10+10) CompileOnepass/^(?:(?:a+)*)$-6 6.40µs ± 1% 6.41µs ± 1% ~ (p=0.699 n=10+10) CompileOnepass/^(?:(?:a|(?:aa)))$-6 8.18µs ± 2% 8.16µs ± 1% ~ (p=0.529 n=10+10) CompileOnepass/^(?:[^\s\S])$-6 5.08µs ± 1% 5.17µs ± 1% +1.77% (p=0.000 n=9+10) CompileOnepass/^(?:(?:(?:a*)+))$-6 6.86µs ± 1% 6.85µs ± 0% ~ (p=0.190 n=10+9) CompileOnepass/^[a-c]+$-6 5.14µs ± 1% 5.11µs ± 0% -0.53% (p=0.041 n=10+10) CompileOnepass/^[a-c]*$-6 5.62µs ± 1% 5.63µs ± 1% ~ (p=0.382 n=10+10) CompileOnepass/^(?:a*)$-6 5.76µs ± 1% 5.73µs ± 1% -0.41% (p=0.008 n=9+10) CompileOnepass/^(?:(?:aa)|a)$-6 7.89µs ± 1% 7.84µs ± 1% -0.66% (p=0.020 n=10+10) CompileOnepass/^...$-6 5.38µs ± 1% 5.38µs ± 1% ~ (p=0.857 n=9+10) CompileOnepass/^(?:a|(?:aa))$-6 7.80µs ± 2% 7.82µs ± 1% ~ (p=0.342 n=10+10) CompileOnepass/^a((b))c$-6 7.75µs ± 1% 7.78µs ± 1% ~ (p=0.172 n=10+10) CompileOnepass/^a.[l-nA-Cg-j]?e$-6 8.39µs ± 1% 8.42µs ± 1% ~ (p=0.138 n=10+10) CompileOnepass/^a((b))$-6 6.92µs ± 1% 6.95µs ± 1% ~ (p=0.159 n=10+10) CompileOnepass/^a(?:(b)|(c))c$-6 10.0µs ± 1% 10.0µs ± 1% ~ (p=0.896 n=10+10) CompileOnepass/^a(?:b|c)$-6 5.62µs ± 1% 5.66µs ± 1% +0.71% (p=0.023 n=10+10) CompileOnepass/^a(?:b?|c)$-6 8.49µs ± 1% 8.43µs ± 1% -0.69% (p=0.010 n=10+10) CompileOnepass/^a(?:b?|c+)$-6 9.26µs ± 1% 9.28µs ± 1% ~ (p=0.448 n=10+10) CompileOnepass/^a(?:bc)+$-6 6.52µs ± 1% 6.46µs ± 2% -1.02% (p=0.003 n=10+10) CompileOnepass/^a(?:[bcd])+$-6 6.29µs ± 1% 6.32µs ± 1% ~ (p=0.256 n=10+10) CompileOnepass/^a((?:[bcd])+)$-6 7.77µs ± 1% 7.79µs ± 1% ~ (p=0.105 n=10+10) CompileOnepass/^a(:?b|c)*d$-6 14.0µs ± 1% 13.9µs ± 1% -0.69% (p=0.003 n=10+10) CompileOnepass/^.bc(d|e)*$-6 8.96µs ± 1% 9.06µs ± 1% +1.20% (p=0.000 n=10+9) CompileOnepass/^loooooooooooooooooo...-6 219µs ± 1% 220µs ± 1% +0.63% (p=0.006 n=9+10) [Geo mean] 31.6µs 31.1µs -1.82% name old speed new speed delta QuoteMetaAll-6 65.5MB/s ± 2% 64.8MB/s ± 3% ~ (p=0.315 n=10+10) QuoteMetaNone-6 290MB/s ± 1% 290MB/s ± 1% ~ (p=0.755 n=10+10) Match/Easy0/32-6 250MB/s ± 0% 251MB/s ± 1% ~ (p=0.277 n=8+9) Match/Easy0/1K-6 1.81GB/s ± 0% 1.81GB/s ± 0% ~ (p=0.408 n=8+10) Match/Easy0/32K-6 3.52GB/s ± 1% 3.53GB/s ± 1% ~ (p=0.529 n=10+10) Match/Easy0/1M-6 2.28GB/s ± 1% 2.28GB/s ± 1% ~ (p=0.853 n=10+10) Match/Easy0/32M-6 2.24GB/s ± 0% 2.23GB/s ± 0% -0.76% (p=0.000 n=9+8) Match/Easy0i/32-6 15.2MB/s ± 1% 16.2MB/s ± 0% +6.43% (p=0.000 n=10+9) Match/Easy0i/1K-6 16.6MB/s ± 0% 17.9MB/s ± 0% +7.48% (p=0.000 n=10+9) Match/Easy0i/32K-6 11.9MB/s ± 0% 12.0MB/s ± 0% +1.11% (p=0.000 n=9+9) Match/Easy0i/1M-6 11.9MB/s ± 0% 12.1MB/s ± 1% +1.31% (p=0.000 n=8+10) Match/Easy0i/32M-6 11.9MB/s ± 0% 12.1MB/s ± 1% +1.84% (p=0.000 n=8+10) Match/Easy1/32-6 260MB/s ± 1% 258MB/s ± 1% -0.91% (p=0.001 n=10+10) Match/Easy1/1K-6 601MB/s ± 1% 621MB/s ± 0% +3.28% (p=0.000 n=9+10) Match/Easy1/32K-6 474MB/s ± 0% 479MB/s ± 1% +0.96% (p=0.000 n=8+10) Match/Easy1/1M-6 426MB/s ± 1% 433MB/s ± 1% +1.68% (p=0.000 n=10+10) Match/Easy1/32M-6 428MB/s ± 1% 433MB/s ± 0% +1.09% (p=0.000 n=10+9) Match/Medium/32-6 15.4MB/s ± 1% 16.7MB/s ± 1% +8.23% (p=0.000 n=10+9) Match/Medium/1K-6 16.3MB/s ± 1% 17.7MB/s ± 1% +8.43% (p=0.000 n=9+10) Match/Medium/32K-6 12.5MB/s ± 1% 12.7MB/s ± 1% +2.15% (p=0.000 n=10+10) Match/Medium/1M-6 12.4MB/s ± 0% 12.7MB/s ± 0% +2.44% (p=0.000 n=8+9) Match/Medium/32M-6 12.4MB/s ± 0% 12.7MB/s ± 0% +2.52% (p=0.000 n=10+9) Match/Hard/32-6 9.82MB/s ± 1% 10.73MB/s ± 1% +9.29% (p=0.000 n=10+10) Match/Hard/1K-6 10.2MB/s ± 0% 11.3MB/s ± 1% +10.56% (p=0.000 n=9+10) Match/Hard/32K-6 8.58MB/s ± 0% 8.58MB/s ± 1% ~ (p=0.554 n=8+10) Match/Hard/1M-6 8.59MB/s ± 1% 8.53MB/s ± 0% -0.70% (p=0.000 n=10+8) Match/Hard/32M-6 8.62MB/s ± 1% 8.59MB/s ± 1% ~ (p=0.098 n=10+10) Match/Hard1/32-6 1.77MB/s ± 1% 1.99MB/s ± 1% +12.40% (p=0.000 n=10+8) Match/Hard1/1K-6 1.81MB/s ± 1% 2.08MB/s ± 1% +14.55% (p=0.000 n=10+10) Match/Hard1/32K-6 1.74MB/s ± 0% 1.74MB/s ± 0% ~ (p=0.108 n=9+10) Match/Hard1/1M-6 1.74MB/s ± 0% 1.74MB/s ± 1% ~ (p=1.000 n=9+10) Match/Hard1/32M-6 1.75MB/s ± 0% 1.75MB/s ± 1% ~ (p=0.157 n=9+10) Match_onepass_regex/32-6 5.05MB/s ± 0% 5.05MB/s ± 1% ~ (p=0.262 n=8+10) Match_onepass_regex/1K-6 5.02MB/s ± 1% 5.02MB/s ± 1% ~ (p=0.677 n=9+10) Match_onepass_regex/32K-6 5.02MB/s ± 0% 4.99MB/s ± 0% -0.47% (p=0.000 n=10+9) Match_onepass_regex/1M-6 5.01MB/s ± 0% 5.04MB/s ± 1% +0.68% (p=0.017 n=8+10) Match_onepass_regex/32M-6 4.99MB/s ± 0% 5.03MB/s ± 1% +0.74% (p=0.000 n=10+10) [Geo mean] 29.1MB/s 29.8MB/s +2.44% go1 data for reference name old time/op new time/op delta BinaryTree17-6 4.39s ± 1% 4.37s ± 0% -0.58% (p=0.006 n=9+9) Fannkuch11-6 5.13s ± 0% 5.18s ± 0% +0.87% (p=0.000 n=8+8) FmtFprintfEmpty-6 74.2ns ± 0% 71.7ns ± 3% -3.41% (p=0.000 n=10+10) FmtFprintfString-6 120ns ± 1% 122ns ± 2% ~ (p=0.333 n=10+10) FmtFprintfInt-6 127ns ± 1% 127ns ± 1% ~ (p=0.809 n=10+10) FmtFprintfIntInt-6 186ns ± 0% 188ns ± 1% +1.02% (p=0.002 n=8+10) FmtFprintfPrefixedInt-6 223ns ± 1% 222ns ± 2% ~ (p=0.421 n=10+10) FmtFprintfFloat-6 374ns ± 0% 376ns ± 1% +0.43% (p=0.030 n=8+10) FmtManyArgs-6 795ns ± 0% 788ns ± 1% -0.79% (p=0.000 n=8+9) GobDecode-6 10.9ms ± 1% 10.9ms ± 0% ~ (p=0.079 n=10+9) GobEncode-6 8.60ms ± 1% 8.56ms ± 0% -0.52% (p=0.004 n=10+10) Gzip-6 378ms ± 1% 386ms ± 1% +2.28% (p=0.000 n=10+10) Gunzip-6 63.7ms ± 0% 62.3ms ± 0% -2.22% (p=0.000 n=9+8) HTTPClientServer-6 120µs ± 3% 114µs ± 3% -4.99% (p=0.000 n=10+10) JSONEncode-6 20.3ms ± 1% 19.9ms ± 0% -1.90% (p=0.000 n=9+10) JSONDecode-6 84.3ms ± 0% 83.7ms ± 0% -0.76% (p=0.000 n=8+8) Mandelbrot200-6 6.91ms ± 0% 6.89ms ± 0% -0.31% (p=0.000 n=9+8) GoParse-6 5.49ms ± 0% 5.47ms ± 1% ~ (p=0.101 n=8+10) RegexpMatchEasy0_32-6 130ns ± 0% 128ns ± 0% -1.54% (p=0.002 n=8+10) RegexpMatchEasy0_1K-6 322ns ± 1% 322ns ± 0% ~ (p=0.525 n=10+9) RegexpMatchEasy1_32-6 124ns ± 0% 124ns ± 0% -0.32% (p=0.046 n=8+10) RegexpMatchEasy1_1K-6 570ns ± 0% 548ns ± 1% -3.76% (p=0.000 n=10+10) RegexpMatchMedium_32-6 196ns ± 0% 183ns ± 1% -6.61% (p=0.000 n=8+10) RegexpMatchMedium_1K-6 64.3µs ± 0% 59.0µs ± 1% -8.31% (p=0.000 n=8+10) RegexpMatchHard_32-6 3.08µs ± 0% 2.80µs ± 0% -8.96% (p=0.000 n=8+9) RegexpMatchHard_1K-6 93.0µs ± 0% 84.5µs ± 1% -9.17% (p=0.000 n=8+9) Revcomp-6 647ms ± 2% 646ms ± 1% ~ (p=0.720 n=10+9) Template-6 92.3ms ± 0% 91.7ms ± 0% -0.65% (p=0.000 n=8+8) TimeParse-6 490ns ± 0% 488ns ± 0% -0.43% (p=0.000 n=10+10) TimeFormat-6 513ns ± 0% 513ns ± 1% ~ (p=0.144 n=9+10) [Geo mean] 79.1µs 77.7µs -1.73% name old speed new speed delta GobDecode-6 70.1MB/s ± 1% 70.3MB/s ± 0% ~ (p=0.078 n=10+9) GobEncode-6 89.2MB/s ± 1% 89.7MB/s ± 0% +0.52% (p=0.004 n=10+10) Gzip-6 51.4MB/s ± 1% 50.2MB/s ± 1% -2.23% (p=0.000 n=10+10) Gunzip-6 304MB/s ± 0% 311MB/s ± 0% +2.27% (p=0.000 n=9+8) JSONEncode-6 95.8MB/s ± 1% 97.7MB/s ± 0% +1.93% (p=0.000 n=9+10) JSONDecode-6 23.0MB/s ± 0% 23.2MB/s ± 0% +0.76% (p=0.000 n=8+8) GoParse-6 10.6MB/s ± 0% 10.6MB/s ± 1% ~ (p=0.111 n=8+10) RegexpMatchEasy0_32-6 244MB/s ± 0% 249MB/s ± 0% +2.06% (p=0.000 n=9+10) RegexpMatchEasy0_1K-6 3.18GB/s ± 1% 3.17GB/s ± 0% ~ (p=0.211 n=10+9) RegexpMatchEasy1_32-6 257MB/s ± 0% 258MB/s ± 0% +0.37% (p=0.000 n=8+8) RegexpMatchEasy1_1K-6 1.80GB/s ± 0% 1.87GB/s ± 1% +3.91% (p=0.000 n=10+10) RegexpMatchMedium_32-6 5.08MB/s ± 0% 5.43MB/s ± 1% +7.03% (p=0.000 n=8+10) RegexpMatchMedium_1K-6 15.9MB/s ± 0% 17.4MB/s ± 1% +9.08% (p=0.000 n=8+10) RegexpMatchHard_32-6 10.4MB/s ± 0% 11.4MB/s ± 0% +9.82% (p=0.000 n=8+9) RegexpMatchHard_1K-6 11.0MB/s ± 0% 12.1MB/s ± 1% +10.10% (p=0.000 n=8+9) Revcomp-6 393MB/s ± 2% 394MB/s ± 1% ~ (p=0.720 n=10+9) Template-6 21.0MB/s ± 0% 21.2MB/s ± 0% +0.66% (p=0.000 n=8+8) [Geo mean] 74.2MB/s 76.2MB/s +2.70% Updates #21851 Change-Id: Ie88455db925f422a828f8528293790726a9c036b Reviewed-on: https://go-review.googlesource.com/65491 Run-TryBot: Ilya Tocar <ilya.tocar@intel.com> Reviewed-by: Daniel Martí <mvdan@mvdan.cc> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2017-09-22 15:15:23 -05:00
} else {
regexp: split bit-state execution out of machine struct This allows the bit-state executions to have their own pool of allocated structures. A step toward eliminating the per-Regexp machine cache. Note especially the -92% on MatchParallelShared. This is real but not a complete story: the other execution engines still need to be de-shared, but the benchmark was only using bit-state. The tiny slowdowns in unrelated code are noise. name old time/op new time/op delta Find-12 264ns ± 3% 254ns ± 0% -3.86% (p=0.000 n=10+9) FindAllNoMatches-12 140ns ± 2% 135ns ± 0% -3.91% (p=0.000 n=10+9) FindString-12 256ns ± 0% 247ns ± 0% -3.52% (p=0.000 n=8+8) FindSubmatch-12 339ns ± 1% 334ns ± 0% -1.41% (p=0.000 n=9+10) FindStringSubmatch-12 322ns ± 0% 321ns ± 0% -0.21% (p=0.005 n=8+9) Literal-12 100ns ± 2% 92ns ± 0% -8.10% (p=0.000 n=10+9) NotLiteral-12 1.50µs ± 0% 1.47µs ± 0% -1.91% (p=0.000 n=8+9) MatchClass-12 2.18µs ± 0% 2.17µs ± 0% -0.20% (p=0.001 n=10+7) MatchClass_InRange-12 2.12µs ± 0% 2.13µs ± 0% +0.23% (p=0.000 n=10+10) ReplaceAll-12 1.41µs ± 0% 1.39µs ± 0% -1.30% (p=0.000 n=7+10) AnchoredLiteralShortNonMatch-12 89.8ns ± 0% 83.2ns ± 0% -7.35% (p=0.000 n=8+8) AnchoredLiteralLongNonMatch-12 105ns ± 3% 105ns ± 0% ~ (p=0.186 n=10+10) AnchoredShortMatch-12 141ns ± 0% 131ns ± 0% -7.09% (p=0.000 n=9+10) AnchoredLongMatch-12 276ns ± 4% 267ns ± 0% -3.23% (p=0.000 n=10+10) OnePassShortA-12 620ns ± 0% 611ns ± 0% -1.39% (p=0.000 n=10+9) NotOnePassShortA-12 575ns ± 3% 552ns ± 0% -3.97% (p=0.000 n=10+8) OnePassShortB-12 493ns ± 0% 491ns ± 0% -0.33% (p=0.000 n=8+8) NotOnePassShortB-12 423ns ± 0% 412ns ± 0% -2.60% (p=0.000 n=8+9) OnePassLongPrefix-12 112ns ± 0% 112ns ± 0% ~ (all equal) OnePassLongNotPrefix-12 405ns ± 0% 410ns ± 0% +1.23% (p=0.000 n=8+9) MatchParallelShared-12 501ns ± 1% 39ns ± 1% -92.27% (p=0.000 n=10+10) MatchParallelCopied-12 39.1ns ± 0% 39.2ns ± 3% ~ (p=0.785 n=6+10) QuoteMetaAll-12 94.6ns ± 0% 94.6ns ± 0% ~ (p=0.439 n=10+8) QuoteMetaNone-12 52.7ns ± 0% 52.7ns ± 0% ~ (all equal) Match/Easy0/32-12 79.1ns ± 0% 72.9ns ± 0% -7.85% (p=0.000 n=9+9) Match/Easy0/1K-12 307ns ± 1% 298ns ± 0% -2.99% (p=0.000 n=10+6) Match/Easy0/32K-12 4.65µs ± 2% 4.60µs ± 2% ~ (p=0.159 n=10+10) Match/Easy0/1M-12 234µs ± 0% 235µs ± 0% +0.17% (p=0.003 n=10+10) Match/Easy0/32M-12 7.98ms ± 1% 7.96ms ± 0% ~ (p=0.278 n=9+10) Match/Easy0i/32-12 1.13µs ± 1% 1.09µs ± 0% -3.24% (p=0.000 n=9+8) Match/Easy0i/1K-12 32.5µs ± 0% 31.7µs ± 0% -2.66% (p=0.000 n=9+9) Match/Easy0i/32K-12 1.59ms ± 0% 1.61ms ± 0% +0.75% (p=0.000 n=9+9) Match/Easy0i/1M-12 51.0ms ± 0% 51.4ms ± 0% +0.77% (p=0.000 n=10+8) Match/Easy0i/32M-12 1.63s ± 0% 1.65s ± 1% +1.24% (p=0.000 n=7+9) Match/Easy1/32-12 75.1ns ± 1% 67.9ns ± 0% -9.54% (p=0.000 n=8+8) Match/Easy1/1K-12 861ns ± 0% 884ns ± 0% +2.71% (p=0.000 n=8+9) Match/Easy1/32K-12 39.2µs ± 1% 39.2µs ± 0% ~ (p=0.090 n=10+9) Match/Easy1/1M-12 1.38ms ± 0% 1.39ms ± 0% ~ (p=0.095 n=10+9) Match/Easy1/32M-12 44.2ms ± 1% 44.2ms ± 1% ~ (p=0.218 n=10+10) Match/Medium/32-12 1.04µs ± 1% 1.05µs ± 0% +1.05% (p=0.000 n=9+8) Match/Medium/1K-12 31.3µs ± 0% 31.3µs ± 0% -0.14% (p=0.004 n=9+9) Match/Medium/32K-12 1.44ms ± 0% 1.45ms ± 0% +0.18% (p=0.001 n=8+8) Match/Medium/1M-12 46.1ms ± 0% 46.2ms ± 0% +0.13% (p=0.003 n=6+9) Match/Medium/32M-12 1.48s ± 0% 1.48s ± 0% +0.20% (p=0.002 n=9+8) Match/Hard/32-12 1.54µs ± 1% 1.49µs ± 0% -3.60% (p=0.000 n=9+10) Match/Hard/1K-12 46.4µs ± 1% 45.1µs ± 1% -2.78% (p=0.000 n=9+10) Match/Hard/32K-12 2.19ms ± 0% 2.18ms ± 1% -0.51% (p=0.006 n=8+9) Match/Hard/1M-12 70.1ms ± 0% 69.7ms ± 1% -0.52% (p=0.006 n=8+9) Match/Hard/32M-12 2.24s ± 0% 2.23s ± 1% -0.42% (p=0.046 n=8+9) Match/Hard1/32-12 8.17µs ± 1% 7.89µs ± 0% -3.42% (p=0.000 n=8+9) Match/Hard1/1K-12 254µs ± 2% 244µs ± 0% -3.91% (p=0.000 n=9+9) Match/Hard1/32K-12 9.58ms ± 1% 10.35ms ± 0% +8.00% (p=0.000 n=10+10) Match/Hard1/1M-12 306ms ± 1% 331ms ± 0% +8.27% (p=0.000 n=9+8) Match/Hard1/32M-12 9.79s ± 1% 10.60s ± 0% +8.29% (p=0.000 n=9+8) Match_onepass_regex/32-12 808ns ± 0% 812ns ± 0% +0.47% (p=0.000 n=8+10) Match_onepass_regex/1K-12 27.8µs ± 0% 28.5µs ± 0% +2.32% (p=0.000 n=8+10) Match_onepass_regex/32K-12 925µs ± 0% 936µs ± 0% +1.24% (p=0.000 n=9+10) Match_onepass_regex/1M-12 29.5ms ± 0% 30.2ms ± 0% +2.38% (p=0.000 n=10+10) Match_onepass_regex/32M-12 945ms ± 0% 970ms ± 0% +2.60% (p=0.000 n=9+10) CompileOnepass-12 4.67µs ± 0% 4.63µs ± 1% -0.84% (p=0.000 n=10+10) [Geo mean] 24.5µs 23.3µs -5.04% https://perf.golang.org/search?q=upload:20181004.1 Change-Id: Idbc2b76223718265657819ff38be2d9aba1c54b4 Reviewed-on: https://go-review.googlesource.com/c/139779 Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-09-28 16:37:16 -04:00
b.push(re, pc, pos, true)
regexp: make (*bitState).push inlinable By refactoring job.arg from int with 0/1 as the only valid values into bool and simplifying (*bitState).push, we reduce the number of nodes below the inlining threshold. This improves backtracking regexp performance by 5-10% and go1 geomean by 1.7% Full performance data below: name old time/op new time/op delta Find-6 510ns ± 0% 480ns ± 1% -5.90% (p=0.000 n=10+10) FindString-6 504ns ± 1% 479ns ± 1% -5.10% (p=0.000 n=10+10) FindSubmatch-6 689ns ± 1% 659ns ± 1% -4.27% (p=0.000 n=9+10) FindStringSubmatch-6 659ns ± 0% 628ns ± 1% -4.69% (p=0.000 n=8+10) Literal-6 174ns ± 1% 171ns ± 1% -1.50% (p=0.000 n=10+10) NotLiteral-6 2.89µs ± 1% 2.72µs ± 0% -5.84% (p=0.000 n=10+9) MatchClass-6 4.65µs ± 1% 4.28µs ± 1% -7.96% (p=0.000 n=10+10) MatchClass_InRange-6 4.15µs ± 1% 3.80µs ± 0% -8.61% (p=0.000 n=10+8) ReplaceAll-6 2.72µs ± 1% 2.60µs ± 1% -4.68% (p=0.000 n=10+10) AnchoredLiteralShortNonMatch-6 158ns ± 1% 153ns ± 1% -3.03% (p=0.000 n=10+10) AnchoredLiteralLongNonMatch-6 176ns ± 1% 176ns ± 0% ~ (p=1.000 n=10+9) AnchoredShortMatch-6 260ns ± 0% 255ns ± 1% -1.84% (p=0.000 n=9+10) AnchoredLongMatch-6 456ns ± 0% 455ns ± 0% -0.19% (p=0.008 n=8+10) OnePassShortA-6 1.13µs ± 1% 1.12µs ± 0% -0.57% (p=0.046 n=10+8) NotOnePassShortA-6 1.14µs ± 1% 1.14µs ± 1% ~ (p=0.162 n=10+10) OnePassShortB-6 908ns ± 0% 893ns ± 0% -1.60% (p=0.000 n=8+9) NotOnePassShortB-6 857ns ± 0% 803ns ± 1% -6.34% (p=0.000 n=8+10) OnePassLongPrefix-6 190ns ± 0% 190ns ± 1% ~ (p=0.059 n=8+10) OnePassLongNotPrefix-6 722ns ± 1% 722ns ± 1% ~ (p=0.451 n=10+10) MatchParallelShared-6 810ns ± 2% 807ns ± 2% ~ (p=0.643 n=10+10) MatchParallelCopied-6 72.1ns ± 1% 69.4ns ± 1% -3.81% (p=0.000 n=10+10) QuoteMetaAll-6 213ns ± 2% 216ns ± 3% ~ (p=0.284 n=10+10) QuoteMetaNone-6 89.7ns ± 1% 89.8ns ± 1% ~ (p=0.616 n=10+10) Match/Easy0/32-6 127ns ± 1% 127ns ± 1% ~ (p=0.977 n=10+10) Match/Easy0/1K-6 566ns ± 0% 566ns ± 0% ~ (p=1.000 n=8+8) Match/Easy0/32K-6 9.30µs ± 1% 9.28µs ± 1% ~ (p=0.529 n=10+10) Match/Easy0/1M-6 460µs ± 1% 460µs ± 1% ~ (p=0.853 n=10+10) Match/Easy0/32M-6 15.0ms ± 0% 15.1ms ± 0% +0.77% (p=0.000 n=9+8) Match/Easy0i/32-6 2.10µs ± 1% 1.98µs ± 0% -6.02% (p=0.000 n=10+8) Match/Easy0i/1K-6 61.5µs ± 0% 57.2µs ± 0% -6.97% (p=0.000 n=10+9) Match/Easy0i/32K-6 2.75ms ± 0% 2.72ms ± 0% -1.10% (p=0.000 n=9+9) Match/Easy0i/1M-6 88.0ms ± 0% 86.9ms ± 1% -1.29% (p=0.000 n=8+10) Match/Easy0i/32M-6 2.82s ± 0% 2.77s ± 1% -1.81% (p=0.000 n=8+10) Match/Easy1/32-6 123ns ± 1% 124ns ± 1% +0.90% (p=0.001 n=10+10) Match/Easy1/1K-6 1.70µs ± 1% 1.65µs ± 0% -3.18% (p=0.000 n=9+10) Match/Easy1/32K-6 69.1µs ± 0% 68.4µs ± 1% -0.95% (p=0.000 n=8+10) Match/Easy1/1M-6 2.46ms ± 1% 2.42ms ± 1% -1.66% (p=0.000 n=10+10) Match/Easy1/32M-6 78.4ms ± 1% 77.5ms ± 0% -1.08% (p=0.000 n=10+9) Match/Medium/32-6 2.07µs ± 1% 1.91µs ± 1% -7.69% (p=0.000 n=10+10) Match/Medium/1K-6 62.8µs ± 0% 58.0µs ± 1% -7.70% (p=0.000 n=8+10) Match/Medium/32K-6 2.63ms ± 1% 2.58ms ± 1% -2.14% (p=0.000 n=10+10) Match/Medium/1M-6 84.6ms ± 0% 82.5ms ± 0% -2.37% (p=0.000 n=8+9) Match/Medium/32M-6 2.71s ± 0% 2.64s ± 0% -2.46% (p=0.000 n=10+9) Match/Hard/32-6 3.26µs ± 1% 2.98µs ± 1% -8.49% (p=0.000 n=10+10) Match/Hard/1K-6 100µs ± 0% 90µs ± 1% -9.55% (p=0.000 n=9+10) Match/Hard/32K-6 3.82ms ± 0% 3.82ms ± 1% ~ (p=0.515 n=8+10) Match/Hard/1M-6 122ms ± 1% 123ms ± 0% +0.66% (p=0.000 n=10+8) Match/Hard/32M-6 3.89s ± 1% 3.91s ± 1% ~ (p=0.105 n=10+10) Match/Hard1/32-6 18.1µs ± 1% 16.1µs ± 1% -11.31% (p=0.000 n=10+10) Match/Hard1/1K-6 565µs ± 0% 493µs ± 1% -12.65% (p=0.000 n=8+10) Match/Hard1/32K-6 18.8ms ± 0% 18.8ms ± 1% ~ (p=0.905 n=9+10) Match/Hard1/1M-6 602ms ± 1% 602ms ± 1% ~ (p=0.278 n=9+10) Match/Hard1/32M-6 19.1s ± 1% 19.2s ± 1% +0.31% (p=0.035 n=9+10) Match_onepass_regex/32-6 6.32µs ± 1% 6.34µs ± 1% ~ (p=0.060 n=10+10) Match_onepass_regex/1K-6 204µs ± 1% 204µs ± 1% ~ (p=0.842 n=9+10) Match_onepass_regex/32K-6 6.53ms ± 0% 6.55ms ± 1% +0.36% (p=0.005 n=10+10) Match_onepass_regex/1M-6 209ms ± 0% 208ms ± 1% -0.65% (p=0.034 n=8+10) Match_onepass_regex/32M-6 6.72s ± 0% 6.68s ± 1% -0.74% (p=0.000 n=9+10) CompileOnepass/^(?:(?:(?:.(?:$))?))...-6 7.02µs ± 1% 7.02µs ± 1% ~ (p=0.671 n=10+10) CompileOnepass/^abcd$-6 5.65µs ± 1% 5.65µs ± 1% ~ (p=0.411 n=10+9) CompileOnepass/^(?:(?:a{0,})*?)$-6 7.06µs ± 1% 7.06µs ± 1% ~ (p=0.912 n=10+10) CompileOnepass/^(?:(?:a+)*)$-6 6.40µs ± 1% 6.41µs ± 1% ~ (p=0.699 n=10+10) CompileOnepass/^(?:(?:a|(?:aa)))$-6 8.18µs ± 2% 8.16µs ± 1% ~ (p=0.529 n=10+10) CompileOnepass/^(?:[^\s\S])$-6 5.08µs ± 1% 5.17µs ± 1% +1.77% (p=0.000 n=9+10) CompileOnepass/^(?:(?:(?:a*)+))$-6 6.86µs ± 1% 6.85µs ± 0% ~ (p=0.190 n=10+9) CompileOnepass/^[a-c]+$-6 5.14µs ± 1% 5.11µs ± 0% -0.53% (p=0.041 n=10+10) CompileOnepass/^[a-c]*$-6 5.62µs ± 1% 5.63µs ± 1% ~ (p=0.382 n=10+10) CompileOnepass/^(?:a*)$-6 5.76µs ± 1% 5.73µs ± 1% -0.41% (p=0.008 n=9+10) CompileOnepass/^(?:(?:aa)|a)$-6 7.89µs ± 1% 7.84µs ± 1% -0.66% (p=0.020 n=10+10) CompileOnepass/^...$-6 5.38µs ± 1% 5.38µs ± 1% ~ (p=0.857 n=9+10) CompileOnepass/^(?:a|(?:aa))$-6 7.80µs ± 2% 7.82µs ± 1% ~ (p=0.342 n=10+10) CompileOnepass/^a((b))c$-6 7.75µs ± 1% 7.78µs ± 1% ~ (p=0.172 n=10+10) CompileOnepass/^a.[l-nA-Cg-j]?e$-6 8.39µs ± 1% 8.42µs ± 1% ~ (p=0.138 n=10+10) CompileOnepass/^a((b))$-6 6.92µs ± 1% 6.95µs ± 1% ~ (p=0.159 n=10+10) CompileOnepass/^a(?:(b)|(c))c$-6 10.0µs ± 1% 10.0µs ± 1% ~ (p=0.896 n=10+10) CompileOnepass/^a(?:b|c)$-6 5.62µs ± 1% 5.66µs ± 1% +0.71% (p=0.023 n=10+10) CompileOnepass/^a(?:b?|c)$-6 8.49µs ± 1% 8.43µs ± 1% -0.69% (p=0.010 n=10+10) CompileOnepass/^a(?:b?|c+)$-6 9.26µs ± 1% 9.28µs ± 1% ~ (p=0.448 n=10+10) CompileOnepass/^a(?:bc)+$-6 6.52µs ± 1% 6.46µs ± 2% -1.02% (p=0.003 n=10+10) CompileOnepass/^a(?:[bcd])+$-6 6.29µs ± 1% 6.32µs ± 1% ~ (p=0.256 n=10+10) CompileOnepass/^a((?:[bcd])+)$-6 7.77µs ± 1% 7.79µs ± 1% ~ (p=0.105 n=10+10) CompileOnepass/^a(:?b|c)*d$-6 14.0µs ± 1% 13.9µs ± 1% -0.69% (p=0.003 n=10+10) CompileOnepass/^.bc(d|e)*$-6 8.96µs ± 1% 9.06µs ± 1% +1.20% (p=0.000 n=10+9) CompileOnepass/^loooooooooooooooooo...-6 219µs ± 1% 220µs ± 1% +0.63% (p=0.006 n=9+10) [Geo mean] 31.6µs 31.1µs -1.82% name old speed new speed delta QuoteMetaAll-6 65.5MB/s ± 2% 64.8MB/s ± 3% ~ (p=0.315 n=10+10) QuoteMetaNone-6 290MB/s ± 1% 290MB/s ± 1% ~ (p=0.755 n=10+10) Match/Easy0/32-6 250MB/s ± 0% 251MB/s ± 1% ~ (p=0.277 n=8+9) Match/Easy0/1K-6 1.81GB/s ± 0% 1.81GB/s ± 0% ~ (p=0.408 n=8+10) Match/Easy0/32K-6 3.52GB/s ± 1% 3.53GB/s ± 1% ~ (p=0.529 n=10+10) Match/Easy0/1M-6 2.28GB/s ± 1% 2.28GB/s ± 1% ~ (p=0.853 n=10+10) Match/Easy0/32M-6 2.24GB/s ± 0% 2.23GB/s ± 0% -0.76% (p=0.000 n=9+8) Match/Easy0i/32-6 15.2MB/s ± 1% 16.2MB/s ± 0% +6.43% (p=0.000 n=10+9) Match/Easy0i/1K-6 16.6MB/s ± 0% 17.9MB/s ± 0% +7.48% (p=0.000 n=10+9) Match/Easy0i/32K-6 11.9MB/s ± 0% 12.0MB/s ± 0% +1.11% (p=0.000 n=9+9) Match/Easy0i/1M-6 11.9MB/s ± 0% 12.1MB/s ± 1% +1.31% (p=0.000 n=8+10) Match/Easy0i/32M-6 11.9MB/s ± 0% 12.1MB/s ± 1% +1.84% (p=0.000 n=8+10) Match/Easy1/32-6 260MB/s ± 1% 258MB/s ± 1% -0.91% (p=0.001 n=10+10) Match/Easy1/1K-6 601MB/s ± 1% 621MB/s ± 0% +3.28% (p=0.000 n=9+10) Match/Easy1/32K-6 474MB/s ± 0% 479MB/s ± 1% +0.96% (p=0.000 n=8+10) Match/Easy1/1M-6 426MB/s ± 1% 433MB/s ± 1% +1.68% (p=0.000 n=10+10) Match/Easy1/32M-6 428MB/s ± 1% 433MB/s ± 0% +1.09% (p=0.000 n=10+9) Match/Medium/32-6 15.4MB/s ± 1% 16.7MB/s ± 1% +8.23% (p=0.000 n=10+9) Match/Medium/1K-6 16.3MB/s ± 1% 17.7MB/s ± 1% +8.43% (p=0.000 n=9+10) Match/Medium/32K-6 12.5MB/s ± 1% 12.7MB/s ± 1% +2.15% (p=0.000 n=10+10) Match/Medium/1M-6 12.4MB/s ± 0% 12.7MB/s ± 0% +2.44% (p=0.000 n=8+9) Match/Medium/32M-6 12.4MB/s ± 0% 12.7MB/s ± 0% +2.52% (p=0.000 n=10+9) Match/Hard/32-6 9.82MB/s ± 1% 10.73MB/s ± 1% +9.29% (p=0.000 n=10+10) Match/Hard/1K-6 10.2MB/s ± 0% 11.3MB/s ± 1% +10.56% (p=0.000 n=9+10) Match/Hard/32K-6 8.58MB/s ± 0% 8.58MB/s ± 1% ~ (p=0.554 n=8+10) Match/Hard/1M-6 8.59MB/s ± 1% 8.53MB/s ± 0% -0.70% (p=0.000 n=10+8) Match/Hard/32M-6 8.62MB/s ± 1% 8.59MB/s ± 1% ~ (p=0.098 n=10+10) Match/Hard1/32-6 1.77MB/s ± 1% 1.99MB/s ± 1% +12.40% (p=0.000 n=10+8) Match/Hard1/1K-6 1.81MB/s ± 1% 2.08MB/s ± 1% +14.55% (p=0.000 n=10+10) Match/Hard1/32K-6 1.74MB/s ± 0% 1.74MB/s ± 0% ~ (p=0.108 n=9+10) Match/Hard1/1M-6 1.74MB/s ± 0% 1.74MB/s ± 1% ~ (p=1.000 n=9+10) Match/Hard1/32M-6 1.75MB/s ± 0% 1.75MB/s ± 1% ~ (p=0.157 n=9+10) Match_onepass_regex/32-6 5.05MB/s ± 0% 5.05MB/s ± 1% ~ (p=0.262 n=8+10) Match_onepass_regex/1K-6 5.02MB/s ± 1% 5.02MB/s ± 1% ~ (p=0.677 n=9+10) Match_onepass_regex/32K-6 5.02MB/s ± 0% 4.99MB/s ± 0% -0.47% (p=0.000 n=10+9) Match_onepass_regex/1M-6 5.01MB/s ± 0% 5.04MB/s ± 1% +0.68% (p=0.017 n=8+10) Match_onepass_regex/32M-6 4.99MB/s ± 0% 5.03MB/s ± 1% +0.74% (p=0.000 n=10+10) [Geo mean] 29.1MB/s 29.8MB/s +2.44% go1 data for reference name old time/op new time/op delta BinaryTree17-6 4.39s ± 1% 4.37s ± 0% -0.58% (p=0.006 n=9+9) Fannkuch11-6 5.13s ± 0% 5.18s ± 0% +0.87% (p=0.000 n=8+8) FmtFprintfEmpty-6 74.2ns ± 0% 71.7ns ± 3% -3.41% (p=0.000 n=10+10) FmtFprintfString-6 120ns ± 1% 122ns ± 2% ~ (p=0.333 n=10+10) FmtFprintfInt-6 127ns ± 1% 127ns ± 1% ~ (p=0.809 n=10+10) FmtFprintfIntInt-6 186ns ± 0% 188ns ± 1% +1.02% (p=0.002 n=8+10) FmtFprintfPrefixedInt-6 223ns ± 1% 222ns ± 2% ~ (p=0.421 n=10+10) FmtFprintfFloat-6 374ns ± 0% 376ns ± 1% +0.43% (p=0.030 n=8+10) FmtManyArgs-6 795ns ± 0% 788ns ± 1% -0.79% (p=0.000 n=8+9) GobDecode-6 10.9ms ± 1% 10.9ms ± 0% ~ (p=0.079 n=10+9) GobEncode-6 8.60ms ± 1% 8.56ms ± 0% -0.52% (p=0.004 n=10+10) Gzip-6 378ms ± 1% 386ms ± 1% +2.28% (p=0.000 n=10+10) Gunzip-6 63.7ms ± 0% 62.3ms ± 0% -2.22% (p=0.000 n=9+8) HTTPClientServer-6 120µs ± 3% 114µs ± 3% -4.99% (p=0.000 n=10+10) JSONEncode-6 20.3ms ± 1% 19.9ms ± 0% -1.90% (p=0.000 n=9+10) JSONDecode-6 84.3ms ± 0% 83.7ms ± 0% -0.76% (p=0.000 n=8+8) Mandelbrot200-6 6.91ms ± 0% 6.89ms ± 0% -0.31% (p=0.000 n=9+8) GoParse-6 5.49ms ± 0% 5.47ms ± 1% ~ (p=0.101 n=8+10) RegexpMatchEasy0_32-6 130ns ± 0% 128ns ± 0% -1.54% (p=0.002 n=8+10) RegexpMatchEasy0_1K-6 322ns ± 1% 322ns ± 0% ~ (p=0.525 n=10+9) RegexpMatchEasy1_32-6 124ns ± 0% 124ns ± 0% -0.32% (p=0.046 n=8+10) RegexpMatchEasy1_1K-6 570ns ± 0% 548ns ± 1% -3.76% (p=0.000 n=10+10) RegexpMatchMedium_32-6 196ns ± 0% 183ns ± 1% -6.61% (p=0.000 n=8+10) RegexpMatchMedium_1K-6 64.3µs ± 0% 59.0µs ± 1% -8.31% (p=0.000 n=8+10) RegexpMatchHard_32-6 3.08µs ± 0% 2.80µs ± 0% -8.96% (p=0.000 n=8+9) RegexpMatchHard_1K-6 93.0µs ± 0% 84.5µs ± 1% -9.17% (p=0.000 n=8+9) Revcomp-6 647ms ± 2% 646ms ± 1% ~ (p=0.720 n=10+9) Template-6 92.3ms ± 0% 91.7ms ± 0% -0.65% (p=0.000 n=8+8) TimeParse-6 490ns ± 0% 488ns ± 0% -0.43% (p=0.000 n=10+10) TimeFormat-6 513ns ± 0% 513ns ± 1% ~ (p=0.144 n=9+10) [Geo mean] 79.1µs 77.7µs -1.73% name old speed new speed delta GobDecode-6 70.1MB/s ± 1% 70.3MB/s ± 0% ~ (p=0.078 n=10+9) GobEncode-6 89.2MB/s ± 1% 89.7MB/s ± 0% +0.52% (p=0.004 n=10+10) Gzip-6 51.4MB/s ± 1% 50.2MB/s ± 1% -2.23% (p=0.000 n=10+10) Gunzip-6 304MB/s ± 0% 311MB/s ± 0% +2.27% (p=0.000 n=9+8) JSONEncode-6 95.8MB/s ± 1% 97.7MB/s ± 0% +1.93% (p=0.000 n=9+10) JSONDecode-6 23.0MB/s ± 0% 23.2MB/s ± 0% +0.76% (p=0.000 n=8+8) GoParse-6 10.6MB/s ± 0% 10.6MB/s ± 1% ~ (p=0.111 n=8+10) RegexpMatchEasy0_32-6 244MB/s ± 0% 249MB/s ± 0% +2.06% (p=0.000 n=9+10) RegexpMatchEasy0_1K-6 3.18GB/s ± 1% 3.17GB/s ± 0% ~ (p=0.211 n=10+9) RegexpMatchEasy1_32-6 257MB/s ± 0% 258MB/s ± 0% +0.37% (p=0.000 n=8+8) RegexpMatchEasy1_1K-6 1.80GB/s ± 0% 1.87GB/s ± 1% +3.91% (p=0.000 n=10+10) RegexpMatchMedium_32-6 5.08MB/s ± 0% 5.43MB/s ± 1% +7.03% (p=0.000 n=8+10) RegexpMatchMedium_1K-6 15.9MB/s ± 0% 17.4MB/s ± 1% +9.08% (p=0.000 n=8+10) RegexpMatchHard_32-6 10.4MB/s ± 0% 11.4MB/s ± 0% +9.82% (p=0.000 n=8+9) RegexpMatchHard_1K-6 11.0MB/s ± 0% 12.1MB/s ± 1% +10.10% (p=0.000 n=8+9) Revcomp-6 393MB/s ± 2% 394MB/s ± 1% ~ (p=0.720 n=10+9) Template-6 21.0MB/s ± 0% 21.2MB/s ± 0% +0.66% (p=0.000 n=8+8) [Geo mean] 74.2MB/s 76.2MB/s +2.70% Updates #21851 Change-Id: Ie88455db925f422a828f8528293790726a9c036b Reviewed-on: https://go-review.googlesource.com/65491 Run-TryBot: Ilya Tocar <ilya.tocar@intel.com> Reviewed-by: Daniel Martí <mvdan@mvdan.cc> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2017-09-22 15:15:23 -05:00
pc = inst.Out
goto CheckAndLoop
regexp: port RE2's bitstate backtracker to the regexp package This is a port of RE2's bitstate backtracker, which triggers under the same conditions that the RE2 backtracker triggers. However I wasn't sure how to port over some of the optimizations in the RE2 backtracker, and there is a ~2% penalty on benchmarks that don't trigger the backtracker. benchmark old ns/op new ns/op delta BenchmarkLiteral 312 189 -39.42% BenchmarkNotLiteral 4435 3001 -32.33% BenchmarkMatchClass 5758 4378 -23.97% BenchmarkMatchClass_InRange 5385 4084 -24.16% BenchmarkReplaceAll 5291 3505 -33.76% BenchmarkAnchoredLiteralShortNonMatch 190 200 +5.26% BenchmarkAnchoredLiteralLongNonMatch 189 194 +2.65% BenchmarkAnchoredShortMatch 479 304 -36.53% BenchmarkAnchoredLongMatch 478 499 +4.39% BenchmarkOnePassShortA 791 798 +0.88% BenchmarkNotOnePassShortA 3202 1571 -50.94% BenchmarkOnePassShortB 614 633 +3.09% BenchmarkNotOnePassShortB 2685 881 -67.19% BenchmarkOnePassLongPrefix 152 154 +1.32% BenchmarkOnePassLongNotPrefix 505 533 +5.54% BenchmarkMatchEasy0_32 139 171 +23.02% BenchmarkMatchEasy0_1K 653 1797 +175.19% BenchmarkMatchEasy0_32K 12032 13346 +10.92% BenchmarkMatchEasy0_1M 462882 461272 -0.35% BenchmarkMatchEasy0_32M 15015339 15365238 +2.33% BenchmarkMatchEasy1_32 122 168 +37.70% BenchmarkMatchEasy1_1K 3339 2612 -21.77% BenchmarkMatchEasy1_32K 72330 71721 -0.84% BenchmarkMatchEasy1_1M 2545410 2652284 +4.20% BenchmarkMatchEasy1_32M 80072063 82609750 +3.17% BenchmarkMatchMedium_32 2359 1980 -16.07% BenchmarkMatchMedium_1K 75939 58593 -22.84% BenchmarkMatchMedium_32K 2450907 2501106 +2.05% BenchmarkMatchMedium_1M 78707697 80174418 +1.86% BenchmarkMatchMedium_32M 2535146010 2570896441 +1.41% BenchmarkMatchHard_32 4297 2960 -31.11% BenchmarkMatchHard_1K 133592 88997 -33.38% BenchmarkMatchHard_32K 4240445 4336907 +2.27% BenchmarkMatchHard_1M 136187006 139350238 +2.32% BenchmarkMatchHard_32M 4350855890 4478537306 +2.93% benchmark old MB/s new MB/s speedup BenchmarkMatchEasy0_32 228.74 186.11 0.81x BenchmarkMatchEasy0_1K 1565.91 569.64 0.36x BenchmarkMatchEasy0_32K 2723.31 2455.10 0.90x BenchmarkMatchEasy0_1M 2265.32 2273.22 1.00x BenchmarkMatchEasy0_32M 2234.68 2183.79 0.98x BenchmarkMatchEasy1_32 261.08 190.22 0.73x BenchmarkMatchEasy1_1K 306.59 391.91 1.28x BenchmarkMatchEasy1_32K 453.03 456.88 1.01x BenchmarkMatchEasy1_1M 411.95 395.35 0.96x BenchmarkMatchEasy1_32M 419.05 406.18 0.97x BenchmarkMatchMedium_32 13.56 16.16 1.19x BenchmarkMatchMedium_1K 13.48 17.48 1.30x BenchmarkMatchMedium_32K 13.37 13.10 0.98x BenchmarkMatchMedium_1M 13.32 13.08 0.98x BenchmarkMatchMedium_32M 13.24 13.05 0.99x BenchmarkMatchHard_32 7.45 10.81 1.45x BenchmarkMatchHard_1K 7.67 11.51 1.50x BenchmarkMatchHard_32K 7.73 7.56 0.98x BenchmarkMatchHard_1M 7.70 7.52 0.98x BenchmarkMatchHard_32M 7.71 7.49 0.97x Fixes #4154 Change-Id: Iff7fb9507f0872b320d08afc08679751ed1b28bc Reviewed-on: https://go-review.googlesource.com/2153 Reviewed-by: Russ Cox <rsc@golang.org>
2014-12-28 00:17:01 -08:00
}
case syntax.InstAltMatch:
// One opcode consumes runes; the other leads to match.
regexp: split bit-state execution out of machine struct This allows the bit-state executions to have their own pool of allocated structures. A step toward eliminating the per-Regexp machine cache. Note especially the -92% on MatchParallelShared. This is real but not a complete story: the other execution engines still need to be de-shared, but the benchmark was only using bit-state. The tiny slowdowns in unrelated code are noise. name old time/op new time/op delta Find-12 264ns ± 3% 254ns ± 0% -3.86% (p=0.000 n=10+9) FindAllNoMatches-12 140ns ± 2% 135ns ± 0% -3.91% (p=0.000 n=10+9) FindString-12 256ns ± 0% 247ns ± 0% -3.52% (p=0.000 n=8+8) FindSubmatch-12 339ns ± 1% 334ns ± 0% -1.41% (p=0.000 n=9+10) FindStringSubmatch-12 322ns ± 0% 321ns ± 0% -0.21% (p=0.005 n=8+9) Literal-12 100ns ± 2% 92ns ± 0% -8.10% (p=0.000 n=10+9) NotLiteral-12 1.50µs ± 0% 1.47µs ± 0% -1.91% (p=0.000 n=8+9) MatchClass-12 2.18µs ± 0% 2.17µs ± 0% -0.20% (p=0.001 n=10+7) MatchClass_InRange-12 2.12µs ± 0% 2.13µs ± 0% +0.23% (p=0.000 n=10+10) ReplaceAll-12 1.41µs ± 0% 1.39µs ± 0% -1.30% (p=0.000 n=7+10) AnchoredLiteralShortNonMatch-12 89.8ns ± 0% 83.2ns ± 0% -7.35% (p=0.000 n=8+8) AnchoredLiteralLongNonMatch-12 105ns ± 3% 105ns ± 0% ~ (p=0.186 n=10+10) AnchoredShortMatch-12 141ns ± 0% 131ns ± 0% -7.09% (p=0.000 n=9+10) AnchoredLongMatch-12 276ns ± 4% 267ns ± 0% -3.23% (p=0.000 n=10+10) OnePassShortA-12 620ns ± 0% 611ns ± 0% -1.39% (p=0.000 n=10+9) NotOnePassShortA-12 575ns ± 3% 552ns ± 0% -3.97% (p=0.000 n=10+8) OnePassShortB-12 493ns ± 0% 491ns ± 0% -0.33% (p=0.000 n=8+8) NotOnePassShortB-12 423ns ± 0% 412ns ± 0% -2.60% (p=0.000 n=8+9) OnePassLongPrefix-12 112ns ± 0% 112ns ± 0% ~ (all equal) OnePassLongNotPrefix-12 405ns ± 0% 410ns ± 0% +1.23% (p=0.000 n=8+9) MatchParallelShared-12 501ns ± 1% 39ns ± 1% -92.27% (p=0.000 n=10+10) MatchParallelCopied-12 39.1ns ± 0% 39.2ns ± 3% ~ (p=0.785 n=6+10) QuoteMetaAll-12 94.6ns ± 0% 94.6ns ± 0% ~ (p=0.439 n=10+8) QuoteMetaNone-12 52.7ns ± 0% 52.7ns ± 0% ~ (all equal) Match/Easy0/32-12 79.1ns ± 0% 72.9ns ± 0% -7.85% (p=0.000 n=9+9) Match/Easy0/1K-12 307ns ± 1% 298ns ± 0% -2.99% (p=0.000 n=10+6) Match/Easy0/32K-12 4.65µs ± 2% 4.60µs ± 2% ~ (p=0.159 n=10+10) Match/Easy0/1M-12 234µs ± 0% 235µs ± 0% +0.17% (p=0.003 n=10+10) Match/Easy0/32M-12 7.98ms ± 1% 7.96ms ± 0% ~ (p=0.278 n=9+10) Match/Easy0i/32-12 1.13µs ± 1% 1.09µs ± 0% -3.24% (p=0.000 n=9+8) Match/Easy0i/1K-12 32.5µs ± 0% 31.7µs ± 0% -2.66% (p=0.000 n=9+9) Match/Easy0i/32K-12 1.59ms ± 0% 1.61ms ± 0% +0.75% (p=0.000 n=9+9) Match/Easy0i/1M-12 51.0ms ± 0% 51.4ms ± 0% +0.77% (p=0.000 n=10+8) Match/Easy0i/32M-12 1.63s ± 0% 1.65s ± 1% +1.24% (p=0.000 n=7+9) Match/Easy1/32-12 75.1ns ± 1% 67.9ns ± 0% -9.54% (p=0.000 n=8+8) Match/Easy1/1K-12 861ns ± 0% 884ns ± 0% +2.71% (p=0.000 n=8+9) Match/Easy1/32K-12 39.2µs ± 1% 39.2µs ± 0% ~ (p=0.090 n=10+9) Match/Easy1/1M-12 1.38ms ± 0% 1.39ms ± 0% ~ (p=0.095 n=10+9) Match/Easy1/32M-12 44.2ms ± 1% 44.2ms ± 1% ~ (p=0.218 n=10+10) Match/Medium/32-12 1.04µs ± 1% 1.05µs ± 0% +1.05% (p=0.000 n=9+8) Match/Medium/1K-12 31.3µs ± 0% 31.3µs ± 0% -0.14% (p=0.004 n=9+9) Match/Medium/32K-12 1.44ms ± 0% 1.45ms ± 0% +0.18% (p=0.001 n=8+8) Match/Medium/1M-12 46.1ms ± 0% 46.2ms ± 0% +0.13% (p=0.003 n=6+9) Match/Medium/32M-12 1.48s ± 0% 1.48s ± 0% +0.20% (p=0.002 n=9+8) Match/Hard/32-12 1.54µs ± 1% 1.49µs ± 0% -3.60% (p=0.000 n=9+10) Match/Hard/1K-12 46.4µs ± 1% 45.1µs ± 1% -2.78% (p=0.000 n=9+10) Match/Hard/32K-12 2.19ms ± 0% 2.18ms ± 1% -0.51% (p=0.006 n=8+9) Match/Hard/1M-12 70.1ms ± 0% 69.7ms ± 1% -0.52% (p=0.006 n=8+9) Match/Hard/32M-12 2.24s ± 0% 2.23s ± 1% -0.42% (p=0.046 n=8+9) Match/Hard1/32-12 8.17µs ± 1% 7.89µs ± 0% -3.42% (p=0.000 n=8+9) Match/Hard1/1K-12 254µs ± 2% 244µs ± 0% -3.91% (p=0.000 n=9+9) Match/Hard1/32K-12 9.58ms ± 1% 10.35ms ± 0% +8.00% (p=0.000 n=10+10) Match/Hard1/1M-12 306ms ± 1% 331ms ± 0% +8.27% (p=0.000 n=9+8) Match/Hard1/32M-12 9.79s ± 1% 10.60s ± 0% +8.29% (p=0.000 n=9+8) Match_onepass_regex/32-12 808ns ± 0% 812ns ± 0% +0.47% (p=0.000 n=8+10) Match_onepass_regex/1K-12 27.8µs ± 0% 28.5µs ± 0% +2.32% (p=0.000 n=8+10) Match_onepass_regex/32K-12 925µs ± 0% 936µs ± 0% +1.24% (p=0.000 n=9+10) Match_onepass_regex/1M-12 29.5ms ± 0% 30.2ms ± 0% +2.38% (p=0.000 n=10+10) Match_onepass_regex/32M-12 945ms ± 0% 970ms ± 0% +2.60% (p=0.000 n=9+10) CompileOnepass-12 4.67µs ± 0% 4.63µs ± 1% -0.84% (p=0.000 n=10+10) [Geo mean] 24.5µs 23.3µs -5.04% https://perf.golang.org/search?q=upload:20181004.1 Change-Id: Idbc2b76223718265657819ff38be2d9aba1c54b4 Reviewed-on: https://go-review.googlesource.com/c/139779 Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-09-28 16:37:16 -04:00
switch re.prog.Inst[inst.Out].Op {
regexp: port RE2's bitstate backtracker to the regexp package This is a port of RE2's bitstate backtracker, which triggers under the same conditions that the RE2 backtracker triggers. However I wasn't sure how to port over some of the optimizations in the RE2 backtracker, and there is a ~2% penalty on benchmarks that don't trigger the backtracker. benchmark old ns/op new ns/op delta BenchmarkLiteral 312 189 -39.42% BenchmarkNotLiteral 4435 3001 -32.33% BenchmarkMatchClass 5758 4378 -23.97% BenchmarkMatchClass_InRange 5385 4084 -24.16% BenchmarkReplaceAll 5291 3505 -33.76% BenchmarkAnchoredLiteralShortNonMatch 190 200 +5.26% BenchmarkAnchoredLiteralLongNonMatch 189 194 +2.65% BenchmarkAnchoredShortMatch 479 304 -36.53% BenchmarkAnchoredLongMatch 478 499 +4.39% BenchmarkOnePassShortA 791 798 +0.88% BenchmarkNotOnePassShortA 3202 1571 -50.94% BenchmarkOnePassShortB 614 633 +3.09% BenchmarkNotOnePassShortB 2685 881 -67.19% BenchmarkOnePassLongPrefix 152 154 +1.32% BenchmarkOnePassLongNotPrefix 505 533 +5.54% BenchmarkMatchEasy0_32 139 171 +23.02% BenchmarkMatchEasy0_1K 653 1797 +175.19% BenchmarkMatchEasy0_32K 12032 13346 +10.92% BenchmarkMatchEasy0_1M 462882 461272 -0.35% BenchmarkMatchEasy0_32M 15015339 15365238 +2.33% BenchmarkMatchEasy1_32 122 168 +37.70% BenchmarkMatchEasy1_1K 3339 2612 -21.77% BenchmarkMatchEasy1_32K 72330 71721 -0.84% BenchmarkMatchEasy1_1M 2545410 2652284 +4.20% BenchmarkMatchEasy1_32M 80072063 82609750 +3.17% BenchmarkMatchMedium_32 2359 1980 -16.07% BenchmarkMatchMedium_1K 75939 58593 -22.84% BenchmarkMatchMedium_32K 2450907 2501106 +2.05% BenchmarkMatchMedium_1M 78707697 80174418 +1.86% BenchmarkMatchMedium_32M 2535146010 2570896441 +1.41% BenchmarkMatchHard_32 4297 2960 -31.11% BenchmarkMatchHard_1K 133592 88997 -33.38% BenchmarkMatchHard_32K 4240445 4336907 +2.27% BenchmarkMatchHard_1M 136187006 139350238 +2.32% BenchmarkMatchHard_32M 4350855890 4478537306 +2.93% benchmark old MB/s new MB/s speedup BenchmarkMatchEasy0_32 228.74 186.11 0.81x BenchmarkMatchEasy0_1K 1565.91 569.64 0.36x BenchmarkMatchEasy0_32K 2723.31 2455.10 0.90x BenchmarkMatchEasy0_1M 2265.32 2273.22 1.00x BenchmarkMatchEasy0_32M 2234.68 2183.79 0.98x BenchmarkMatchEasy1_32 261.08 190.22 0.73x BenchmarkMatchEasy1_1K 306.59 391.91 1.28x BenchmarkMatchEasy1_32K 453.03 456.88 1.01x BenchmarkMatchEasy1_1M 411.95 395.35 0.96x BenchmarkMatchEasy1_32M 419.05 406.18 0.97x BenchmarkMatchMedium_32 13.56 16.16 1.19x BenchmarkMatchMedium_1K 13.48 17.48 1.30x BenchmarkMatchMedium_32K 13.37 13.10 0.98x BenchmarkMatchMedium_1M 13.32 13.08 0.98x BenchmarkMatchMedium_32M 13.24 13.05 0.99x BenchmarkMatchHard_32 7.45 10.81 1.45x BenchmarkMatchHard_1K 7.67 11.51 1.50x BenchmarkMatchHard_32K 7.73 7.56 0.98x BenchmarkMatchHard_1M 7.70 7.52 0.98x BenchmarkMatchHard_32M 7.71 7.49 0.97x Fixes #4154 Change-Id: Iff7fb9507f0872b320d08afc08679751ed1b28bc Reviewed-on: https://go-review.googlesource.com/2153 Reviewed-by: Russ Cox <rsc@golang.org>
2014-12-28 00:17:01 -08:00
case syntax.InstRune, syntax.InstRune1, syntax.InstRuneAny, syntax.InstRuneAnyNotNL:
// inst.Arg is the match.
regexp: split bit-state execution out of machine struct This allows the bit-state executions to have their own pool of allocated structures. A step toward eliminating the per-Regexp machine cache. Note especially the -92% on MatchParallelShared. This is real but not a complete story: the other execution engines still need to be de-shared, but the benchmark was only using bit-state. The tiny slowdowns in unrelated code are noise. name old time/op new time/op delta Find-12 264ns ± 3% 254ns ± 0% -3.86% (p=0.000 n=10+9) FindAllNoMatches-12 140ns ± 2% 135ns ± 0% -3.91% (p=0.000 n=10+9) FindString-12 256ns ± 0% 247ns ± 0% -3.52% (p=0.000 n=8+8) FindSubmatch-12 339ns ± 1% 334ns ± 0% -1.41% (p=0.000 n=9+10) FindStringSubmatch-12 322ns ± 0% 321ns ± 0% -0.21% (p=0.005 n=8+9) Literal-12 100ns ± 2% 92ns ± 0% -8.10% (p=0.000 n=10+9) NotLiteral-12 1.50µs ± 0% 1.47µs ± 0% -1.91% (p=0.000 n=8+9) MatchClass-12 2.18µs ± 0% 2.17µs ± 0% -0.20% (p=0.001 n=10+7) MatchClass_InRange-12 2.12µs ± 0% 2.13µs ± 0% +0.23% (p=0.000 n=10+10) ReplaceAll-12 1.41µs ± 0% 1.39µs ± 0% -1.30% (p=0.000 n=7+10) AnchoredLiteralShortNonMatch-12 89.8ns ± 0% 83.2ns ± 0% -7.35% (p=0.000 n=8+8) AnchoredLiteralLongNonMatch-12 105ns ± 3% 105ns ± 0% ~ (p=0.186 n=10+10) AnchoredShortMatch-12 141ns ± 0% 131ns ± 0% -7.09% (p=0.000 n=9+10) AnchoredLongMatch-12 276ns ± 4% 267ns ± 0% -3.23% (p=0.000 n=10+10) OnePassShortA-12 620ns ± 0% 611ns ± 0% -1.39% (p=0.000 n=10+9) NotOnePassShortA-12 575ns ± 3% 552ns ± 0% -3.97% (p=0.000 n=10+8) OnePassShortB-12 493ns ± 0% 491ns ± 0% -0.33% (p=0.000 n=8+8) NotOnePassShortB-12 423ns ± 0% 412ns ± 0% -2.60% (p=0.000 n=8+9) OnePassLongPrefix-12 112ns ± 0% 112ns ± 0% ~ (all equal) OnePassLongNotPrefix-12 405ns ± 0% 410ns ± 0% +1.23% (p=0.000 n=8+9) MatchParallelShared-12 501ns ± 1% 39ns ± 1% -92.27% (p=0.000 n=10+10) MatchParallelCopied-12 39.1ns ± 0% 39.2ns ± 3% ~ (p=0.785 n=6+10) QuoteMetaAll-12 94.6ns ± 0% 94.6ns ± 0% ~ (p=0.439 n=10+8) QuoteMetaNone-12 52.7ns ± 0% 52.7ns ± 0% ~ (all equal) Match/Easy0/32-12 79.1ns ± 0% 72.9ns ± 0% -7.85% (p=0.000 n=9+9) Match/Easy0/1K-12 307ns ± 1% 298ns ± 0% -2.99% (p=0.000 n=10+6) Match/Easy0/32K-12 4.65µs ± 2% 4.60µs ± 2% ~ (p=0.159 n=10+10) Match/Easy0/1M-12 234µs ± 0% 235µs ± 0% +0.17% (p=0.003 n=10+10) Match/Easy0/32M-12 7.98ms ± 1% 7.96ms ± 0% ~ (p=0.278 n=9+10) Match/Easy0i/32-12 1.13µs ± 1% 1.09µs ± 0% -3.24% (p=0.000 n=9+8) Match/Easy0i/1K-12 32.5µs ± 0% 31.7µs ± 0% -2.66% (p=0.000 n=9+9) Match/Easy0i/32K-12 1.59ms ± 0% 1.61ms ± 0% +0.75% (p=0.000 n=9+9) Match/Easy0i/1M-12 51.0ms ± 0% 51.4ms ± 0% +0.77% (p=0.000 n=10+8) Match/Easy0i/32M-12 1.63s ± 0% 1.65s ± 1% +1.24% (p=0.000 n=7+9) Match/Easy1/32-12 75.1ns ± 1% 67.9ns ± 0% -9.54% (p=0.000 n=8+8) Match/Easy1/1K-12 861ns ± 0% 884ns ± 0% +2.71% (p=0.000 n=8+9) Match/Easy1/32K-12 39.2µs ± 1% 39.2µs ± 0% ~ (p=0.090 n=10+9) Match/Easy1/1M-12 1.38ms ± 0% 1.39ms ± 0% ~ (p=0.095 n=10+9) Match/Easy1/32M-12 44.2ms ± 1% 44.2ms ± 1% ~ (p=0.218 n=10+10) Match/Medium/32-12 1.04µs ± 1% 1.05µs ± 0% +1.05% (p=0.000 n=9+8) Match/Medium/1K-12 31.3µs ± 0% 31.3µs ± 0% -0.14% (p=0.004 n=9+9) Match/Medium/32K-12 1.44ms ± 0% 1.45ms ± 0% +0.18% (p=0.001 n=8+8) Match/Medium/1M-12 46.1ms ± 0% 46.2ms ± 0% +0.13% (p=0.003 n=6+9) Match/Medium/32M-12 1.48s ± 0% 1.48s ± 0% +0.20% (p=0.002 n=9+8) Match/Hard/32-12 1.54µs ± 1% 1.49µs ± 0% -3.60% (p=0.000 n=9+10) Match/Hard/1K-12 46.4µs ± 1% 45.1µs ± 1% -2.78% (p=0.000 n=9+10) Match/Hard/32K-12 2.19ms ± 0% 2.18ms ± 1% -0.51% (p=0.006 n=8+9) Match/Hard/1M-12 70.1ms ± 0% 69.7ms ± 1% -0.52% (p=0.006 n=8+9) Match/Hard/32M-12 2.24s ± 0% 2.23s ± 1% -0.42% (p=0.046 n=8+9) Match/Hard1/32-12 8.17µs ± 1% 7.89µs ± 0% -3.42% (p=0.000 n=8+9) Match/Hard1/1K-12 254µs ± 2% 244µs ± 0% -3.91% (p=0.000 n=9+9) Match/Hard1/32K-12 9.58ms ± 1% 10.35ms ± 0% +8.00% (p=0.000 n=10+10) Match/Hard1/1M-12 306ms ± 1% 331ms ± 0% +8.27% (p=0.000 n=9+8) Match/Hard1/32M-12 9.79s ± 1% 10.60s ± 0% +8.29% (p=0.000 n=9+8) Match_onepass_regex/32-12 808ns ± 0% 812ns ± 0% +0.47% (p=0.000 n=8+10) Match_onepass_regex/1K-12 27.8µs ± 0% 28.5µs ± 0% +2.32% (p=0.000 n=8+10) Match_onepass_regex/32K-12 925µs ± 0% 936µs ± 0% +1.24% (p=0.000 n=9+10) Match_onepass_regex/1M-12 29.5ms ± 0% 30.2ms ± 0% +2.38% (p=0.000 n=10+10) Match_onepass_regex/32M-12 945ms ± 0% 970ms ± 0% +2.60% (p=0.000 n=9+10) CompileOnepass-12 4.67µs ± 0% 4.63µs ± 1% -0.84% (p=0.000 n=10+10) [Geo mean] 24.5µs 23.3µs -5.04% https://perf.golang.org/search?q=upload:20181004.1 Change-Id: Idbc2b76223718265657819ff38be2d9aba1c54b4 Reviewed-on: https://go-review.googlesource.com/c/139779 Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-09-28 16:37:16 -04:00
b.push(re, inst.Arg, pos, false)
regexp: port RE2's bitstate backtracker to the regexp package This is a port of RE2's bitstate backtracker, which triggers under the same conditions that the RE2 backtracker triggers. However I wasn't sure how to port over some of the optimizations in the RE2 backtracker, and there is a ~2% penalty on benchmarks that don't trigger the backtracker. benchmark old ns/op new ns/op delta BenchmarkLiteral 312 189 -39.42% BenchmarkNotLiteral 4435 3001 -32.33% BenchmarkMatchClass 5758 4378 -23.97% BenchmarkMatchClass_InRange 5385 4084 -24.16% BenchmarkReplaceAll 5291 3505 -33.76% BenchmarkAnchoredLiteralShortNonMatch 190 200 +5.26% BenchmarkAnchoredLiteralLongNonMatch 189 194 +2.65% BenchmarkAnchoredShortMatch 479 304 -36.53% BenchmarkAnchoredLongMatch 478 499 +4.39% BenchmarkOnePassShortA 791 798 +0.88% BenchmarkNotOnePassShortA 3202 1571 -50.94% BenchmarkOnePassShortB 614 633 +3.09% BenchmarkNotOnePassShortB 2685 881 -67.19% BenchmarkOnePassLongPrefix 152 154 +1.32% BenchmarkOnePassLongNotPrefix 505 533 +5.54% BenchmarkMatchEasy0_32 139 171 +23.02% BenchmarkMatchEasy0_1K 653 1797 +175.19% BenchmarkMatchEasy0_32K 12032 13346 +10.92% BenchmarkMatchEasy0_1M 462882 461272 -0.35% BenchmarkMatchEasy0_32M 15015339 15365238 +2.33% BenchmarkMatchEasy1_32 122 168 +37.70% BenchmarkMatchEasy1_1K 3339 2612 -21.77% BenchmarkMatchEasy1_32K 72330 71721 -0.84% BenchmarkMatchEasy1_1M 2545410 2652284 +4.20% BenchmarkMatchEasy1_32M 80072063 82609750 +3.17% BenchmarkMatchMedium_32 2359 1980 -16.07% BenchmarkMatchMedium_1K 75939 58593 -22.84% BenchmarkMatchMedium_32K 2450907 2501106 +2.05% BenchmarkMatchMedium_1M 78707697 80174418 +1.86% BenchmarkMatchMedium_32M 2535146010 2570896441 +1.41% BenchmarkMatchHard_32 4297 2960 -31.11% BenchmarkMatchHard_1K 133592 88997 -33.38% BenchmarkMatchHard_32K 4240445 4336907 +2.27% BenchmarkMatchHard_1M 136187006 139350238 +2.32% BenchmarkMatchHard_32M 4350855890 4478537306 +2.93% benchmark old MB/s new MB/s speedup BenchmarkMatchEasy0_32 228.74 186.11 0.81x BenchmarkMatchEasy0_1K 1565.91 569.64 0.36x BenchmarkMatchEasy0_32K 2723.31 2455.10 0.90x BenchmarkMatchEasy0_1M 2265.32 2273.22 1.00x BenchmarkMatchEasy0_32M 2234.68 2183.79 0.98x BenchmarkMatchEasy1_32 261.08 190.22 0.73x BenchmarkMatchEasy1_1K 306.59 391.91 1.28x BenchmarkMatchEasy1_32K 453.03 456.88 1.01x BenchmarkMatchEasy1_1M 411.95 395.35 0.96x BenchmarkMatchEasy1_32M 419.05 406.18 0.97x BenchmarkMatchMedium_32 13.56 16.16 1.19x BenchmarkMatchMedium_1K 13.48 17.48 1.30x BenchmarkMatchMedium_32K 13.37 13.10 0.98x BenchmarkMatchMedium_1M 13.32 13.08 0.98x BenchmarkMatchMedium_32M 13.24 13.05 0.99x BenchmarkMatchHard_32 7.45 10.81 1.45x BenchmarkMatchHard_1K 7.67 11.51 1.50x BenchmarkMatchHard_32K 7.73 7.56 0.98x BenchmarkMatchHard_1M 7.70 7.52 0.98x BenchmarkMatchHard_32M 7.71 7.49 0.97x Fixes #4154 Change-Id: Iff7fb9507f0872b320d08afc08679751ed1b28bc Reviewed-on: https://go-review.googlesource.com/2153 Reviewed-by: Russ Cox <rsc@golang.org>
2014-12-28 00:17:01 -08:00
pc = inst.Arg
pos = b.end
goto CheckAndLoop
}
// inst.Out is the match - non-greedy
regexp: split bit-state execution out of machine struct This allows the bit-state executions to have their own pool of allocated structures. A step toward eliminating the per-Regexp machine cache. Note especially the -92% on MatchParallelShared. This is real but not a complete story: the other execution engines still need to be de-shared, but the benchmark was only using bit-state. The tiny slowdowns in unrelated code are noise. name old time/op new time/op delta Find-12 264ns ± 3% 254ns ± 0% -3.86% (p=0.000 n=10+9) FindAllNoMatches-12 140ns ± 2% 135ns ± 0% -3.91% (p=0.000 n=10+9) FindString-12 256ns ± 0% 247ns ± 0% -3.52% (p=0.000 n=8+8) FindSubmatch-12 339ns ± 1% 334ns ± 0% -1.41% (p=0.000 n=9+10) FindStringSubmatch-12 322ns ± 0% 321ns ± 0% -0.21% (p=0.005 n=8+9) Literal-12 100ns ± 2% 92ns ± 0% -8.10% (p=0.000 n=10+9) NotLiteral-12 1.50µs ± 0% 1.47µs ± 0% -1.91% (p=0.000 n=8+9) MatchClass-12 2.18µs ± 0% 2.17µs ± 0% -0.20% (p=0.001 n=10+7) MatchClass_InRange-12 2.12µs ± 0% 2.13µs ± 0% +0.23% (p=0.000 n=10+10) ReplaceAll-12 1.41µs ± 0% 1.39µs ± 0% -1.30% (p=0.000 n=7+10) AnchoredLiteralShortNonMatch-12 89.8ns ± 0% 83.2ns ± 0% -7.35% (p=0.000 n=8+8) AnchoredLiteralLongNonMatch-12 105ns ± 3% 105ns ± 0% ~ (p=0.186 n=10+10) AnchoredShortMatch-12 141ns ± 0% 131ns ± 0% -7.09% (p=0.000 n=9+10) AnchoredLongMatch-12 276ns ± 4% 267ns ± 0% -3.23% (p=0.000 n=10+10) OnePassShortA-12 620ns ± 0% 611ns ± 0% -1.39% (p=0.000 n=10+9) NotOnePassShortA-12 575ns ± 3% 552ns ± 0% -3.97% (p=0.000 n=10+8) OnePassShortB-12 493ns ± 0% 491ns ± 0% -0.33% (p=0.000 n=8+8) NotOnePassShortB-12 423ns ± 0% 412ns ± 0% -2.60% (p=0.000 n=8+9) OnePassLongPrefix-12 112ns ± 0% 112ns ± 0% ~ (all equal) OnePassLongNotPrefix-12 405ns ± 0% 410ns ± 0% +1.23% (p=0.000 n=8+9) MatchParallelShared-12 501ns ± 1% 39ns ± 1% -92.27% (p=0.000 n=10+10) MatchParallelCopied-12 39.1ns ± 0% 39.2ns ± 3% ~ (p=0.785 n=6+10) QuoteMetaAll-12 94.6ns ± 0% 94.6ns ± 0% ~ (p=0.439 n=10+8) QuoteMetaNone-12 52.7ns ± 0% 52.7ns ± 0% ~ (all equal) Match/Easy0/32-12 79.1ns ± 0% 72.9ns ± 0% -7.85% (p=0.000 n=9+9) Match/Easy0/1K-12 307ns ± 1% 298ns ± 0% -2.99% (p=0.000 n=10+6) Match/Easy0/32K-12 4.65µs ± 2% 4.60µs ± 2% ~ (p=0.159 n=10+10) Match/Easy0/1M-12 234µs ± 0% 235µs ± 0% +0.17% (p=0.003 n=10+10) Match/Easy0/32M-12 7.98ms ± 1% 7.96ms ± 0% ~ (p=0.278 n=9+10) Match/Easy0i/32-12 1.13µs ± 1% 1.09µs ± 0% -3.24% (p=0.000 n=9+8) Match/Easy0i/1K-12 32.5µs ± 0% 31.7µs ± 0% -2.66% (p=0.000 n=9+9) Match/Easy0i/32K-12 1.59ms ± 0% 1.61ms ± 0% +0.75% (p=0.000 n=9+9) Match/Easy0i/1M-12 51.0ms ± 0% 51.4ms ± 0% +0.77% (p=0.000 n=10+8) Match/Easy0i/32M-12 1.63s ± 0% 1.65s ± 1% +1.24% (p=0.000 n=7+9) Match/Easy1/32-12 75.1ns ± 1% 67.9ns ± 0% -9.54% (p=0.000 n=8+8) Match/Easy1/1K-12 861ns ± 0% 884ns ± 0% +2.71% (p=0.000 n=8+9) Match/Easy1/32K-12 39.2µs ± 1% 39.2µs ± 0% ~ (p=0.090 n=10+9) Match/Easy1/1M-12 1.38ms ± 0% 1.39ms ± 0% ~ (p=0.095 n=10+9) Match/Easy1/32M-12 44.2ms ± 1% 44.2ms ± 1% ~ (p=0.218 n=10+10) Match/Medium/32-12 1.04µs ± 1% 1.05µs ± 0% +1.05% (p=0.000 n=9+8) Match/Medium/1K-12 31.3µs ± 0% 31.3µs ± 0% -0.14% (p=0.004 n=9+9) Match/Medium/32K-12 1.44ms ± 0% 1.45ms ± 0% +0.18% (p=0.001 n=8+8) Match/Medium/1M-12 46.1ms ± 0% 46.2ms ± 0% +0.13% (p=0.003 n=6+9) Match/Medium/32M-12 1.48s ± 0% 1.48s ± 0% +0.20% (p=0.002 n=9+8) Match/Hard/32-12 1.54µs ± 1% 1.49µs ± 0% -3.60% (p=0.000 n=9+10) Match/Hard/1K-12 46.4µs ± 1% 45.1µs ± 1% -2.78% (p=0.000 n=9+10) Match/Hard/32K-12 2.19ms ± 0% 2.18ms ± 1% -0.51% (p=0.006 n=8+9) Match/Hard/1M-12 70.1ms ± 0% 69.7ms ± 1% -0.52% (p=0.006 n=8+9) Match/Hard/32M-12 2.24s ± 0% 2.23s ± 1% -0.42% (p=0.046 n=8+9) Match/Hard1/32-12 8.17µs ± 1% 7.89µs ± 0% -3.42% (p=0.000 n=8+9) Match/Hard1/1K-12 254µs ± 2% 244µs ± 0% -3.91% (p=0.000 n=9+9) Match/Hard1/32K-12 9.58ms ± 1% 10.35ms ± 0% +8.00% (p=0.000 n=10+10) Match/Hard1/1M-12 306ms ± 1% 331ms ± 0% +8.27% (p=0.000 n=9+8) Match/Hard1/32M-12 9.79s ± 1% 10.60s ± 0% +8.29% (p=0.000 n=9+8) Match_onepass_regex/32-12 808ns ± 0% 812ns ± 0% +0.47% (p=0.000 n=8+10) Match_onepass_regex/1K-12 27.8µs ± 0% 28.5µs ± 0% +2.32% (p=0.000 n=8+10) Match_onepass_regex/32K-12 925µs ± 0% 936µs ± 0% +1.24% (p=0.000 n=9+10) Match_onepass_regex/1M-12 29.5ms ± 0% 30.2ms ± 0% +2.38% (p=0.000 n=10+10) Match_onepass_regex/32M-12 945ms ± 0% 970ms ± 0% +2.60% (p=0.000 n=9+10) CompileOnepass-12 4.67µs ± 0% 4.63µs ± 1% -0.84% (p=0.000 n=10+10) [Geo mean] 24.5µs 23.3µs -5.04% https://perf.golang.org/search?q=upload:20181004.1 Change-Id: Idbc2b76223718265657819ff38be2d9aba1c54b4 Reviewed-on: https://go-review.googlesource.com/c/139779 Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-09-28 16:37:16 -04:00
b.push(re, inst.Out, b.end, false)
regexp: port RE2's bitstate backtracker to the regexp package This is a port of RE2's bitstate backtracker, which triggers under the same conditions that the RE2 backtracker triggers. However I wasn't sure how to port over some of the optimizations in the RE2 backtracker, and there is a ~2% penalty on benchmarks that don't trigger the backtracker. benchmark old ns/op new ns/op delta BenchmarkLiteral 312 189 -39.42% BenchmarkNotLiteral 4435 3001 -32.33% BenchmarkMatchClass 5758 4378 -23.97% BenchmarkMatchClass_InRange 5385 4084 -24.16% BenchmarkReplaceAll 5291 3505 -33.76% BenchmarkAnchoredLiteralShortNonMatch 190 200 +5.26% BenchmarkAnchoredLiteralLongNonMatch 189 194 +2.65% BenchmarkAnchoredShortMatch 479 304 -36.53% BenchmarkAnchoredLongMatch 478 499 +4.39% BenchmarkOnePassShortA 791 798 +0.88% BenchmarkNotOnePassShortA 3202 1571 -50.94% BenchmarkOnePassShortB 614 633 +3.09% BenchmarkNotOnePassShortB 2685 881 -67.19% BenchmarkOnePassLongPrefix 152 154 +1.32% BenchmarkOnePassLongNotPrefix 505 533 +5.54% BenchmarkMatchEasy0_32 139 171 +23.02% BenchmarkMatchEasy0_1K 653 1797 +175.19% BenchmarkMatchEasy0_32K 12032 13346 +10.92% BenchmarkMatchEasy0_1M 462882 461272 -0.35% BenchmarkMatchEasy0_32M 15015339 15365238 +2.33% BenchmarkMatchEasy1_32 122 168 +37.70% BenchmarkMatchEasy1_1K 3339 2612 -21.77% BenchmarkMatchEasy1_32K 72330 71721 -0.84% BenchmarkMatchEasy1_1M 2545410 2652284 +4.20% BenchmarkMatchEasy1_32M 80072063 82609750 +3.17% BenchmarkMatchMedium_32 2359 1980 -16.07% BenchmarkMatchMedium_1K 75939 58593 -22.84% BenchmarkMatchMedium_32K 2450907 2501106 +2.05% BenchmarkMatchMedium_1M 78707697 80174418 +1.86% BenchmarkMatchMedium_32M 2535146010 2570896441 +1.41% BenchmarkMatchHard_32 4297 2960 -31.11% BenchmarkMatchHard_1K 133592 88997 -33.38% BenchmarkMatchHard_32K 4240445 4336907 +2.27% BenchmarkMatchHard_1M 136187006 139350238 +2.32% BenchmarkMatchHard_32M 4350855890 4478537306 +2.93% benchmark old MB/s new MB/s speedup BenchmarkMatchEasy0_32 228.74 186.11 0.81x BenchmarkMatchEasy0_1K 1565.91 569.64 0.36x BenchmarkMatchEasy0_32K 2723.31 2455.10 0.90x BenchmarkMatchEasy0_1M 2265.32 2273.22 1.00x BenchmarkMatchEasy0_32M 2234.68 2183.79 0.98x BenchmarkMatchEasy1_32 261.08 190.22 0.73x BenchmarkMatchEasy1_1K 306.59 391.91 1.28x BenchmarkMatchEasy1_32K 453.03 456.88 1.01x BenchmarkMatchEasy1_1M 411.95 395.35 0.96x BenchmarkMatchEasy1_32M 419.05 406.18 0.97x BenchmarkMatchMedium_32 13.56 16.16 1.19x BenchmarkMatchMedium_1K 13.48 17.48 1.30x BenchmarkMatchMedium_32K 13.37 13.10 0.98x BenchmarkMatchMedium_1M 13.32 13.08 0.98x BenchmarkMatchMedium_32M 13.24 13.05 0.99x BenchmarkMatchHard_32 7.45 10.81 1.45x BenchmarkMatchHard_1K 7.67 11.51 1.50x BenchmarkMatchHard_32K 7.73 7.56 0.98x BenchmarkMatchHard_1M 7.70 7.52 0.98x BenchmarkMatchHard_32M 7.71 7.49 0.97x Fixes #4154 Change-Id: Iff7fb9507f0872b320d08afc08679751ed1b28bc Reviewed-on: https://go-review.googlesource.com/2153 Reviewed-by: Russ Cox <rsc@golang.org>
2014-12-28 00:17:01 -08:00
pc = inst.Out
goto CheckAndLoop
case syntax.InstRune:
r, width := i.step(pos)
if !inst.MatchRune(r) {
continue
}
pos += width
pc = inst.Out
goto CheckAndLoop
case syntax.InstRune1:
r, width := i.step(pos)
if r != inst.Rune[0] {
continue
}
pos += width
pc = inst.Out
goto CheckAndLoop
case syntax.InstRuneAnyNotNL:
r, width := i.step(pos)
if r == '\n' || r == endOfText {
continue
}
pos += width
pc = inst.Out
goto CheckAndLoop
case syntax.InstRuneAny:
r, width := i.step(pos)
if r == endOfText {
continue
}
pos += width
pc = inst.Out
goto CheckAndLoop
case syntax.InstCapture:
regexp: make (*bitState).push inlinable By refactoring job.arg from int with 0/1 as the only valid values into bool and simplifying (*bitState).push, we reduce the number of nodes below the inlining threshold. This improves backtracking regexp performance by 5-10% and go1 geomean by 1.7% Full performance data below: name old time/op new time/op delta Find-6 510ns ± 0% 480ns ± 1% -5.90% (p=0.000 n=10+10) FindString-6 504ns ± 1% 479ns ± 1% -5.10% (p=0.000 n=10+10) FindSubmatch-6 689ns ± 1% 659ns ± 1% -4.27% (p=0.000 n=9+10) FindStringSubmatch-6 659ns ± 0% 628ns ± 1% -4.69% (p=0.000 n=8+10) Literal-6 174ns ± 1% 171ns ± 1% -1.50% (p=0.000 n=10+10) NotLiteral-6 2.89µs ± 1% 2.72µs ± 0% -5.84% (p=0.000 n=10+9) MatchClass-6 4.65µs ± 1% 4.28µs ± 1% -7.96% (p=0.000 n=10+10) MatchClass_InRange-6 4.15µs ± 1% 3.80µs ± 0% -8.61% (p=0.000 n=10+8) ReplaceAll-6 2.72µs ± 1% 2.60µs ± 1% -4.68% (p=0.000 n=10+10) AnchoredLiteralShortNonMatch-6 158ns ± 1% 153ns ± 1% -3.03% (p=0.000 n=10+10) AnchoredLiteralLongNonMatch-6 176ns ± 1% 176ns ± 0% ~ (p=1.000 n=10+9) AnchoredShortMatch-6 260ns ± 0% 255ns ± 1% -1.84% (p=0.000 n=9+10) AnchoredLongMatch-6 456ns ± 0% 455ns ± 0% -0.19% (p=0.008 n=8+10) OnePassShortA-6 1.13µs ± 1% 1.12µs ± 0% -0.57% (p=0.046 n=10+8) NotOnePassShortA-6 1.14µs ± 1% 1.14µs ± 1% ~ (p=0.162 n=10+10) OnePassShortB-6 908ns ± 0% 893ns ± 0% -1.60% (p=0.000 n=8+9) NotOnePassShortB-6 857ns ± 0% 803ns ± 1% -6.34% (p=0.000 n=8+10) OnePassLongPrefix-6 190ns ± 0% 190ns ± 1% ~ (p=0.059 n=8+10) OnePassLongNotPrefix-6 722ns ± 1% 722ns ± 1% ~ (p=0.451 n=10+10) MatchParallelShared-6 810ns ± 2% 807ns ± 2% ~ (p=0.643 n=10+10) MatchParallelCopied-6 72.1ns ± 1% 69.4ns ± 1% -3.81% (p=0.000 n=10+10) QuoteMetaAll-6 213ns ± 2% 216ns ± 3% ~ (p=0.284 n=10+10) QuoteMetaNone-6 89.7ns ± 1% 89.8ns ± 1% ~ (p=0.616 n=10+10) Match/Easy0/32-6 127ns ± 1% 127ns ± 1% ~ (p=0.977 n=10+10) Match/Easy0/1K-6 566ns ± 0% 566ns ± 0% ~ (p=1.000 n=8+8) Match/Easy0/32K-6 9.30µs ± 1% 9.28µs ± 1% ~ (p=0.529 n=10+10) Match/Easy0/1M-6 460µs ± 1% 460µs ± 1% ~ (p=0.853 n=10+10) Match/Easy0/32M-6 15.0ms ± 0% 15.1ms ± 0% +0.77% (p=0.000 n=9+8) Match/Easy0i/32-6 2.10µs ± 1% 1.98µs ± 0% -6.02% (p=0.000 n=10+8) Match/Easy0i/1K-6 61.5µs ± 0% 57.2µs ± 0% -6.97% (p=0.000 n=10+9) Match/Easy0i/32K-6 2.75ms ± 0% 2.72ms ± 0% -1.10% (p=0.000 n=9+9) Match/Easy0i/1M-6 88.0ms ± 0% 86.9ms ± 1% -1.29% (p=0.000 n=8+10) Match/Easy0i/32M-6 2.82s ± 0% 2.77s ± 1% -1.81% (p=0.000 n=8+10) Match/Easy1/32-6 123ns ± 1% 124ns ± 1% +0.90% (p=0.001 n=10+10) Match/Easy1/1K-6 1.70µs ± 1% 1.65µs ± 0% -3.18% (p=0.000 n=9+10) Match/Easy1/32K-6 69.1µs ± 0% 68.4µs ± 1% -0.95% (p=0.000 n=8+10) Match/Easy1/1M-6 2.46ms ± 1% 2.42ms ± 1% -1.66% (p=0.000 n=10+10) Match/Easy1/32M-6 78.4ms ± 1% 77.5ms ± 0% -1.08% (p=0.000 n=10+9) Match/Medium/32-6 2.07µs ± 1% 1.91µs ± 1% -7.69% (p=0.000 n=10+10) Match/Medium/1K-6 62.8µs ± 0% 58.0µs ± 1% -7.70% (p=0.000 n=8+10) Match/Medium/32K-6 2.63ms ± 1% 2.58ms ± 1% -2.14% (p=0.000 n=10+10) Match/Medium/1M-6 84.6ms ± 0% 82.5ms ± 0% -2.37% (p=0.000 n=8+9) Match/Medium/32M-6 2.71s ± 0% 2.64s ± 0% -2.46% (p=0.000 n=10+9) Match/Hard/32-6 3.26µs ± 1% 2.98µs ± 1% -8.49% (p=0.000 n=10+10) Match/Hard/1K-6 100µs ± 0% 90µs ± 1% -9.55% (p=0.000 n=9+10) Match/Hard/32K-6 3.82ms ± 0% 3.82ms ± 1% ~ (p=0.515 n=8+10) Match/Hard/1M-6 122ms ± 1% 123ms ± 0% +0.66% (p=0.000 n=10+8) Match/Hard/32M-6 3.89s ± 1% 3.91s ± 1% ~ (p=0.105 n=10+10) Match/Hard1/32-6 18.1µs ± 1% 16.1µs ± 1% -11.31% (p=0.000 n=10+10) Match/Hard1/1K-6 565µs ± 0% 493µs ± 1% -12.65% (p=0.000 n=8+10) Match/Hard1/32K-6 18.8ms ± 0% 18.8ms ± 1% ~ (p=0.905 n=9+10) Match/Hard1/1M-6 602ms ± 1% 602ms ± 1% ~ (p=0.278 n=9+10) Match/Hard1/32M-6 19.1s ± 1% 19.2s ± 1% +0.31% (p=0.035 n=9+10) Match_onepass_regex/32-6 6.32µs ± 1% 6.34µs ± 1% ~ (p=0.060 n=10+10) Match_onepass_regex/1K-6 204µs ± 1% 204µs ± 1% ~ (p=0.842 n=9+10) Match_onepass_regex/32K-6 6.53ms ± 0% 6.55ms ± 1% +0.36% (p=0.005 n=10+10) Match_onepass_regex/1M-6 209ms ± 0% 208ms ± 1% -0.65% (p=0.034 n=8+10) Match_onepass_regex/32M-6 6.72s ± 0% 6.68s ± 1% -0.74% (p=0.000 n=9+10) CompileOnepass/^(?:(?:(?:.(?:$))?))...-6 7.02µs ± 1% 7.02µs ± 1% ~ (p=0.671 n=10+10) CompileOnepass/^abcd$-6 5.65µs ± 1% 5.65µs ± 1% ~ (p=0.411 n=10+9) CompileOnepass/^(?:(?:a{0,})*?)$-6 7.06µs ± 1% 7.06µs ± 1% ~ (p=0.912 n=10+10) CompileOnepass/^(?:(?:a+)*)$-6 6.40µs ± 1% 6.41µs ± 1% ~ (p=0.699 n=10+10) CompileOnepass/^(?:(?:a|(?:aa)))$-6 8.18µs ± 2% 8.16µs ± 1% ~ (p=0.529 n=10+10) CompileOnepass/^(?:[^\s\S])$-6 5.08µs ± 1% 5.17µs ± 1% +1.77% (p=0.000 n=9+10) CompileOnepass/^(?:(?:(?:a*)+))$-6 6.86µs ± 1% 6.85µs ± 0% ~ (p=0.190 n=10+9) CompileOnepass/^[a-c]+$-6 5.14µs ± 1% 5.11µs ± 0% -0.53% (p=0.041 n=10+10) CompileOnepass/^[a-c]*$-6 5.62µs ± 1% 5.63µs ± 1% ~ (p=0.382 n=10+10) CompileOnepass/^(?:a*)$-6 5.76µs ± 1% 5.73µs ± 1% -0.41% (p=0.008 n=9+10) CompileOnepass/^(?:(?:aa)|a)$-6 7.89µs ± 1% 7.84µs ± 1% -0.66% (p=0.020 n=10+10) CompileOnepass/^...$-6 5.38µs ± 1% 5.38µs ± 1% ~ (p=0.857 n=9+10) CompileOnepass/^(?:a|(?:aa))$-6 7.80µs ± 2% 7.82µs ± 1% ~ (p=0.342 n=10+10) CompileOnepass/^a((b))c$-6 7.75µs ± 1% 7.78µs ± 1% ~ (p=0.172 n=10+10) CompileOnepass/^a.[l-nA-Cg-j]?e$-6 8.39µs ± 1% 8.42µs ± 1% ~ (p=0.138 n=10+10) CompileOnepass/^a((b))$-6 6.92µs ± 1% 6.95µs ± 1% ~ (p=0.159 n=10+10) CompileOnepass/^a(?:(b)|(c))c$-6 10.0µs ± 1% 10.0µs ± 1% ~ (p=0.896 n=10+10) CompileOnepass/^a(?:b|c)$-6 5.62µs ± 1% 5.66µs ± 1% +0.71% (p=0.023 n=10+10) CompileOnepass/^a(?:b?|c)$-6 8.49µs ± 1% 8.43µs ± 1% -0.69% (p=0.010 n=10+10) CompileOnepass/^a(?:b?|c+)$-6 9.26µs ± 1% 9.28µs ± 1% ~ (p=0.448 n=10+10) CompileOnepass/^a(?:bc)+$-6 6.52µs ± 1% 6.46µs ± 2% -1.02% (p=0.003 n=10+10) CompileOnepass/^a(?:[bcd])+$-6 6.29µs ± 1% 6.32µs ± 1% ~ (p=0.256 n=10+10) CompileOnepass/^a((?:[bcd])+)$-6 7.77µs ± 1% 7.79µs ± 1% ~ (p=0.105 n=10+10) CompileOnepass/^a(:?b|c)*d$-6 14.0µs ± 1% 13.9µs ± 1% -0.69% (p=0.003 n=10+10) CompileOnepass/^.bc(d|e)*$-6 8.96µs ± 1% 9.06µs ± 1% +1.20% (p=0.000 n=10+9) CompileOnepass/^loooooooooooooooooo...-6 219µs ± 1% 220µs ± 1% +0.63% (p=0.006 n=9+10) [Geo mean] 31.6µs 31.1µs -1.82% name old speed new speed delta QuoteMetaAll-6 65.5MB/s ± 2% 64.8MB/s ± 3% ~ (p=0.315 n=10+10) QuoteMetaNone-6 290MB/s ± 1% 290MB/s ± 1% ~ (p=0.755 n=10+10) Match/Easy0/32-6 250MB/s ± 0% 251MB/s ± 1% ~ (p=0.277 n=8+9) Match/Easy0/1K-6 1.81GB/s ± 0% 1.81GB/s ± 0% ~ (p=0.408 n=8+10) Match/Easy0/32K-6 3.52GB/s ± 1% 3.53GB/s ± 1% ~ (p=0.529 n=10+10) Match/Easy0/1M-6 2.28GB/s ± 1% 2.28GB/s ± 1% ~ (p=0.853 n=10+10) Match/Easy0/32M-6 2.24GB/s ± 0% 2.23GB/s ± 0% -0.76% (p=0.000 n=9+8) Match/Easy0i/32-6 15.2MB/s ± 1% 16.2MB/s ± 0% +6.43% (p=0.000 n=10+9) Match/Easy0i/1K-6 16.6MB/s ± 0% 17.9MB/s ± 0% +7.48% (p=0.000 n=10+9) Match/Easy0i/32K-6 11.9MB/s ± 0% 12.0MB/s ± 0% +1.11% (p=0.000 n=9+9) Match/Easy0i/1M-6 11.9MB/s ± 0% 12.1MB/s ± 1% +1.31% (p=0.000 n=8+10) Match/Easy0i/32M-6 11.9MB/s ± 0% 12.1MB/s ± 1% +1.84% (p=0.000 n=8+10) Match/Easy1/32-6 260MB/s ± 1% 258MB/s ± 1% -0.91% (p=0.001 n=10+10) Match/Easy1/1K-6 601MB/s ± 1% 621MB/s ± 0% +3.28% (p=0.000 n=9+10) Match/Easy1/32K-6 474MB/s ± 0% 479MB/s ± 1% +0.96% (p=0.000 n=8+10) Match/Easy1/1M-6 426MB/s ± 1% 433MB/s ± 1% +1.68% (p=0.000 n=10+10) Match/Easy1/32M-6 428MB/s ± 1% 433MB/s ± 0% +1.09% (p=0.000 n=10+9) Match/Medium/32-6 15.4MB/s ± 1% 16.7MB/s ± 1% +8.23% (p=0.000 n=10+9) Match/Medium/1K-6 16.3MB/s ± 1% 17.7MB/s ± 1% +8.43% (p=0.000 n=9+10) Match/Medium/32K-6 12.5MB/s ± 1% 12.7MB/s ± 1% +2.15% (p=0.000 n=10+10) Match/Medium/1M-6 12.4MB/s ± 0% 12.7MB/s ± 0% +2.44% (p=0.000 n=8+9) Match/Medium/32M-6 12.4MB/s ± 0% 12.7MB/s ± 0% +2.52% (p=0.000 n=10+9) Match/Hard/32-6 9.82MB/s ± 1% 10.73MB/s ± 1% +9.29% (p=0.000 n=10+10) Match/Hard/1K-6 10.2MB/s ± 0% 11.3MB/s ± 1% +10.56% (p=0.000 n=9+10) Match/Hard/32K-6 8.58MB/s ± 0% 8.58MB/s ± 1% ~ (p=0.554 n=8+10) Match/Hard/1M-6 8.59MB/s ± 1% 8.53MB/s ± 0% -0.70% (p=0.000 n=10+8) Match/Hard/32M-6 8.62MB/s ± 1% 8.59MB/s ± 1% ~ (p=0.098 n=10+10) Match/Hard1/32-6 1.77MB/s ± 1% 1.99MB/s ± 1% +12.40% (p=0.000 n=10+8) Match/Hard1/1K-6 1.81MB/s ± 1% 2.08MB/s ± 1% +14.55% (p=0.000 n=10+10) Match/Hard1/32K-6 1.74MB/s ± 0% 1.74MB/s ± 0% ~ (p=0.108 n=9+10) Match/Hard1/1M-6 1.74MB/s ± 0% 1.74MB/s ± 1% ~ (p=1.000 n=9+10) Match/Hard1/32M-6 1.75MB/s ± 0% 1.75MB/s ± 1% ~ (p=0.157 n=9+10) Match_onepass_regex/32-6 5.05MB/s ± 0% 5.05MB/s ± 1% ~ (p=0.262 n=8+10) Match_onepass_regex/1K-6 5.02MB/s ± 1% 5.02MB/s ± 1% ~ (p=0.677 n=9+10) Match_onepass_regex/32K-6 5.02MB/s ± 0% 4.99MB/s ± 0% -0.47% (p=0.000 n=10+9) Match_onepass_regex/1M-6 5.01MB/s ± 0% 5.04MB/s ± 1% +0.68% (p=0.017 n=8+10) Match_onepass_regex/32M-6 4.99MB/s ± 0% 5.03MB/s ± 1% +0.74% (p=0.000 n=10+10) [Geo mean] 29.1MB/s 29.8MB/s +2.44% go1 data for reference name old time/op new time/op delta BinaryTree17-6 4.39s ± 1% 4.37s ± 0% -0.58% (p=0.006 n=9+9) Fannkuch11-6 5.13s ± 0% 5.18s ± 0% +0.87% (p=0.000 n=8+8) FmtFprintfEmpty-6 74.2ns ± 0% 71.7ns ± 3% -3.41% (p=0.000 n=10+10) FmtFprintfString-6 120ns ± 1% 122ns ± 2% ~ (p=0.333 n=10+10) FmtFprintfInt-6 127ns ± 1% 127ns ± 1% ~ (p=0.809 n=10+10) FmtFprintfIntInt-6 186ns ± 0% 188ns ± 1% +1.02% (p=0.002 n=8+10) FmtFprintfPrefixedInt-6 223ns ± 1% 222ns ± 2% ~ (p=0.421 n=10+10) FmtFprintfFloat-6 374ns ± 0% 376ns ± 1% +0.43% (p=0.030 n=8+10) FmtManyArgs-6 795ns ± 0% 788ns ± 1% -0.79% (p=0.000 n=8+9) GobDecode-6 10.9ms ± 1% 10.9ms ± 0% ~ (p=0.079 n=10+9) GobEncode-6 8.60ms ± 1% 8.56ms ± 0% -0.52% (p=0.004 n=10+10) Gzip-6 378ms ± 1% 386ms ± 1% +2.28% (p=0.000 n=10+10) Gunzip-6 63.7ms ± 0% 62.3ms ± 0% -2.22% (p=0.000 n=9+8) HTTPClientServer-6 120µs ± 3% 114µs ± 3% -4.99% (p=0.000 n=10+10) JSONEncode-6 20.3ms ± 1% 19.9ms ± 0% -1.90% (p=0.000 n=9+10) JSONDecode-6 84.3ms ± 0% 83.7ms ± 0% -0.76% (p=0.000 n=8+8) Mandelbrot200-6 6.91ms ± 0% 6.89ms ± 0% -0.31% (p=0.000 n=9+8) GoParse-6 5.49ms ± 0% 5.47ms ± 1% ~ (p=0.101 n=8+10) RegexpMatchEasy0_32-6 130ns ± 0% 128ns ± 0% -1.54% (p=0.002 n=8+10) RegexpMatchEasy0_1K-6 322ns ± 1% 322ns ± 0% ~ (p=0.525 n=10+9) RegexpMatchEasy1_32-6 124ns ± 0% 124ns ± 0% -0.32% (p=0.046 n=8+10) RegexpMatchEasy1_1K-6 570ns ± 0% 548ns ± 1% -3.76% (p=0.000 n=10+10) RegexpMatchMedium_32-6 196ns ± 0% 183ns ± 1% -6.61% (p=0.000 n=8+10) RegexpMatchMedium_1K-6 64.3µs ± 0% 59.0µs ± 1% -8.31% (p=0.000 n=8+10) RegexpMatchHard_32-6 3.08µs ± 0% 2.80µs ± 0% -8.96% (p=0.000 n=8+9) RegexpMatchHard_1K-6 93.0µs ± 0% 84.5µs ± 1% -9.17% (p=0.000 n=8+9) Revcomp-6 647ms ± 2% 646ms ± 1% ~ (p=0.720 n=10+9) Template-6 92.3ms ± 0% 91.7ms ± 0% -0.65% (p=0.000 n=8+8) TimeParse-6 490ns ± 0% 488ns ± 0% -0.43% (p=0.000 n=10+10) TimeFormat-6 513ns ± 0% 513ns ± 1% ~ (p=0.144 n=9+10) [Geo mean] 79.1µs 77.7µs -1.73% name old speed new speed delta GobDecode-6 70.1MB/s ± 1% 70.3MB/s ± 0% ~ (p=0.078 n=10+9) GobEncode-6 89.2MB/s ± 1% 89.7MB/s ± 0% +0.52% (p=0.004 n=10+10) Gzip-6 51.4MB/s ± 1% 50.2MB/s ± 1% -2.23% (p=0.000 n=10+10) Gunzip-6 304MB/s ± 0% 311MB/s ± 0% +2.27% (p=0.000 n=9+8) JSONEncode-6 95.8MB/s ± 1% 97.7MB/s ± 0% +1.93% (p=0.000 n=9+10) JSONDecode-6 23.0MB/s ± 0% 23.2MB/s ± 0% +0.76% (p=0.000 n=8+8) GoParse-6 10.6MB/s ± 0% 10.6MB/s ± 1% ~ (p=0.111 n=8+10) RegexpMatchEasy0_32-6 244MB/s ± 0% 249MB/s ± 0% +2.06% (p=0.000 n=9+10) RegexpMatchEasy0_1K-6 3.18GB/s ± 1% 3.17GB/s ± 0% ~ (p=0.211 n=10+9) RegexpMatchEasy1_32-6 257MB/s ± 0% 258MB/s ± 0% +0.37% (p=0.000 n=8+8) RegexpMatchEasy1_1K-6 1.80GB/s ± 0% 1.87GB/s ± 1% +3.91% (p=0.000 n=10+10) RegexpMatchMedium_32-6 5.08MB/s ± 0% 5.43MB/s ± 1% +7.03% (p=0.000 n=8+10) RegexpMatchMedium_1K-6 15.9MB/s ± 0% 17.4MB/s ± 1% +9.08% (p=0.000 n=8+10) RegexpMatchHard_32-6 10.4MB/s ± 0% 11.4MB/s ± 0% +9.82% (p=0.000 n=8+9) RegexpMatchHard_1K-6 11.0MB/s ± 0% 12.1MB/s ± 1% +10.10% (p=0.000 n=8+9) Revcomp-6 393MB/s ± 2% 394MB/s ± 1% ~ (p=0.720 n=10+9) Template-6 21.0MB/s ± 0% 21.2MB/s ± 0% +0.66% (p=0.000 n=8+8) [Geo mean] 74.2MB/s 76.2MB/s +2.70% Updates #21851 Change-Id: Ie88455db925f422a828f8528293790726a9c036b Reviewed-on: https://go-review.googlesource.com/65491 Run-TryBot: Ilya Tocar <ilya.tocar@intel.com> Reviewed-by: Daniel Martí <mvdan@mvdan.cc> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2017-09-22 15:15:23 -05:00
if arg {
// Finished inst.Out; restore the old value.
b.cap[inst.Arg] = pos
continue
} else {
regexp: port RE2's bitstate backtracker to the regexp package This is a port of RE2's bitstate backtracker, which triggers under the same conditions that the RE2 backtracker triggers. However I wasn't sure how to port over some of the optimizations in the RE2 backtracker, and there is a ~2% penalty on benchmarks that don't trigger the backtracker. benchmark old ns/op new ns/op delta BenchmarkLiteral 312 189 -39.42% BenchmarkNotLiteral 4435 3001 -32.33% BenchmarkMatchClass 5758 4378 -23.97% BenchmarkMatchClass_InRange 5385 4084 -24.16% BenchmarkReplaceAll 5291 3505 -33.76% BenchmarkAnchoredLiteralShortNonMatch 190 200 +5.26% BenchmarkAnchoredLiteralLongNonMatch 189 194 +2.65% BenchmarkAnchoredShortMatch 479 304 -36.53% BenchmarkAnchoredLongMatch 478 499 +4.39% BenchmarkOnePassShortA 791 798 +0.88% BenchmarkNotOnePassShortA 3202 1571 -50.94% BenchmarkOnePassShortB 614 633 +3.09% BenchmarkNotOnePassShortB 2685 881 -67.19% BenchmarkOnePassLongPrefix 152 154 +1.32% BenchmarkOnePassLongNotPrefix 505 533 +5.54% BenchmarkMatchEasy0_32 139 171 +23.02% BenchmarkMatchEasy0_1K 653 1797 +175.19% BenchmarkMatchEasy0_32K 12032 13346 +10.92% BenchmarkMatchEasy0_1M 462882 461272 -0.35% BenchmarkMatchEasy0_32M 15015339 15365238 +2.33% BenchmarkMatchEasy1_32 122 168 +37.70% BenchmarkMatchEasy1_1K 3339 2612 -21.77% BenchmarkMatchEasy1_32K 72330 71721 -0.84% BenchmarkMatchEasy1_1M 2545410 2652284 +4.20% BenchmarkMatchEasy1_32M 80072063 82609750 +3.17% BenchmarkMatchMedium_32 2359 1980 -16.07% BenchmarkMatchMedium_1K 75939 58593 -22.84% BenchmarkMatchMedium_32K 2450907 2501106 +2.05% BenchmarkMatchMedium_1M 78707697 80174418 +1.86% BenchmarkMatchMedium_32M 2535146010 2570896441 +1.41% BenchmarkMatchHard_32 4297 2960 -31.11% BenchmarkMatchHard_1K 133592 88997 -33.38% BenchmarkMatchHard_32K 4240445 4336907 +2.27% BenchmarkMatchHard_1M 136187006 139350238 +2.32% BenchmarkMatchHard_32M 4350855890 4478537306 +2.93% benchmark old MB/s new MB/s speedup BenchmarkMatchEasy0_32 228.74 186.11 0.81x BenchmarkMatchEasy0_1K 1565.91 569.64 0.36x BenchmarkMatchEasy0_32K 2723.31 2455.10 0.90x BenchmarkMatchEasy0_1M 2265.32 2273.22 1.00x BenchmarkMatchEasy0_32M 2234.68 2183.79 0.98x BenchmarkMatchEasy1_32 261.08 190.22 0.73x BenchmarkMatchEasy1_1K 306.59 391.91 1.28x BenchmarkMatchEasy1_32K 453.03 456.88 1.01x BenchmarkMatchEasy1_1M 411.95 395.35 0.96x BenchmarkMatchEasy1_32M 419.05 406.18 0.97x BenchmarkMatchMedium_32 13.56 16.16 1.19x BenchmarkMatchMedium_1K 13.48 17.48 1.30x BenchmarkMatchMedium_32K 13.37 13.10 0.98x BenchmarkMatchMedium_1M 13.32 13.08 0.98x BenchmarkMatchMedium_32M 13.24 13.05 0.99x BenchmarkMatchHard_32 7.45 10.81 1.45x BenchmarkMatchHard_1K 7.67 11.51 1.50x BenchmarkMatchHard_32K 7.73 7.56 0.98x BenchmarkMatchHard_1M 7.70 7.52 0.98x BenchmarkMatchHard_32M 7.71 7.49 0.97x Fixes #4154 Change-Id: Iff7fb9507f0872b320d08afc08679751ed1b28bc Reviewed-on: https://go-review.googlesource.com/2153 Reviewed-by: Russ Cox <rsc@golang.org>
2014-12-28 00:17:01 -08:00
if 0 <= inst.Arg && inst.Arg < uint32(len(b.cap)) {
// Capture pos to register, but save old value.
regexp: split bit-state execution out of machine struct This allows the bit-state executions to have their own pool of allocated structures. A step toward eliminating the per-Regexp machine cache. Note especially the -92% on MatchParallelShared. This is real but not a complete story: the other execution engines still need to be de-shared, but the benchmark was only using bit-state. The tiny slowdowns in unrelated code are noise. name old time/op new time/op delta Find-12 264ns ± 3% 254ns ± 0% -3.86% (p=0.000 n=10+9) FindAllNoMatches-12 140ns ± 2% 135ns ± 0% -3.91% (p=0.000 n=10+9) FindString-12 256ns ± 0% 247ns ± 0% -3.52% (p=0.000 n=8+8) FindSubmatch-12 339ns ± 1% 334ns ± 0% -1.41% (p=0.000 n=9+10) FindStringSubmatch-12 322ns ± 0% 321ns ± 0% -0.21% (p=0.005 n=8+9) Literal-12 100ns ± 2% 92ns ± 0% -8.10% (p=0.000 n=10+9) NotLiteral-12 1.50µs ± 0% 1.47µs ± 0% -1.91% (p=0.000 n=8+9) MatchClass-12 2.18µs ± 0% 2.17µs ± 0% -0.20% (p=0.001 n=10+7) MatchClass_InRange-12 2.12µs ± 0% 2.13µs ± 0% +0.23% (p=0.000 n=10+10) ReplaceAll-12 1.41µs ± 0% 1.39µs ± 0% -1.30% (p=0.000 n=7+10) AnchoredLiteralShortNonMatch-12 89.8ns ± 0% 83.2ns ± 0% -7.35% (p=0.000 n=8+8) AnchoredLiteralLongNonMatch-12 105ns ± 3% 105ns ± 0% ~ (p=0.186 n=10+10) AnchoredShortMatch-12 141ns ± 0% 131ns ± 0% -7.09% (p=0.000 n=9+10) AnchoredLongMatch-12 276ns ± 4% 267ns ± 0% -3.23% (p=0.000 n=10+10) OnePassShortA-12 620ns ± 0% 611ns ± 0% -1.39% (p=0.000 n=10+9) NotOnePassShortA-12 575ns ± 3% 552ns ± 0% -3.97% (p=0.000 n=10+8) OnePassShortB-12 493ns ± 0% 491ns ± 0% -0.33% (p=0.000 n=8+8) NotOnePassShortB-12 423ns ± 0% 412ns ± 0% -2.60% (p=0.000 n=8+9) OnePassLongPrefix-12 112ns ± 0% 112ns ± 0% ~ (all equal) OnePassLongNotPrefix-12 405ns ± 0% 410ns ± 0% +1.23% (p=0.000 n=8+9) MatchParallelShared-12 501ns ± 1% 39ns ± 1% -92.27% (p=0.000 n=10+10) MatchParallelCopied-12 39.1ns ± 0% 39.2ns ± 3% ~ (p=0.785 n=6+10) QuoteMetaAll-12 94.6ns ± 0% 94.6ns ± 0% ~ (p=0.439 n=10+8) QuoteMetaNone-12 52.7ns ± 0% 52.7ns ± 0% ~ (all equal) Match/Easy0/32-12 79.1ns ± 0% 72.9ns ± 0% -7.85% (p=0.000 n=9+9) Match/Easy0/1K-12 307ns ± 1% 298ns ± 0% -2.99% (p=0.000 n=10+6) Match/Easy0/32K-12 4.65µs ± 2% 4.60µs ± 2% ~ (p=0.159 n=10+10) Match/Easy0/1M-12 234µs ± 0% 235µs ± 0% +0.17% (p=0.003 n=10+10) Match/Easy0/32M-12 7.98ms ± 1% 7.96ms ± 0% ~ (p=0.278 n=9+10) Match/Easy0i/32-12 1.13µs ± 1% 1.09µs ± 0% -3.24% (p=0.000 n=9+8) Match/Easy0i/1K-12 32.5µs ± 0% 31.7µs ± 0% -2.66% (p=0.000 n=9+9) Match/Easy0i/32K-12 1.59ms ± 0% 1.61ms ± 0% +0.75% (p=0.000 n=9+9) Match/Easy0i/1M-12 51.0ms ± 0% 51.4ms ± 0% +0.77% (p=0.000 n=10+8) Match/Easy0i/32M-12 1.63s ± 0% 1.65s ± 1% +1.24% (p=0.000 n=7+9) Match/Easy1/32-12 75.1ns ± 1% 67.9ns ± 0% -9.54% (p=0.000 n=8+8) Match/Easy1/1K-12 861ns ± 0% 884ns ± 0% +2.71% (p=0.000 n=8+9) Match/Easy1/32K-12 39.2µs ± 1% 39.2µs ± 0% ~ (p=0.090 n=10+9) Match/Easy1/1M-12 1.38ms ± 0% 1.39ms ± 0% ~ (p=0.095 n=10+9) Match/Easy1/32M-12 44.2ms ± 1% 44.2ms ± 1% ~ (p=0.218 n=10+10) Match/Medium/32-12 1.04µs ± 1% 1.05µs ± 0% +1.05% (p=0.000 n=9+8) Match/Medium/1K-12 31.3µs ± 0% 31.3µs ± 0% -0.14% (p=0.004 n=9+9) Match/Medium/32K-12 1.44ms ± 0% 1.45ms ± 0% +0.18% (p=0.001 n=8+8) Match/Medium/1M-12 46.1ms ± 0% 46.2ms ± 0% +0.13% (p=0.003 n=6+9) Match/Medium/32M-12 1.48s ± 0% 1.48s ± 0% +0.20% (p=0.002 n=9+8) Match/Hard/32-12 1.54µs ± 1% 1.49µs ± 0% -3.60% (p=0.000 n=9+10) Match/Hard/1K-12 46.4µs ± 1% 45.1µs ± 1% -2.78% (p=0.000 n=9+10) Match/Hard/32K-12 2.19ms ± 0% 2.18ms ± 1% -0.51% (p=0.006 n=8+9) Match/Hard/1M-12 70.1ms ± 0% 69.7ms ± 1% -0.52% (p=0.006 n=8+9) Match/Hard/32M-12 2.24s ± 0% 2.23s ± 1% -0.42% (p=0.046 n=8+9) Match/Hard1/32-12 8.17µs ± 1% 7.89µs ± 0% -3.42% (p=0.000 n=8+9) Match/Hard1/1K-12 254µs ± 2% 244µs ± 0% -3.91% (p=0.000 n=9+9) Match/Hard1/32K-12 9.58ms ± 1% 10.35ms ± 0% +8.00% (p=0.000 n=10+10) Match/Hard1/1M-12 306ms ± 1% 331ms ± 0% +8.27% (p=0.000 n=9+8) Match/Hard1/32M-12 9.79s ± 1% 10.60s ± 0% +8.29% (p=0.000 n=9+8) Match_onepass_regex/32-12 808ns ± 0% 812ns ± 0% +0.47% (p=0.000 n=8+10) Match_onepass_regex/1K-12 27.8µs ± 0% 28.5µs ± 0% +2.32% (p=0.000 n=8+10) Match_onepass_regex/32K-12 925µs ± 0% 936µs ± 0% +1.24% (p=0.000 n=9+10) Match_onepass_regex/1M-12 29.5ms ± 0% 30.2ms ± 0% +2.38% (p=0.000 n=10+10) Match_onepass_regex/32M-12 945ms ± 0% 970ms ± 0% +2.60% (p=0.000 n=9+10) CompileOnepass-12 4.67µs ± 0% 4.63µs ± 1% -0.84% (p=0.000 n=10+10) [Geo mean] 24.5µs 23.3µs -5.04% https://perf.golang.org/search?q=upload:20181004.1 Change-Id: Idbc2b76223718265657819ff38be2d9aba1c54b4 Reviewed-on: https://go-review.googlesource.com/c/139779 Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-09-28 16:37:16 -04:00
b.push(re, pc, b.cap[inst.Arg], true) // come back when we're done.
regexp: port RE2's bitstate backtracker to the regexp package This is a port of RE2's bitstate backtracker, which triggers under the same conditions that the RE2 backtracker triggers. However I wasn't sure how to port over some of the optimizations in the RE2 backtracker, and there is a ~2% penalty on benchmarks that don't trigger the backtracker. benchmark old ns/op new ns/op delta BenchmarkLiteral 312 189 -39.42% BenchmarkNotLiteral 4435 3001 -32.33% BenchmarkMatchClass 5758 4378 -23.97% BenchmarkMatchClass_InRange 5385 4084 -24.16% BenchmarkReplaceAll 5291 3505 -33.76% BenchmarkAnchoredLiteralShortNonMatch 190 200 +5.26% BenchmarkAnchoredLiteralLongNonMatch 189 194 +2.65% BenchmarkAnchoredShortMatch 479 304 -36.53% BenchmarkAnchoredLongMatch 478 499 +4.39% BenchmarkOnePassShortA 791 798 +0.88% BenchmarkNotOnePassShortA 3202 1571 -50.94% BenchmarkOnePassShortB 614 633 +3.09% BenchmarkNotOnePassShortB 2685 881 -67.19% BenchmarkOnePassLongPrefix 152 154 +1.32% BenchmarkOnePassLongNotPrefix 505 533 +5.54% BenchmarkMatchEasy0_32 139 171 +23.02% BenchmarkMatchEasy0_1K 653 1797 +175.19% BenchmarkMatchEasy0_32K 12032 13346 +10.92% BenchmarkMatchEasy0_1M 462882 461272 -0.35% BenchmarkMatchEasy0_32M 15015339 15365238 +2.33% BenchmarkMatchEasy1_32 122 168 +37.70% BenchmarkMatchEasy1_1K 3339 2612 -21.77% BenchmarkMatchEasy1_32K 72330 71721 -0.84% BenchmarkMatchEasy1_1M 2545410 2652284 +4.20% BenchmarkMatchEasy1_32M 80072063 82609750 +3.17% BenchmarkMatchMedium_32 2359 1980 -16.07% BenchmarkMatchMedium_1K 75939 58593 -22.84% BenchmarkMatchMedium_32K 2450907 2501106 +2.05% BenchmarkMatchMedium_1M 78707697 80174418 +1.86% BenchmarkMatchMedium_32M 2535146010 2570896441 +1.41% BenchmarkMatchHard_32 4297 2960 -31.11% BenchmarkMatchHard_1K 133592 88997 -33.38% BenchmarkMatchHard_32K 4240445 4336907 +2.27% BenchmarkMatchHard_1M 136187006 139350238 +2.32% BenchmarkMatchHard_32M 4350855890 4478537306 +2.93% benchmark old MB/s new MB/s speedup BenchmarkMatchEasy0_32 228.74 186.11 0.81x BenchmarkMatchEasy0_1K 1565.91 569.64 0.36x BenchmarkMatchEasy0_32K 2723.31 2455.10 0.90x BenchmarkMatchEasy0_1M 2265.32 2273.22 1.00x BenchmarkMatchEasy0_32M 2234.68 2183.79 0.98x BenchmarkMatchEasy1_32 261.08 190.22 0.73x BenchmarkMatchEasy1_1K 306.59 391.91 1.28x BenchmarkMatchEasy1_32K 453.03 456.88 1.01x BenchmarkMatchEasy1_1M 411.95 395.35 0.96x BenchmarkMatchEasy1_32M 419.05 406.18 0.97x BenchmarkMatchMedium_32 13.56 16.16 1.19x BenchmarkMatchMedium_1K 13.48 17.48 1.30x BenchmarkMatchMedium_32K 13.37 13.10 0.98x BenchmarkMatchMedium_1M 13.32 13.08 0.98x BenchmarkMatchMedium_32M 13.24 13.05 0.99x BenchmarkMatchHard_32 7.45 10.81 1.45x BenchmarkMatchHard_1K 7.67 11.51 1.50x BenchmarkMatchHard_32K 7.73 7.56 0.98x BenchmarkMatchHard_1M 7.70 7.52 0.98x BenchmarkMatchHard_32M 7.71 7.49 0.97x Fixes #4154 Change-Id: Iff7fb9507f0872b320d08afc08679751ed1b28bc Reviewed-on: https://go-review.googlesource.com/2153 Reviewed-by: Russ Cox <rsc@golang.org>
2014-12-28 00:17:01 -08:00
b.cap[inst.Arg] = pos
}
pc = inst.Out
goto CheckAndLoop
}
case syntax.InstEmptyWidth:
if syntax.EmptyOp(inst.Arg)&^i.context(pos) != 0 {
continue
}
pc = inst.Out
goto CheckAndLoop
case syntax.InstNop:
pc = inst.Out
goto CheckAndLoop
case syntax.InstMatch:
// We found a match. If the caller doesn't care
// where the match is, no point going further.
if len(b.cap) == 0 {
regexp: split bit-state execution out of machine struct This allows the bit-state executions to have their own pool of allocated structures. A step toward eliminating the per-Regexp machine cache. Note especially the -92% on MatchParallelShared. This is real but not a complete story: the other execution engines still need to be de-shared, but the benchmark was only using bit-state. The tiny slowdowns in unrelated code are noise. name old time/op new time/op delta Find-12 264ns ± 3% 254ns ± 0% -3.86% (p=0.000 n=10+9) FindAllNoMatches-12 140ns ± 2% 135ns ± 0% -3.91% (p=0.000 n=10+9) FindString-12 256ns ± 0% 247ns ± 0% -3.52% (p=0.000 n=8+8) FindSubmatch-12 339ns ± 1% 334ns ± 0% -1.41% (p=0.000 n=9+10) FindStringSubmatch-12 322ns ± 0% 321ns ± 0% -0.21% (p=0.005 n=8+9) Literal-12 100ns ± 2% 92ns ± 0% -8.10% (p=0.000 n=10+9) NotLiteral-12 1.50µs ± 0% 1.47µs ± 0% -1.91% (p=0.000 n=8+9) MatchClass-12 2.18µs ± 0% 2.17µs ± 0% -0.20% (p=0.001 n=10+7) MatchClass_InRange-12 2.12µs ± 0% 2.13µs ± 0% +0.23% (p=0.000 n=10+10) ReplaceAll-12 1.41µs ± 0% 1.39µs ± 0% -1.30% (p=0.000 n=7+10) AnchoredLiteralShortNonMatch-12 89.8ns ± 0% 83.2ns ± 0% -7.35% (p=0.000 n=8+8) AnchoredLiteralLongNonMatch-12 105ns ± 3% 105ns ± 0% ~ (p=0.186 n=10+10) AnchoredShortMatch-12 141ns ± 0% 131ns ± 0% -7.09% (p=0.000 n=9+10) AnchoredLongMatch-12 276ns ± 4% 267ns ± 0% -3.23% (p=0.000 n=10+10) OnePassShortA-12 620ns ± 0% 611ns ± 0% -1.39% (p=0.000 n=10+9) NotOnePassShortA-12 575ns ± 3% 552ns ± 0% -3.97% (p=0.000 n=10+8) OnePassShortB-12 493ns ± 0% 491ns ± 0% -0.33% (p=0.000 n=8+8) NotOnePassShortB-12 423ns ± 0% 412ns ± 0% -2.60% (p=0.000 n=8+9) OnePassLongPrefix-12 112ns ± 0% 112ns ± 0% ~ (all equal) OnePassLongNotPrefix-12 405ns ± 0% 410ns ± 0% +1.23% (p=0.000 n=8+9) MatchParallelShared-12 501ns ± 1% 39ns ± 1% -92.27% (p=0.000 n=10+10) MatchParallelCopied-12 39.1ns ± 0% 39.2ns ± 3% ~ (p=0.785 n=6+10) QuoteMetaAll-12 94.6ns ± 0% 94.6ns ± 0% ~ (p=0.439 n=10+8) QuoteMetaNone-12 52.7ns ± 0% 52.7ns ± 0% ~ (all equal) Match/Easy0/32-12 79.1ns ± 0% 72.9ns ± 0% -7.85% (p=0.000 n=9+9) Match/Easy0/1K-12 307ns ± 1% 298ns ± 0% -2.99% (p=0.000 n=10+6) Match/Easy0/32K-12 4.65µs ± 2% 4.60µs ± 2% ~ (p=0.159 n=10+10) Match/Easy0/1M-12 234µs ± 0% 235µs ± 0% +0.17% (p=0.003 n=10+10) Match/Easy0/32M-12 7.98ms ± 1% 7.96ms ± 0% ~ (p=0.278 n=9+10) Match/Easy0i/32-12 1.13µs ± 1% 1.09µs ± 0% -3.24% (p=0.000 n=9+8) Match/Easy0i/1K-12 32.5µs ± 0% 31.7µs ± 0% -2.66% (p=0.000 n=9+9) Match/Easy0i/32K-12 1.59ms ± 0% 1.61ms ± 0% +0.75% (p=0.000 n=9+9) Match/Easy0i/1M-12 51.0ms ± 0% 51.4ms ± 0% +0.77% (p=0.000 n=10+8) Match/Easy0i/32M-12 1.63s ± 0% 1.65s ± 1% +1.24% (p=0.000 n=7+9) Match/Easy1/32-12 75.1ns ± 1% 67.9ns ± 0% -9.54% (p=0.000 n=8+8) Match/Easy1/1K-12 861ns ± 0% 884ns ± 0% +2.71% (p=0.000 n=8+9) Match/Easy1/32K-12 39.2µs ± 1% 39.2µs ± 0% ~ (p=0.090 n=10+9) Match/Easy1/1M-12 1.38ms ± 0% 1.39ms ± 0% ~ (p=0.095 n=10+9) Match/Easy1/32M-12 44.2ms ± 1% 44.2ms ± 1% ~ (p=0.218 n=10+10) Match/Medium/32-12 1.04µs ± 1% 1.05µs ± 0% +1.05% (p=0.000 n=9+8) Match/Medium/1K-12 31.3µs ± 0% 31.3µs ± 0% -0.14% (p=0.004 n=9+9) Match/Medium/32K-12 1.44ms ± 0% 1.45ms ± 0% +0.18% (p=0.001 n=8+8) Match/Medium/1M-12 46.1ms ± 0% 46.2ms ± 0% +0.13% (p=0.003 n=6+9) Match/Medium/32M-12 1.48s ± 0% 1.48s ± 0% +0.20% (p=0.002 n=9+8) Match/Hard/32-12 1.54µs ± 1% 1.49µs ± 0% -3.60% (p=0.000 n=9+10) Match/Hard/1K-12 46.4µs ± 1% 45.1µs ± 1% -2.78% (p=0.000 n=9+10) Match/Hard/32K-12 2.19ms ± 0% 2.18ms ± 1% -0.51% (p=0.006 n=8+9) Match/Hard/1M-12 70.1ms ± 0% 69.7ms ± 1% -0.52% (p=0.006 n=8+9) Match/Hard/32M-12 2.24s ± 0% 2.23s ± 1% -0.42% (p=0.046 n=8+9) Match/Hard1/32-12 8.17µs ± 1% 7.89µs ± 0% -3.42% (p=0.000 n=8+9) Match/Hard1/1K-12 254µs ± 2% 244µs ± 0% -3.91% (p=0.000 n=9+9) Match/Hard1/32K-12 9.58ms ± 1% 10.35ms ± 0% +8.00% (p=0.000 n=10+10) Match/Hard1/1M-12 306ms ± 1% 331ms ± 0% +8.27% (p=0.000 n=9+8) Match/Hard1/32M-12 9.79s ± 1% 10.60s ± 0% +8.29% (p=0.000 n=9+8) Match_onepass_regex/32-12 808ns ± 0% 812ns ± 0% +0.47% (p=0.000 n=8+10) Match_onepass_regex/1K-12 27.8µs ± 0% 28.5µs ± 0% +2.32% (p=0.000 n=8+10) Match_onepass_regex/32K-12 925µs ± 0% 936µs ± 0% +1.24% (p=0.000 n=9+10) Match_onepass_regex/1M-12 29.5ms ± 0% 30.2ms ± 0% +2.38% (p=0.000 n=10+10) Match_onepass_regex/32M-12 945ms ± 0% 970ms ± 0% +2.60% (p=0.000 n=9+10) CompileOnepass-12 4.67µs ± 0% 4.63µs ± 1% -0.84% (p=0.000 n=10+10) [Geo mean] 24.5µs 23.3µs -5.04% https://perf.golang.org/search?q=upload:20181004.1 Change-Id: Idbc2b76223718265657819ff38be2d9aba1c54b4 Reviewed-on: https://go-review.googlesource.com/c/139779 Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-09-28 16:37:16 -04:00
return true
regexp: port RE2's bitstate backtracker to the regexp package This is a port of RE2's bitstate backtracker, which triggers under the same conditions that the RE2 backtracker triggers. However I wasn't sure how to port over some of the optimizations in the RE2 backtracker, and there is a ~2% penalty on benchmarks that don't trigger the backtracker. benchmark old ns/op new ns/op delta BenchmarkLiteral 312 189 -39.42% BenchmarkNotLiteral 4435 3001 -32.33% BenchmarkMatchClass 5758 4378 -23.97% BenchmarkMatchClass_InRange 5385 4084 -24.16% BenchmarkReplaceAll 5291 3505 -33.76% BenchmarkAnchoredLiteralShortNonMatch 190 200 +5.26% BenchmarkAnchoredLiteralLongNonMatch 189 194 +2.65% BenchmarkAnchoredShortMatch 479 304 -36.53% BenchmarkAnchoredLongMatch 478 499 +4.39% BenchmarkOnePassShortA 791 798 +0.88% BenchmarkNotOnePassShortA 3202 1571 -50.94% BenchmarkOnePassShortB 614 633 +3.09% BenchmarkNotOnePassShortB 2685 881 -67.19% BenchmarkOnePassLongPrefix 152 154 +1.32% BenchmarkOnePassLongNotPrefix 505 533 +5.54% BenchmarkMatchEasy0_32 139 171 +23.02% BenchmarkMatchEasy0_1K 653 1797 +175.19% BenchmarkMatchEasy0_32K 12032 13346 +10.92% BenchmarkMatchEasy0_1M 462882 461272 -0.35% BenchmarkMatchEasy0_32M 15015339 15365238 +2.33% BenchmarkMatchEasy1_32 122 168 +37.70% BenchmarkMatchEasy1_1K 3339 2612 -21.77% BenchmarkMatchEasy1_32K 72330 71721 -0.84% BenchmarkMatchEasy1_1M 2545410 2652284 +4.20% BenchmarkMatchEasy1_32M 80072063 82609750 +3.17% BenchmarkMatchMedium_32 2359 1980 -16.07% BenchmarkMatchMedium_1K 75939 58593 -22.84% BenchmarkMatchMedium_32K 2450907 2501106 +2.05% BenchmarkMatchMedium_1M 78707697 80174418 +1.86% BenchmarkMatchMedium_32M 2535146010 2570896441 +1.41% BenchmarkMatchHard_32 4297 2960 -31.11% BenchmarkMatchHard_1K 133592 88997 -33.38% BenchmarkMatchHard_32K 4240445 4336907 +2.27% BenchmarkMatchHard_1M 136187006 139350238 +2.32% BenchmarkMatchHard_32M 4350855890 4478537306 +2.93% benchmark old MB/s new MB/s speedup BenchmarkMatchEasy0_32 228.74 186.11 0.81x BenchmarkMatchEasy0_1K 1565.91 569.64 0.36x BenchmarkMatchEasy0_32K 2723.31 2455.10 0.90x BenchmarkMatchEasy0_1M 2265.32 2273.22 1.00x BenchmarkMatchEasy0_32M 2234.68 2183.79 0.98x BenchmarkMatchEasy1_32 261.08 190.22 0.73x BenchmarkMatchEasy1_1K 306.59 391.91 1.28x BenchmarkMatchEasy1_32K 453.03 456.88 1.01x BenchmarkMatchEasy1_1M 411.95 395.35 0.96x BenchmarkMatchEasy1_32M 419.05 406.18 0.97x BenchmarkMatchMedium_32 13.56 16.16 1.19x BenchmarkMatchMedium_1K 13.48 17.48 1.30x BenchmarkMatchMedium_32K 13.37 13.10 0.98x BenchmarkMatchMedium_1M 13.32 13.08 0.98x BenchmarkMatchMedium_32M 13.24 13.05 0.99x BenchmarkMatchHard_32 7.45 10.81 1.45x BenchmarkMatchHard_1K 7.67 11.51 1.50x BenchmarkMatchHard_32K 7.73 7.56 0.98x BenchmarkMatchHard_1M 7.70 7.52 0.98x BenchmarkMatchHard_32M 7.71 7.49 0.97x Fixes #4154 Change-Id: Iff7fb9507f0872b320d08afc08679751ed1b28bc Reviewed-on: https://go-review.googlesource.com/2153 Reviewed-by: Russ Cox <rsc@golang.org>
2014-12-28 00:17:01 -08:00
}
// Record best match so far.
// Only need to check end point, because this entire
// call is only considering one start position.
if len(b.cap) > 1 {
b.cap[1] = pos
}
regexp: split bit-state execution out of machine struct This allows the bit-state executions to have their own pool of allocated structures. A step toward eliminating the per-Regexp machine cache. Note especially the -92% on MatchParallelShared. This is real but not a complete story: the other execution engines still need to be de-shared, but the benchmark was only using bit-state. The tiny slowdowns in unrelated code are noise. name old time/op new time/op delta Find-12 264ns ± 3% 254ns ± 0% -3.86% (p=0.000 n=10+9) FindAllNoMatches-12 140ns ± 2% 135ns ± 0% -3.91% (p=0.000 n=10+9) FindString-12 256ns ± 0% 247ns ± 0% -3.52% (p=0.000 n=8+8) FindSubmatch-12 339ns ± 1% 334ns ± 0% -1.41% (p=0.000 n=9+10) FindStringSubmatch-12 322ns ± 0% 321ns ± 0% -0.21% (p=0.005 n=8+9) Literal-12 100ns ± 2% 92ns ± 0% -8.10% (p=0.000 n=10+9) NotLiteral-12 1.50µs ± 0% 1.47µs ± 0% -1.91% (p=0.000 n=8+9) MatchClass-12 2.18µs ± 0% 2.17µs ± 0% -0.20% (p=0.001 n=10+7) MatchClass_InRange-12 2.12µs ± 0% 2.13µs ± 0% +0.23% (p=0.000 n=10+10) ReplaceAll-12 1.41µs ± 0% 1.39µs ± 0% -1.30% (p=0.000 n=7+10) AnchoredLiteralShortNonMatch-12 89.8ns ± 0% 83.2ns ± 0% -7.35% (p=0.000 n=8+8) AnchoredLiteralLongNonMatch-12 105ns ± 3% 105ns ± 0% ~ (p=0.186 n=10+10) AnchoredShortMatch-12 141ns ± 0% 131ns ± 0% -7.09% (p=0.000 n=9+10) AnchoredLongMatch-12 276ns ± 4% 267ns ± 0% -3.23% (p=0.000 n=10+10) OnePassShortA-12 620ns ± 0% 611ns ± 0% -1.39% (p=0.000 n=10+9) NotOnePassShortA-12 575ns ± 3% 552ns ± 0% -3.97% (p=0.000 n=10+8) OnePassShortB-12 493ns ± 0% 491ns ± 0% -0.33% (p=0.000 n=8+8) NotOnePassShortB-12 423ns ± 0% 412ns ± 0% -2.60% (p=0.000 n=8+9) OnePassLongPrefix-12 112ns ± 0% 112ns ± 0% ~ (all equal) OnePassLongNotPrefix-12 405ns ± 0% 410ns ± 0% +1.23% (p=0.000 n=8+9) MatchParallelShared-12 501ns ± 1% 39ns ± 1% -92.27% (p=0.000 n=10+10) MatchParallelCopied-12 39.1ns ± 0% 39.2ns ± 3% ~ (p=0.785 n=6+10) QuoteMetaAll-12 94.6ns ± 0% 94.6ns ± 0% ~ (p=0.439 n=10+8) QuoteMetaNone-12 52.7ns ± 0% 52.7ns ± 0% ~ (all equal) Match/Easy0/32-12 79.1ns ± 0% 72.9ns ± 0% -7.85% (p=0.000 n=9+9) Match/Easy0/1K-12 307ns ± 1% 298ns ± 0% -2.99% (p=0.000 n=10+6) Match/Easy0/32K-12 4.65µs ± 2% 4.60µs ± 2% ~ (p=0.159 n=10+10) Match/Easy0/1M-12 234µs ± 0% 235µs ± 0% +0.17% (p=0.003 n=10+10) Match/Easy0/32M-12 7.98ms ± 1% 7.96ms ± 0% ~ (p=0.278 n=9+10) Match/Easy0i/32-12 1.13µs ± 1% 1.09µs ± 0% -3.24% (p=0.000 n=9+8) Match/Easy0i/1K-12 32.5µs ± 0% 31.7µs ± 0% -2.66% (p=0.000 n=9+9) Match/Easy0i/32K-12 1.59ms ± 0% 1.61ms ± 0% +0.75% (p=0.000 n=9+9) Match/Easy0i/1M-12 51.0ms ± 0% 51.4ms ± 0% +0.77% (p=0.000 n=10+8) Match/Easy0i/32M-12 1.63s ± 0% 1.65s ± 1% +1.24% (p=0.000 n=7+9) Match/Easy1/32-12 75.1ns ± 1% 67.9ns ± 0% -9.54% (p=0.000 n=8+8) Match/Easy1/1K-12 861ns ± 0% 884ns ± 0% +2.71% (p=0.000 n=8+9) Match/Easy1/32K-12 39.2µs ± 1% 39.2µs ± 0% ~ (p=0.090 n=10+9) Match/Easy1/1M-12 1.38ms ± 0% 1.39ms ± 0% ~ (p=0.095 n=10+9) Match/Easy1/32M-12 44.2ms ± 1% 44.2ms ± 1% ~ (p=0.218 n=10+10) Match/Medium/32-12 1.04µs ± 1% 1.05µs ± 0% +1.05% (p=0.000 n=9+8) Match/Medium/1K-12 31.3µs ± 0% 31.3µs ± 0% -0.14% (p=0.004 n=9+9) Match/Medium/32K-12 1.44ms ± 0% 1.45ms ± 0% +0.18% (p=0.001 n=8+8) Match/Medium/1M-12 46.1ms ± 0% 46.2ms ± 0% +0.13% (p=0.003 n=6+9) Match/Medium/32M-12 1.48s ± 0% 1.48s ± 0% +0.20% (p=0.002 n=9+8) Match/Hard/32-12 1.54µs ± 1% 1.49µs ± 0% -3.60% (p=0.000 n=9+10) Match/Hard/1K-12 46.4µs ± 1% 45.1µs ± 1% -2.78% (p=0.000 n=9+10) Match/Hard/32K-12 2.19ms ± 0% 2.18ms ± 1% -0.51% (p=0.006 n=8+9) Match/Hard/1M-12 70.1ms ± 0% 69.7ms ± 1% -0.52% (p=0.006 n=8+9) Match/Hard/32M-12 2.24s ± 0% 2.23s ± 1% -0.42% (p=0.046 n=8+9) Match/Hard1/32-12 8.17µs ± 1% 7.89µs ± 0% -3.42% (p=0.000 n=8+9) Match/Hard1/1K-12 254µs ± 2% 244µs ± 0% -3.91% (p=0.000 n=9+9) Match/Hard1/32K-12 9.58ms ± 1% 10.35ms ± 0% +8.00% (p=0.000 n=10+10) Match/Hard1/1M-12 306ms ± 1% 331ms ± 0% +8.27% (p=0.000 n=9+8) Match/Hard1/32M-12 9.79s ± 1% 10.60s ± 0% +8.29% (p=0.000 n=9+8) Match_onepass_regex/32-12 808ns ± 0% 812ns ± 0% +0.47% (p=0.000 n=8+10) Match_onepass_regex/1K-12 27.8µs ± 0% 28.5µs ± 0% +2.32% (p=0.000 n=8+10) Match_onepass_regex/32K-12 925µs ± 0% 936µs ± 0% +1.24% (p=0.000 n=9+10) Match_onepass_regex/1M-12 29.5ms ± 0% 30.2ms ± 0% +2.38% (p=0.000 n=10+10) Match_onepass_regex/32M-12 945ms ± 0% 970ms ± 0% +2.60% (p=0.000 n=9+10) CompileOnepass-12 4.67µs ± 0% 4.63µs ± 1% -0.84% (p=0.000 n=10+10) [Geo mean] 24.5µs 23.3µs -5.04% https://perf.golang.org/search?q=upload:20181004.1 Change-Id: Idbc2b76223718265657819ff38be2d9aba1c54b4 Reviewed-on: https://go-review.googlesource.com/c/139779 Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-09-28 16:37:16 -04:00
if old := b.matchcap[1]; old == -1 || (longest && pos > 0 && pos > old) {
copy(b.matchcap, b.cap)
regexp: port RE2's bitstate backtracker to the regexp package This is a port of RE2's bitstate backtracker, which triggers under the same conditions that the RE2 backtracker triggers. However I wasn't sure how to port over some of the optimizations in the RE2 backtracker, and there is a ~2% penalty on benchmarks that don't trigger the backtracker. benchmark old ns/op new ns/op delta BenchmarkLiteral 312 189 -39.42% BenchmarkNotLiteral 4435 3001 -32.33% BenchmarkMatchClass 5758 4378 -23.97% BenchmarkMatchClass_InRange 5385 4084 -24.16% BenchmarkReplaceAll 5291 3505 -33.76% BenchmarkAnchoredLiteralShortNonMatch 190 200 +5.26% BenchmarkAnchoredLiteralLongNonMatch 189 194 +2.65% BenchmarkAnchoredShortMatch 479 304 -36.53% BenchmarkAnchoredLongMatch 478 499 +4.39% BenchmarkOnePassShortA 791 798 +0.88% BenchmarkNotOnePassShortA 3202 1571 -50.94% BenchmarkOnePassShortB 614 633 +3.09% BenchmarkNotOnePassShortB 2685 881 -67.19% BenchmarkOnePassLongPrefix 152 154 +1.32% BenchmarkOnePassLongNotPrefix 505 533 +5.54% BenchmarkMatchEasy0_32 139 171 +23.02% BenchmarkMatchEasy0_1K 653 1797 +175.19% BenchmarkMatchEasy0_32K 12032 13346 +10.92% BenchmarkMatchEasy0_1M 462882 461272 -0.35% BenchmarkMatchEasy0_32M 15015339 15365238 +2.33% BenchmarkMatchEasy1_32 122 168 +37.70% BenchmarkMatchEasy1_1K 3339 2612 -21.77% BenchmarkMatchEasy1_32K 72330 71721 -0.84% BenchmarkMatchEasy1_1M 2545410 2652284 +4.20% BenchmarkMatchEasy1_32M 80072063 82609750 +3.17% BenchmarkMatchMedium_32 2359 1980 -16.07% BenchmarkMatchMedium_1K 75939 58593 -22.84% BenchmarkMatchMedium_32K 2450907 2501106 +2.05% BenchmarkMatchMedium_1M 78707697 80174418 +1.86% BenchmarkMatchMedium_32M 2535146010 2570896441 +1.41% BenchmarkMatchHard_32 4297 2960 -31.11% BenchmarkMatchHard_1K 133592 88997 -33.38% BenchmarkMatchHard_32K 4240445 4336907 +2.27% BenchmarkMatchHard_1M 136187006 139350238 +2.32% BenchmarkMatchHard_32M 4350855890 4478537306 +2.93% benchmark old MB/s new MB/s speedup BenchmarkMatchEasy0_32 228.74 186.11 0.81x BenchmarkMatchEasy0_1K 1565.91 569.64 0.36x BenchmarkMatchEasy0_32K 2723.31 2455.10 0.90x BenchmarkMatchEasy0_1M 2265.32 2273.22 1.00x BenchmarkMatchEasy0_32M 2234.68 2183.79 0.98x BenchmarkMatchEasy1_32 261.08 190.22 0.73x BenchmarkMatchEasy1_1K 306.59 391.91 1.28x BenchmarkMatchEasy1_32K 453.03 456.88 1.01x BenchmarkMatchEasy1_1M 411.95 395.35 0.96x BenchmarkMatchEasy1_32M 419.05 406.18 0.97x BenchmarkMatchMedium_32 13.56 16.16 1.19x BenchmarkMatchMedium_1K 13.48 17.48 1.30x BenchmarkMatchMedium_32K 13.37 13.10 0.98x BenchmarkMatchMedium_1M 13.32 13.08 0.98x BenchmarkMatchMedium_32M 13.24 13.05 0.99x BenchmarkMatchHard_32 7.45 10.81 1.45x BenchmarkMatchHard_1K 7.67 11.51 1.50x BenchmarkMatchHard_32K 7.73 7.56 0.98x BenchmarkMatchHard_1M 7.70 7.52 0.98x BenchmarkMatchHard_32M 7.71 7.49 0.97x Fixes #4154 Change-Id: Iff7fb9507f0872b320d08afc08679751ed1b28bc Reviewed-on: https://go-review.googlesource.com/2153 Reviewed-by: Russ Cox <rsc@golang.org>
2014-12-28 00:17:01 -08:00
}
// If going for first match, we're done.
if !longest {
regexp: split bit-state execution out of machine struct This allows the bit-state executions to have their own pool of allocated structures. A step toward eliminating the per-Regexp machine cache. Note especially the -92% on MatchParallelShared. This is real but not a complete story: the other execution engines still need to be de-shared, but the benchmark was only using bit-state. The tiny slowdowns in unrelated code are noise. name old time/op new time/op delta Find-12 264ns ± 3% 254ns ± 0% -3.86% (p=0.000 n=10+9) FindAllNoMatches-12 140ns ± 2% 135ns ± 0% -3.91% (p=0.000 n=10+9) FindString-12 256ns ± 0% 247ns ± 0% -3.52% (p=0.000 n=8+8) FindSubmatch-12 339ns ± 1% 334ns ± 0% -1.41% (p=0.000 n=9+10) FindStringSubmatch-12 322ns ± 0% 321ns ± 0% -0.21% (p=0.005 n=8+9) Literal-12 100ns ± 2% 92ns ± 0% -8.10% (p=0.000 n=10+9) NotLiteral-12 1.50µs ± 0% 1.47µs ± 0% -1.91% (p=0.000 n=8+9) MatchClass-12 2.18µs ± 0% 2.17µs ± 0% -0.20% (p=0.001 n=10+7) MatchClass_InRange-12 2.12µs ± 0% 2.13µs ± 0% +0.23% (p=0.000 n=10+10) ReplaceAll-12 1.41µs ± 0% 1.39µs ± 0% -1.30% (p=0.000 n=7+10) AnchoredLiteralShortNonMatch-12 89.8ns ± 0% 83.2ns ± 0% -7.35% (p=0.000 n=8+8) AnchoredLiteralLongNonMatch-12 105ns ± 3% 105ns ± 0% ~ (p=0.186 n=10+10) AnchoredShortMatch-12 141ns ± 0% 131ns ± 0% -7.09% (p=0.000 n=9+10) AnchoredLongMatch-12 276ns ± 4% 267ns ± 0% -3.23% (p=0.000 n=10+10) OnePassShortA-12 620ns ± 0% 611ns ± 0% -1.39% (p=0.000 n=10+9) NotOnePassShortA-12 575ns ± 3% 552ns ± 0% -3.97% (p=0.000 n=10+8) OnePassShortB-12 493ns ± 0% 491ns ± 0% -0.33% (p=0.000 n=8+8) NotOnePassShortB-12 423ns ± 0% 412ns ± 0% -2.60% (p=0.000 n=8+9) OnePassLongPrefix-12 112ns ± 0% 112ns ± 0% ~ (all equal) OnePassLongNotPrefix-12 405ns ± 0% 410ns ± 0% +1.23% (p=0.000 n=8+9) MatchParallelShared-12 501ns ± 1% 39ns ± 1% -92.27% (p=0.000 n=10+10) MatchParallelCopied-12 39.1ns ± 0% 39.2ns ± 3% ~ (p=0.785 n=6+10) QuoteMetaAll-12 94.6ns ± 0% 94.6ns ± 0% ~ (p=0.439 n=10+8) QuoteMetaNone-12 52.7ns ± 0% 52.7ns ± 0% ~ (all equal) Match/Easy0/32-12 79.1ns ± 0% 72.9ns ± 0% -7.85% (p=0.000 n=9+9) Match/Easy0/1K-12 307ns ± 1% 298ns ± 0% -2.99% (p=0.000 n=10+6) Match/Easy0/32K-12 4.65µs ± 2% 4.60µs ± 2% ~ (p=0.159 n=10+10) Match/Easy0/1M-12 234µs ± 0% 235µs ± 0% +0.17% (p=0.003 n=10+10) Match/Easy0/32M-12 7.98ms ± 1% 7.96ms ± 0% ~ (p=0.278 n=9+10) Match/Easy0i/32-12 1.13µs ± 1% 1.09µs ± 0% -3.24% (p=0.000 n=9+8) Match/Easy0i/1K-12 32.5µs ± 0% 31.7µs ± 0% -2.66% (p=0.000 n=9+9) Match/Easy0i/32K-12 1.59ms ± 0% 1.61ms ± 0% +0.75% (p=0.000 n=9+9) Match/Easy0i/1M-12 51.0ms ± 0% 51.4ms ± 0% +0.77% (p=0.000 n=10+8) Match/Easy0i/32M-12 1.63s ± 0% 1.65s ± 1% +1.24% (p=0.000 n=7+9) Match/Easy1/32-12 75.1ns ± 1% 67.9ns ± 0% -9.54% (p=0.000 n=8+8) Match/Easy1/1K-12 861ns ± 0% 884ns ± 0% +2.71% (p=0.000 n=8+9) Match/Easy1/32K-12 39.2µs ± 1% 39.2µs ± 0% ~ (p=0.090 n=10+9) Match/Easy1/1M-12 1.38ms ± 0% 1.39ms ± 0% ~ (p=0.095 n=10+9) Match/Easy1/32M-12 44.2ms ± 1% 44.2ms ± 1% ~ (p=0.218 n=10+10) Match/Medium/32-12 1.04µs ± 1% 1.05µs ± 0% +1.05% (p=0.000 n=9+8) Match/Medium/1K-12 31.3µs ± 0% 31.3µs ± 0% -0.14% (p=0.004 n=9+9) Match/Medium/32K-12 1.44ms ± 0% 1.45ms ± 0% +0.18% (p=0.001 n=8+8) Match/Medium/1M-12 46.1ms ± 0% 46.2ms ± 0% +0.13% (p=0.003 n=6+9) Match/Medium/32M-12 1.48s ± 0% 1.48s ± 0% +0.20% (p=0.002 n=9+8) Match/Hard/32-12 1.54µs ± 1% 1.49µs ± 0% -3.60% (p=0.000 n=9+10) Match/Hard/1K-12 46.4µs ± 1% 45.1µs ± 1% -2.78% (p=0.000 n=9+10) Match/Hard/32K-12 2.19ms ± 0% 2.18ms ± 1% -0.51% (p=0.006 n=8+9) Match/Hard/1M-12 70.1ms ± 0% 69.7ms ± 1% -0.52% (p=0.006 n=8+9) Match/Hard/32M-12 2.24s ± 0% 2.23s ± 1% -0.42% (p=0.046 n=8+9) Match/Hard1/32-12 8.17µs ± 1% 7.89µs ± 0% -3.42% (p=0.000 n=8+9) Match/Hard1/1K-12 254µs ± 2% 244µs ± 0% -3.91% (p=0.000 n=9+9) Match/Hard1/32K-12 9.58ms ± 1% 10.35ms ± 0% +8.00% (p=0.000 n=10+10) Match/Hard1/1M-12 306ms ± 1% 331ms ± 0% +8.27% (p=0.000 n=9+8) Match/Hard1/32M-12 9.79s ± 1% 10.60s ± 0% +8.29% (p=0.000 n=9+8) Match_onepass_regex/32-12 808ns ± 0% 812ns ± 0% +0.47% (p=0.000 n=8+10) Match_onepass_regex/1K-12 27.8µs ± 0% 28.5µs ± 0% +2.32% (p=0.000 n=8+10) Match_onepass_regex/32K-12 925µs ± 0% 936µs ± 0% +1.24% (p=0.000 n=9+10) Match_onepass_regex/1M-12 29.5ms ± 0% 30.2ms ± 0% +2.38% (p=0.000 n=10+10) Match_onepass_regex/32M-12 945ms ± 0% 970ms ± 0% +2.60% (p=0.000 n=9+10) CompileOnepass-12 4.67µs ± 0% 4.63µs ± 1% -0.84% (p=0.000 n=10+10) [Geo mean] 24.5µs 23.3µs -5.04% https://perf.golang.org/search?q=upload:20181004.1 Change-Id: Idbc2b76223718265657819ff38be2d9aba1c54b4 Reviewed-on: https://go-review.googlesource.com/c/139779 Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-09-28 16:37:16 -04:00
return true
regexp: port RE2's bitstate backtracker to the regexp package This is a port of RE2's bitstate backtracker, which triggers under the same conditions that the RE2 backtracker triggers. However I wasn't sure how to port over some of the optimizations in the RE2 backtracker, and there is a ~2% penalty on benchmarks that don't trigger the backtracker. benchmark old ns/op new ns/op delta BenchmarkLiteral 312 189 -39.42% BenchmarkNotLiteral 4435 3001 -32.33% BenchmarkMatchClass 5758 4378 -23.97% BenchmarkMatchClass_InRange 5385 4084 -24.16% BenchmarkReplaceAll 5291 3505 -33.76% BenchmarkAnchoredLiteralShortNonMatch 190 200 +5.26% BenchmarkAnchoredLiteralLongNonMatch 189 194 +2.65% BenchmarkAnchoredShortMatch 479 304 -36.53% BenchmarkAnchoredLongMatch 478 499 +4.39% BenchmarkOnePassShortA 791 798 +0.88% BenchmarkNotOnePassShortA 3202 1571 -50.94% BenchmarkOnePassShortB 614 633 +3.09% BenchmarkNotOnePassShortB 2685 881 -67.19% BenchmarkOnePassLongPrefix 152 154 +1.32% BenchmarkOnePassLongNotPrefix 505 533 +5.54% BenchmarkMatchEasy0_32 139 171 +23.02% BenchmarkMatchEasy0_1K 653 1797 +175.19% BenchmarkMatchEasy0_32K 12032 13346 +10.92% BenchmarkMatchEasy0_1M 462882 461272 -0.35% BenchmarkMatchEasy0_32M 15015339 15365238 +2.33% BenchmarkMatchEasy1_32 122 168 +37.70% BenchmarkMatchEasy1_1K 3339 2612 -21.77% BenchmarkMatchEasy1_32K 72330 71721 -0.84% BenchmarkMatchEasy1_1M 2545410 2652284 +4.20% BenchmarkMatchEasy1_32M 80072063 82609750 +3.17% BenchmarkMatchMedium_32 2359 1980 -16.07% BenchmarkMatchMedium_1K 75939 58593 -22.84% BenchmarkMatchMedium_32K 2450907 2501106 +2.05% BenchmarkMatchMedium_1M 78707697 80174418 +1.86% BenchmarkMatchMedium_32M 2535146010 2570896441 +1.41% BenchmarkMatchHard_32 4297 2960 -31.11% BenchmarkMatchHard_1K 133592 88997 -33.38% BenchmarkMatchHard_32K 4240445 4336907 +2.27% BenchmarkMatchHard_1M 136187006 139350238 +2.32% BenchmarkMatchHard_32M 4350855890 4478537306 +2.93% benchmark old MB/s new MB/s speedup BenchmarkMatchEasy0_32 228.74 186.11 0.81x BenchmarkMatchEasy0_1K 1565.91 569.64 0.36x BenchmarkMatchEasy0_32K 2723.31 2455.10 0.90x BenchmarkMatchEasy0_1M 2265.32 2273.22 1.00x BenchmarkMatchEasy0_32M 2234.68 2183.79 0.98x BenchmarkMatchEasy1_32 261.08 190.22 0.73x BenchmarkMatchEasy1_1K 306.59 391.91 1.28x BenchmarkMatchEasy1_32K 453.03 456.88 1.01x BenchmarkMatchEasy1_1M 411.95 395.35 0.96x BenchmarkMatchEasy1_32M 419.05 406.18 0.97x BenchmarkMatchMedium_32 13.56 16.16 1.19x BenchmarkMatchMedium_1K 13.48 17.48 1.30x BenchmarkMatchMedium_32K 13.37 13.10 0.98x BenchmarkMatchMedium_1M 13.32 13.08 0.98x BenchmarkMatchMedium_32M 13.24 13.05 0.99x BenchmarkMatchHard_32 7.45 10.81 1.45x BenchmarkMatchHard_1K 7.67 11.51 1.50x BenchmarkMatchHard_32K 7.73 7.56 0.98x BenchmarkMatchHard_1M 7.70 7.52 0.98x BenchmarkMatchHard_32M 7.71 7.49 0.97x Fixes #4154 Change-Id: Iff7fb9507f0872b320d08afc08679751ed1b28bc Reviewed-on: https://go-review.googlesource.com/2153 Reviewed-by: Russ Cox <rsc@golang.org>
2014-12-28 00:17:01 -08:00
}
// If we used the entire text, no longer match is possible.
if pos == b.end {
regexp: split bit-state execution out of machine struct This allows the bit-state executions to have their own pool of allocated structures. A step toward eliminating the per-Regexp machine cache. Note especially the -92% on MatchParallelShared. This is real but not a complete story: the other execution engines still need to be de-shared, but the benchmark was only using bit-state. The tiny slowdowns in unrelated code are noise. name old time/op new time/op delta Find-12 264ns ± 3% 254ns ± 0% -3.86% (p=0.000 n=10+9) FindAllNoMatches-12 140ns ± 2% 135ns ± 0% -3.91% (p=0.000 n=10+9) FindString-12 256ns ± 0% 247ns ± 0% -3.52% (p=0.000 n=8+8) FindSubmatch-12 339ns ± 1% 334ns ± 0% -1.41% (p=0.000 n=9+10) FindStringSubmatch-12 322ns ± 0% 321ns ± 0% -0.21% (p=0.005 n=8+9) Literal-12 100ns ± 2% 92ns ± 0% -8.10% (p=0.000 n=10+9) NotLiteral-12 1.50µs ± 0% 1.47µs ± 0% -1.91% (p=0.000 n=8+9) MatchClass-12 2.18µs ± 0% 2.17µs ± 0% -0.20% (p=0.001 n=10+7) MatchClass_InRange-12 2.12µs ± 0% 2.13µs ± 0% +0.23% (p=0.000 n=10+10) ReplaceAll-12 1.41µs ± 0% 1.39µs ± 0% -1.30% (p=0.000 n=7+10) AnchoredLiteralShortNonMatch-12 89.8ns ± 0% 83.2ns ± 0% -7.35% (p=0.000 n=8+8) AnchoredLiteralLongNonMatch-12 105ns ± 3% 105ns ± 0% ~ (p=0.186 n=10+10) AnchoredShortMatch-12 141ns ± 0% 131ns ± 0% -7.09% (p=0.000 n=9+10) AnchoredLongMatch-12 276ns ± 4% 267ns ± 0% -3.23% (p=0.000 n=10+10) OnePassShortA-12 620ns ± 0% 611ns ± 0% -1.39% (p=0.000 n=10+9) NotOnePassShortA-12 575ns ± 3% 552ns ± 0% -3.97% (p=0.000 n=10+8) OnePassShortB-12 493ns ± 0% 491ns ± 0% -0.33% (p=0.000 n=8+8) NotOnePassShortB-12 423ns ± 0% 412ns ± 0% -2.60% (p=0.000 n=8+9) OnePassLongPrefix-12 112ns ± 0% 112ns ± 0% ~ (all equal) OnePassLongNotPrefix-12 405ns ± 0% 410ns ± 0% +1.23% (p=0.000 n=8+9) MatchParallelShared-12 501ns ± 1% 39ns ± 1% -92.27% (p=0.000 n=10+10) MatchParallelCopied-12 39.1ns ± 0% 39.2ns ± 3% ~ (p=0.785 n=6+10) QuoteMetaAll-12 94.6ns ± 0% 94.6ns ± 0% ~ (p=0.439 n=10+8) QuoteMetaNone-12 52.7ns ± 0% 52.7ns ± 0% ~ (all equal) Match/Easy0/32-12 79.1ns ± 0% 72.9ns ± 0% -7.85% (p=0.000 n=9+9) Match/Easy0/1K-12 307ns ± 1% 298ns ± 0% -2.99% (p=0.000 n=10+6) Match/Easy0/32K-12 4.65µs ± 2% 4.60µs ± 2% ~ (p=0.159 n=10+10) Match/Easy0/1M-12 234µs ± 0% 235µs ± 0% +0.17% (p=0.003 n=10+10) Match/Easy0/32M-12 7.98ms ± 1% 7.96ms ± 0% ~ (p=0.278 n=9+10) Match/Easy0i/32-12 1.13µs ± 1% 1.09µs ± 0% -3.24% (p=0.000 n=9+8) Match/Easy0i/1K-12 32.5µs ± 0% 31.7µs ± 0% -2.66% (p=0.000 n=9+9) Match/Easy0i/32K-12 1.59ms ± 0% 1.61ms ± 0% +0.75% (p=0.000 n=9+9) Match/Easy0i/1M-12 51.0ms ± 0% 51.4ms ± 0% +0.77% (p=0.000 n=10+8) Match/Easy0i/32M-12 1.63s ± 0% 1.65s ± 1% +1.24% (p=0.000 n=7+9) Match/Easy1/32-12 75.1ns ± 1% 67.9ns ± 0% -9.54% (p=0.000 n=8+8) Match/Easy1/1K-12 861ns ± 0% 884ns ± 0% +2.71% (p=0.000 n=8+9) Match/Easy1/32K-12 39.2µs ± 1% 39.2µs ± 0% ~ (p=0.090 n=10+9) Match/Easy1/1M-12 1.38ms ± 0% 1.39ms ± 0% ~ (p=0.095 n=10+9) Match/Easy1/32M-12 44.2ms ± 1% 44.2ms ± 1% ~ (p=0.218 n=10+10) Match/Medium/32-12 1.04µs ± 1% 1.05µs ± 0% +1.05% (p=0.000 n=9+8) Match/Medium/1K-12 31.3µs ± 0% 31.3µs ± 0% -0.14% (p=0.004 n=9+9) Match/Medium/32K-12 1.44ms ± 0% 1.45ms ± 0% +0.18% (p=0.001 n=8+8) Match/Medium/1M-12 46.1ms ± 0% 46.2ms ± 0% +0.13% (p=0.003 n=6+9) Match/Medium/32M-12 1.48s ± 0% 1.48s ± 0% +0.20% (p=0.002 n=9+8) Match/Hard/32-12 1.54µs ± 1% 1.49µs ± 0% -3.60% (p=0.000 n=9+10) Match/Hard/1K-12 46.4µs ± 1% 45.1µs ± 1% -2.78% (p=0.000 n=9+10) Match/Hard/32K-12 2.19ms ± 0% 2.18ms ± 1% -0.51% (p=0.006 n=8+9) Match/Hard/1M-12 70.1ms ± 0% 69.7ms ± 1% -0.52% (p=0.006 n=8+9) Match/Hard/32M-12 2.24s ± 0% 2.23s ± 1% -0.42% (p=0.046 n=8+9) Match/Hard1/32-12 8.17µs ± 1% 7.89µs ± 0% -3.42% (p=0.000 n=8+9) Match/Hard1/1K-12 254µs ± 2% 244µs ± 0% -3.91% (p=0.000 n=9+9) Match/Hard1/32K-12 9.58ms ± 1% 10.35ms ± 0% +8.00% (p=0.000 n=10+10) Match/Hard1/1M-12 306ms ± 1% 331ms ± 0% +8.27% (p=0.000 n=9+8) Match/Hard1/32M-12 9.79s ± 1% 10.60s ± 0% +8.29% (p=0.000 n=9+8) Match_onepass_regex/32-12 808ns ± 0% 812ns ± 0% +0.47% (p=0.000 n=8+10) Match_onepass_regex/1K-12 27.8µs ± 0% 28.5µs ± 0% +2.32% (p=0.000 n=8+10) Match_onepass_regex/32K-12 925µs ± 0% 936µs ± 0% +1.24% (p=0.000 n=9+10) Match_onepass_regex/1M-12 29.5ms ± 0% 30.2ms ± 0% +2.38% (p=0.000 n=10+10) Match_onepass_regex/32M-12 945ms ± 0% 970ms ± 0% +2.60% (p=0.000 n=9+10) CompileOnepass-12 4.67µs ± 0% 4.63µs ± 1% -0.84% (p=0.000 n=10+10) [Geo mean] 24.5µs 23.3µs -5.04% https://perf.golang.org/search?q=upload:20181004.1 Change-Id: Idbc2b76223718265657819ff38be2d9aba1c54b4 Reviewed-on: https://go-review.googlesource.com/c/139779 Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-09-28 16:37:16 -04:00
return true
regexp: port RE2's bitstate backtracker to the regexp package This is a port of RE2's bitstate backtracker, which triggers under the same conditions that the RE2 backtracker triggers. However I wasn't sure how to port over some of the optimizations in the RE2 backtracker, and there is a ~2% penalty on benchmarks that don't trigger the backtracker. benchmark old ns/op new ns/op delta BenchmarkLiteral 312 189 -39.42% BenchmarkNotLiteral 4435 3001 -32.33% BenchmarkMatchClass 5758 4378 -23.97% BenchmarkMatchClass_InRange 5385 4084 -24.16% BenchmarkReplaceAll 5291 3505 -33.76% BenchmarkAnchoredLiteralShortNonMatch 190 200 +5.26% BenchmarkAnchoredLiteralLongNonMatch 189 194 +2.65% BenchmarkAnchoredShortMatch 479 304 -36.53% BenchmarkAnchoredLongMatch 478 499 +4.39% BenchmarkOnePassShortA 791 798 +0.88% BenchmarkNotOnePassShortA 3202 1571 -50.94% BenchmarkOnePassShortB 614 633 +3.09% BenchmarkNotOnePassShortB 2685 881 -67.19% BenchmarkOnePassLongPrefix 152 154 +1.32% BenchmarkOnePassLongNotPrefix 505 533 +5.54% BenchmarkMatchEasy0_32 139 171 +23.02% BenchmarkMatchEasy0_1K 653 1797 +175.19% BenchmarkMatchEasy0_32K 12032 13346 +10.92% BenchmarkMatchEasy0_1M 462882 461272 -0.35% BenchmarkMatchEasy0_32M 15015339 15365238 +2.33% BenchmarkMatchEasy1_32 122 168 +37.70% BenchmarkMatchEasy1_1K 3339 2612 -21.77% BenchmarkMatchEasy1_32K 72330 71721 -0.84% BenchmarkMatchEasy1_1M 2545410 2652284 +4.20% BenchmarkMatchEasy1_32M 80072063 82609750 +3.17% BenchmarkMatchMedium_32 2359 1980 -16.07% BenchmarkMatchMedium_1K 75939 58593 -22.84% BenchmarkMatchMedium_32K 2450907 2501106 +2.05% BenchmarkMatchMedium_1M 78707697 80174418 +1.86% BenchmarkMatchMedium_32M 2535146010 2570896441 +1.41% BenchmarkMatchHard_32 4297 2960 -31.11% BenchmarkMatchHard_1K 133592 88997 -33.38% BenchmarkMatchHard_32K 4240445 4336907 +2.27% BenchmarkMatchHard_1M 136187006 139350238 +2.32% BenchmarkMatchHard_32M 4350855890 4478537306 +2.93% benchmark old MB/s new MB/s speedup BenchmarkMatchEasy0_32 228.74 186.11 0.81x BenchmarkMatchEasy0_1K 1565.91 569.64 0.36x BenchmarkMatchEasy0_32K 2723.31 2455.10 0.90x BenchmarkMatchEasy0_1M 2265.32 2273.22 1.00x BenchmarkMatchEasy0_32M 2234.68 2183.79 0.98x BenchmarkMatchEasy1_32 261.08 190.22 0.73x BenchmarkMatchEasy1_1K 306.59 391.91 1.28x BenchmarkMatchEasy1_32K 453.03 456.88 1.01x BenchmarkMatchEasy1_1M 411.95 395.35 0.96x BenchmarkMatchEasy1_32M 419.05 406.18 0.97x BenchmarkMatchMedium_32 13.56 16.16 1.19x BenchmarkMatchMedium_1K 13.48 17.48 1.30x BenchmarkMatchMedium_32K 13.37 13.10 0.98x BenchmarkMatchMedium_1M 13.32 13.08 0.98x BenchmarkMatchMedium_32M 13.24 13.05 0.99x BenchmarkMatchHard_32 7.45 10.81 1.45x BenchmarkMatchHard_1K 7.67 11.51 1.50x BenchmarkMatchHard_32K 7.73 7.56 0.98x BenchmarkMatchHard_1M 7.70 7.52 0.98x BenchmarkMatchHard_32M 7.71 7.49 0.97x Fixes #4154 Change-Id: Iff7fb9507f0872b320d08afc08679751ed1b28bc Reviewed-on: https://go-review.googlesource.com/2153 Reviewed-by: Russ Cox <rsc@golang.org>
2014-12-28 00:17:01 -08:00
}
// Otherwise, continue on in hope of a longer match.
continue
}
}
regexp: split bit-state execution out of machine struct This allows the bit-state executions to have their own pool of allocated structures. A step toward eliminating the per-Regexp machine cache. Note especially the -92% on MatchParallelShared. This is real but not a complete story: the other execution engines still need to be de-shared, but the benchmark was only using bit-state. The tiny slowdowns in unrelated code are noise. name old time/op new time/op delta Find-12 264ns ± 3% 254ns ± 0% -3.86% (p=0.000 n=10+9) FindAllNoMatches-12 140ns ± 2% 135ns ± 0% -3.91% (p=0.000 n=10+9) FindString-12 256ns ± 0% 247ns ± 0% -3.52% (p=0.000 n=8+8) FindSubmatch-12 339ns ± 1% 334ns ± 0% -1.41% (p=0.000 n=9+10) FindStringSubmatch-12 322ns ± 0% 321ns ± 0% -0.21% (p=0.005 n=8+9) Literal-12 100ns ± 2% 92ns ± 0% -8.10% (p=0.000 n=10+9) NotLiteral-12 1.50µs ± 0% 1.47µs ± 0% -1.91% (p=0.000 n=8+9) MatchClass-12 2.18µs ± 0% 2.17µs ± 0% -0.20% (p=0.001 n=10+7) MatchClass_InRange-12 2.12µs ± 0% 2.13µs ± 0% +0.23% (p=0.000 n=10+10) ReplaceAll-12 1.41µs ± 0% 1.39µs ± 0% -1.30% (p=0.000 n=7+10) AnchoredLiteralShortNonMatch-12 89.8ns ± 0% 83.2ns ± 0% -7.35% (p=0.000 n=8+8) AnchoredLiteralLongNonMatch-12 105ns ± 3% 105ns ± 0% ~ (p=0.186 n=10+10) AnchoredShortMatch-12 141ns ± 0% 131ns ± 0% -7.09% (p=0.000 n=9+10) AnchoredLongMatch-12 276ns ± 4% 267ns ± 0% -3.23% (p=0.000 n=10+10) OnePassShortA-12 620ns ± 0% 611ns ± 0% -1.39% (p=0.000 n=10+9) NotOnePassShortA-12 575ns ± 3% 552ns ± 0% -3.97% (p=0.000 n=10+8) OnePassShortB-12 493ns ± 0% 491ns ± 0% -0.33% (p=0.000 n=8+8) NotOnePassShortB-12 423ns ± 0% 412ns ± 0% -2.60% (p=0.000 n=8+9) OnePassLongPrefix-12 112ns ± 0% 112ns ± 0% ~ (all equal) OnePassLongNotPrefix-12 405ns ± 0% 410ns ± 0% +1.23% (p=0.000 n=8+9) MatchParallelShared-12 501ns ± 1% 39ns ± 1% -92.27% (p=0.000 n=10+10) MatchParallelCopied-12 39.1ns ± 0% 39.2ns ± 3% ~ (p=0.785 n=6+10) QuoteMetaAll-12 94.6ns ± 0% 94.6ns ± 0% ~ (p=0.439 n=10+8) QuoteMetaNone-12 52.7ns ± 0% 52.7ns ± 0% ~ (all equal) Match/Easy0/32-12 79.1ns ± 0% 72.9ns ± 0% -7.85% (p=0.000 n=9+9) Match/Easy0/1K-12 307ns ± 1% 298ns ± 0% -2.99% (p=0.000 n=10+6) Match/Easy0/32K-12 4.65µs ± 2% 4.60µs ± 2% ~ (p=0.159 n=10+10) Match/Easy0/1M-12 234µs ± 0% 235µs ± 0% +0.17% (p=0.003 n=10+10) Match/Easy0/32M-12 7.98ms ± 1% 7.96ms ± 0% ~ (p=0.278 n=9+10) Match/Easy0i/32-12 1.13µs ± 1% 1.09µs ± 0% -3.24% (p=0.000 n=9+8) Match/Easy0i/1K-12 32.5µs ± 0% 31.7µs ± 0% -2.66% (p=0.000 n=9+9) Match/Easy0i/32K-12 1.59ms ± 0% 1.61ms ± 0% +0.75% (p=0.000 n=9+9) Match/Easy0i/1M-12 51.0ms ± 0% 51.4ms ± 0% +0.77% (p=0.000 n=10+8) Match/Easy0i/32M-12 1.63s ± 0% 1.65s ± 1% +1.24% (p=0.000 n=7+9) Match/Easy1/32-12 75.1ns ± 1% 67.9ns ± 0% -9.54% (p=0.000 n=8+8) Match/Easy1/1K-12 861ns ± 0% 884ns ± 0% +2.71% (p=0.000 n=8+9) Match/Easy1/32K-12 39.2µs ± 1% 39.2µs ± 0% ~ (p=0.090 n=10+9) Match/Easy1/1M-12 1.38ms ± 0% 1.39ms ± 0% ~ (p=0.095 n=10+9) Match/Easy1/32M-12 44.2ms ± 1% 44.2ms ± 1% ~ (p=0.218 n=10+10) Match/Medium/32-12 1.04µs ± 1% 1.05µs ± 0% +1.05% (p=0.000 n=9+8) Match/Medium/1K-12 31.3µs ± 0% 31.3µs ± 0% -0.14% (p=0.004 n=9+9) Match/Medium/32K-12 1.44ms ± 0% 1.45ms ± 0% +0.18% (p=0.001 n=8+8) Match/Medium/1M-12 46.1ms ± 0% 46.2ms ± 0% +0.13% (p=0.003 n=6+9) Match/Medium/32M-12 1.48s ± 0% 1.48s ± 0% +0.20% (p=0.002 n=9+8) Match/Hard/32-12 1.54µs ± 1% 1.49µs ± 0% -3.60% (p=0.000 n=9+10) Match/Hard/1K-12 46.4µs ± 1% 45.1µs ± 1% -2.78% (p=0.000 n=9+10) Match/Hard/32K-12 2.19ms ± 0% 2.18ms ± 1% -0.51% (p=0.006 n=8+9) Match/Hard/1M-12 70.1ms ± 0% 69.7ms ± 1% -0.52% (p=0.006 n=8+9) Match/Hard/32M-12 2.24s ± 0% 2.23s ± 1% -0.42% (p=0.046 n=8+9) Match/Hard1/32-12 8.17µs ± 1% 7.89µs ± 0% -3.42% (p=0.000 n=8+9) Match/Hard1/1K-12 254µs ± 2% 244µs ± 0% -3.91% (p=0.000 n=9+9) Match/Hard1/32K-12 9.58ms ± 1% 10.35ms ± 0% +8.00% (p=0.000 n=10+10) Match/Hard1/1M-12 306ms ± 1% 331ms ± 0% +8.27% (p=0.000 n=9+8) Match/Hard1/32M-12 9.79s ± 1% 10.60s ± 0% +8.29% (p=0.000 n=9+8) Match_onepass_regex/32-12 808ns ± 0% 812ns ± 0% +0.47% (p=0.000 n=8+10) Match_onepass_regex/1K-12 27.8µs ± 0% 28.5µs ± 0% +2.32% (p=0.000 n=8+10) Match_onepass_regex/32K-12 925µs ± 0% 936µs ± 0% +1.24% (p=0.000 n=9+10) Match_onepass_regex/1M-12 29.5ms ± 0% 30.2ms ± 0% +2.38% (p=0.000 n=10+10) Match_onepass_regex/32M-12 945ms ± 0% 970ms ± 0% +2.60% (p=0.000 n=9+10) CompileOnepass-12 4.67µs ± 0% 4.63µs ± 1% -0.84% (p=0.000 n=10+10) [Geo mean] 24.5µs 23.3µs -5.04% https://perf.golang.org/search?q=upload:20181004.1 Change-Id: Idbc2b76223718265657819ff38be2d9aba1c54b4 Reviewed-on: https://go-review.googlesource.com/c/139779 Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-09-28 16:37:16 -04:00
return longest && len(b.matchcap) > 1 && b.matchcap[1] >= 0
regexp: port RE2's bitstate backtracker to the regexp package This is a port of RE2's bitstate backtracker, which triggers under the same conditions that the RE2 backtracker triggers. However I wasn't sure how to port over some of the optimizations in the RE2 backtracker, and there is a ~2% penalty on benchmarks that don't trigger the backtracker. benchmark old ns/op new ns/op delta BenchmarkLiteral 312 189 -39.42% BenchmarkNotLiteral 4435 3001 -32.33% BenchmarkMatchClass 5758 4378 -23.97% BenchmarkMatchClass_InRange 5385 4084 -24.16% BenchmarkReplaceAll 5291 3505 -33.76% BenchmarkAnchoredLiteralShortNonMatch 190 200 +5.26% BenchmarkAnchoredLiteralLongNonMatch 189 194 +2.65% BenchmarkAnchoredShortMatch 479 304 -36.53% BenchmarkAnchoredLongMatch 478 499 +4.39% BenchmarkOnePassShortA 791 798 +0.88% BenchmarkNotOnePassShortA 3202 1571 -50.94% BenchmarkOnePassShortB 614 633 +3.09% BenchmarkNotOnePassShortB 2685 881 -67.19% BenchmarkOnePassLongPrefix 152 154 +1.32% BenchmarkOnePassLongNotPrefix 505 533 +5.54% BenchmarkMatchEasy0_32 139 171 +23.02% BenchmarkMatchEasy0_1K 653 1797 +175.19% BenchmarkMatchEasy0_32K 12032 13346 +10.92% BenchmarkMatchEasy0_1M 462882 461272 -0.35% BenchmarkMatchEasy0_32M 15015339 15365238 +2.33% BenchmarkMatchEasy1_32 122 168 +37.70% BenchmarkMatchEasy1_1K 3339 2612 -21.77% BenchmarkMatchEasy1_32K 72330 71721 -0.84% BenchmarkMatchEasy1_1M 2545410 2652284 +4.20% BenchmarkMatchEasy1_32M 80072063 82609750 +3.17% BenchmarkMatchMedium_32 2359 1980 -16.07% BenchmarkMatchMedium_1K 75939 58593 -22.84% BenchmarkMatchMedium_32K 2450907 2501106 +2.05% BenchmarkMatchMedium_1M 78707697 80174418 +1.86% BenchmarkMatchMedium_32M 2535146010 2570896441 +1.41% BenchmarkMatchHard_32 4297 2960 -31.11% BenchmarkMatchHard_1K 133592 88997 -33.38% BenchmarkMatchHard_32K 4240445 4336907 +2.27% BenchmarkMatchHard_1M 136187006 139350238 +2.32% BenchmarkMatchHard_32M 4350855890 4478537306 +2.93% benchmark old MB/s new MB/s speedup BenchmarkMatchEasy0_32 228.74 186.11 0.81x BenchmarkMatchEasy0_1K 1565.91 569.64 0.36x BenchmarkMatchEasy0_32K 2723.31 2455.10 0.90x BenchmarkMatchEasy0_1M 2265.32 2273.22 1.00x BenchmarkMatchEasy0_32M 2234.68 2183.79 0.98x BenchmarkMatchEasy1_32 261.08 190.22 0.73x BenchmarkMatchEasy1_1K 306.59 391.91 1.28x BenchmarkMatchEasy1_32K 453.03 456.88 1.01x BenchmarkMatchEasy1_1M 411.95 395.35 0.96x BenchmarkMatchEasy1_32M 419.05 406.18 0.97x BenchmarkMatchMedium_32 13.56 16.16 1.19x BenchmarkMatchMedium_1K 13.48 17.48 1.30x BenchmarkMatchMedium_32K 13.37 13.10 0.98x BenchmarkMatchMedium_1M 13.32 13.08 0.98x BenchmarkMatchMedium_32M 13.24 13.05 0.99x BenchmarkMatchHard_32 7.45 10.81 1.45x BenchmarkMatchHard_1K 7.67 11.51 1.50x BenchmarkMatchHard_32K 7.73 7.56 0.98x BenchmarkMatchHard_1M 7.70 7.52 0.98x BenchmarkMatchHard_32M 7.71 7.49 0.97x Fixes #4154 Change-Id: Iff7fb9507f0872b320d08afc08679751ed1b28bc Reviewed-on: https://go-review.googlesource.com/2153 Reviewed-by: Russ Cox <rsc@golang.org>
2014-12-28 00:17:01 -08:00
}
// backtrack runs a backtracking search of prog on the input starting at pos.
regexp: split bit-state execution out of machine struct This allows the bit-state executions to have their own pool of allocated structures. A step toward eliminating the per-Regexp machine cache. Note especially the -92% on MatchParallelShared. This is real but not a complete story: the other execution engines still need to be de-shared, but the benchmark was only using bit-state. The tiny slowdowns in unrelated code are noise. name old time/op new time/op delta Find-12 264ns ± 3% 254ns ± 0% -3.86% (p=0.000 n=10+9) FindAllNoMatches-12 140ns ± 2% 135ns ± 0% -3.91% (p=0.000 n=10+9) FindString-12 256ns ± 0% 247ns ± 0% -3.52% (p=0.000 n=8+8) FindSubmatch-12 339ns ± 1% 334ns ± 0% -1.41% (p=0.000 n=9+10) FindStringSubmatch-12 322ns ± 0% 321ns ± 0% -0.21% (p=0.005 n=8+9) Literal-12 100ns ± 2% 92ns ± 0% -8.10% (p=0.000 n=10+9) NotLiteral-12 1.50µs ± 0% 1.47µs ± 0% -1.91% (p=0.000 n=8+9) MatchClass-12 2.18µs ± 0% 2.17µs ± 0% -0.20% (p=0.001 n=10+7) MatchClass_InRange-12 2.12µs ± 0% 2.13µs ± 0% +0.23% (p=0.000 n=10+10) ReplaceAll-12 1.41µs ± 0% 1.39µs ± 0% -1.30% (p=0.000 n=7+10) AnchoredLiteralShortNonMatch-12 89.8ns ± 0% 83.2ns ± 0% -7.35% (p=0.000 n=8+8) AnchoredLiteralLongNonMatch-12 105ns ± 3% 105ns ± 0% ~ (p=0.186 n=10+10) AnchoredShortMatch-12 141ns ± 0% 131ns ± 0% -7.09% (p=0.000 n=9+10) AnchoredLongMatch-12 276ns ± 4% 267ns ± 0% -3.23% (p=0.000 n=10+10) OnePassShortA-12 620ns ± 0% 611ns ± 0% -1.39% (p=0.000 n=10+9) NotOnePassShortA-12 575ns ± 3% 552ns ± 0% -3.97% (p=0.000 n=10+8) OnePassShortB-12 493ns ± 0% 491ns ± 0% -0.33% (p=0.000 n=8+8) NotOnePassShortB-12 423ns ± 0% 412ns ± 0% -2.60% (p=0.000 n=8+9) OnePassLongPrefix-12 112ns ± 0% 112ns ± 0% ~ (all equal) OnePassLongNotPrefix-12 405ns ± 0% 410ns ± 0% +1.23% (p=0.000 n=8+9) MatchParallelShared-12 501ns ± 1% 39ns ± 1% -92.27% (p=0.000 n=10+10) MatchParallelCopied-12 39.1ns ± 0% 39.2ns ± 3% ~ (p=0.785 n=6+10) QuoteMetaAll-12 94.6ns ± 0% 94.6ns ± 0% ~ (p=0.439 n=10+8) QuoteMetaNone-12 52.7ns ± 0% 52.7ns ± 0% ~ (all equal) Match/Easy0/32-12 79.1ns ± 0% 72.9ns ± 0% -7.85% (p=0.000 n=9+9) Match/Easy0/1K-12 307ns ± 1% 298ns ± 0% -2.99% (p=0.000 n=10+6) Match/Easy0/32K-12 4.65µs ± 2% 4.60µs ± 2% ~ (p=0.159 n=10+10) Match/Easy0/1M-12 234µs ± 0% 235µs ± 0% +0.17% (p=0.003 n=10+10) Match/Easy0/32M-12 7.98ms ± 1% 7.96ms ± 0% ~ (p=0.278 n=9+10) Match/Easy0i/32-12 1.13µs ± 1% 1.09µs ± 0% -3.24% (p=0.000 n=9+8) Match/Easy0i/1K-12 32.5µs ± 0% 31.7µs ± 0% -2.66% (p=0.000 n=9+9) Match/Easy0i/32K-12 1.59ms ± 0% 1.61ms ± 0% +0.75% (p=0.000 n=9+9) Match/Easy0i/1M-12 51.0ms ± 0% 51.4ms ± 0% +0.77% (p=0.000 n=10+8) Match/Easy0i/32M-12 1.63s ± 0% 1.65s ± 1% +1.24% (p=0.000 n=7+9) Match/Easy1/32-12 75.1ns ± 1% 67.9ns ± 0% -9.54% (p=0.000 n=8+8) Match/Easy1/1K-12 861ns ± 0% 884ns ± 0% +2.71% (p=0.000 n=8+9) Match/Easy1/32K-12 39.2µs ± 1% 39.2µs ± 0% ~ (p=0.090 n=10+9) Match/Easy1/1M-12 1.38ms ± 0% 1.39ms ± 0% ~ (p=0.095 n=10+9) Match/Easy1/32M-12 44.2ms ± 1% 44.2ms ± 1% ~ (p=0.218 n=10+10) Match/Medium/32-12 1.04µs ± 1% 1.05µs ± 0% +1.05% (p=0.000 n=9+8) Match/Medium/1K-12 31.3µs ± 0% 31.3µs ± 0% -0.14% (p=0.004 n=9+9) Match/Medium/32K-12 1.44ms ± 0% 1.45ms ± 0% +0.18% (p=0.001 n=8+8) Match/Medium/1M-12 46.1ms ± 0% 46.2ms ± 0% +0.13% (p=0.003 n=6+9) Match/Medium/32M-12 1.48s ± 0% 1.48s ± 0% +0.20% (p=0.002 n=9+8) Match/Hard/32-12 1.54µs ± 1% 1.49µs ± 0% -3.60% (p=0.000 n=9+10) Match/Hard/1K-12 46.4µs ± 1% 45.1µs ± 1% -2.78% (p=0.000 n=9+10) Match/Hard/32K-12 2.19ms ± 0% 2.18ms ± 1% -0.51% (p=0.006 n=8+9) Match/Hard/1M-12 70.1ms ± 0% 69.7ms ± 1% -0.52% (p=0.006 n=8+9) Match/Hard/32M-12 2.24s ± 0% 2.23s ± 1% -0.42% (p=0.046 n=8+9) Match/Hard1/32-12 8.17µs ± 1% 7.89µs ± 0% -3.42% (p=0.000 n=8+9) Match/Hard1/1K-12 254µs ± 2% 244µs ± 0% -3.91% (p=0.000 n=9+9) Match/Hard1/32K-12 9.58ms ± 1% 10.35ms ± 0% +8.00% (p=0.000 n=10+10) Match/Hard1/1M-12 306ms ± 1% 331ms ± 0% +8.27% (p=0.000 n=9+8) Match/Hard1/32M-12 9.79s ± 1% 10.60s ± 0% +8.29% (p=0.000 n=9+8) Match_onepass_regex/32-12 808ns ± 0% 812ns ± 0% +0.47% (p=0.000 n=8+10) Match_onepass_regex/1K-12 27.8µs ± 0% 28.5µs ± 0% +2.32% (p=0.000 n=8+10) Match_onepass_regex/32K-12 925µs ± 0% 936µs ± 0% +1.24% (p=0.000 n=9+10) Match_onepass_regex/1M-12 29.5ms ± 0% 30.2ms ± 0% +2.38% (p=0.000 n=10+10) Match_onepass_regex/32M-12 945ms ± 0% 970ms ± 0% +2.60% (p=0.000 n=9+10) CompileOnepass-12 4.67µs ± 0% 4.63µs ± 1% -0.84% (p=0.000 n=10+10) [Geo mean] 24.5µs 23.3µs -5.04% https://perf.golang.org/search?q=upload:20181004.1 Change-Id: Idbc2b76223718265657819ff38be2d9aba1c54b4 Reviewed-on: https://go-review.googlesource.com/c/139779 Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-09-28 16:37:16 -04:00
func (re *Regexp) backtrack(ib []byte, is string, pos int, ncap int, dstCap []int) []int {
startCond := re.cond
regexp: port RE2's bitstate backtracker to the regexp package This is a port of RE2's bitstate backtracker, which triggers under the same conditions that the RE2 backtracker triggers. However I wasn't sure how to port over some of the optimizations in the RE2 backtracker, and there is a ~2% penalty on benchmarks that don't trigger the backtracker. benchmark old ns/op new ns/op delta BenchmarkLiteral 312 189 -39.42% BenchmarkNotLiteral 4435 3001 -32.33% BenchmarkMatchClass 5758 4378 -23.97% BenchmarkMatchClass_InRange 5385 4084 -24.16% BenchmarkReplaceAll 5291 3505 -33.76% BenchmarkAnchoredLiteralShortNonMatch 190 200 +5.26% BenchmarkAnchoredLiteralLongNonMatch 189 194 +2.65% BenchmarkAnchoredShortMatch 479 304 -36.53% BenchmarkAnchoredLongMatch 478 499 +4.39% BenchmarkOnePassShortA 791 798 +0.88% BenchmarkNotOnePassShortA 3202 1571 -50.94% BenchmarkOnePassShortB 614 633 +3.09% BenchmarkNotOnePassShortB 2685 881 -67.19% BenchmarkOnePassLongPrefix 152 154 +1.32% BenchmarkOnePassLongNotPrefix 505 533 +5.54% BenchmarkMatchEasy0_32 139 171 +23.02% BenchmarkMatchEasy0_1K 653 1797 +175.19% BenchmarkMatchEasy0_32K 12032 13346 +10.92% BenchmarkMatchEasy0_1M 462882 461272 -0.35% BenchmarkMatchEasy0_32M 15015339 15365238 +2.33% BenchmarkMatchEasy1_32 122 168 +37.70% BenchmarkMatchEasy1_1K 3339 2612 -21.77% BenchmarkMatchEasy1_32K 72330 71721 -0.84% BenchmarkMatchEasy1_1M 2545410 2652284 +4.20% BenchmarkMatchEasy1_32M 80072063 82609750 +3.17% BenchmarkMatchMedium_32 2359 1980 -16.07% BenchmarkMatchMedium_1K 75939 58593 -22.84% BenchmarkMatchMedium_32K 2450907 2501106 +2.05% BenchmarkMatchMedium_1M 78707697 80174418 +1.86% BenchmarkMatchMedium_32M 2535146010 2570896441 +1.41% BenchmarkMatchHard_32 4297 2960 -31.11% BenchmarkMatchHard_1K 133592 88997 -33.38% BenchmarkMatchHard_32K 4240445 4336907 +2.27% BenchmarkMatchHard_1M 136187006 139350238 +2.32% BenchmarkMatchHard_32M 4350855890 4478537306 +2.93% benchmark old MB/s new MB/s speedup BenchmarkMatchEasy0_32 228.74 186.11 0.81x BenchmarkMatchEasy0_1K 1565.91 569.64 0.36x BenchmarkMatchEasy0_32K 2723.31 2455.10 0.90x BenchmarkMatchEasy0_1M 2265.32 2273.22 1.00x BenchmarkMatchEasy0_32M 2234.68 2183.79 0.98x BenchmarkMatchEasy1_32 261.08 190.22 0.73x BenchmarkMatchEasy1_1K 306.59 391.91 1.28x BenchmarkMatchEasy1_32K 453.03 456.88 1.01x BenchmarkMatchEasy1_1M 411.95 395.35 0.96x BenchmarkMatchEasy1_32M 419.05 406.18 0.97x BenchmarkMatchMedium_32 13.56 16.16 1.19x BenchmarkMatchMedium_1K 13.48 17.48 1.30x BenchmarkMatchMedium_32K 13.37 13.10 0.98x BenchmarkMatchMedium_1M 13.32 13.08 0.98x BenchmarkMatchMedium_32M 13.24 13.05 0.99x BenchmarkMatchHard_32 7.45 10.81 1.45x BenchmarkMatchHard_1K 7.67 11.51 1.50x BenchmarkMatchHard_32K 7.73 7.56 0.98x BenchmarkMatchHard_1M 7.70 7.52 0.98x BenchmarkMatchHard_32M 7.71 7.49 0.97x Fixes #4154 Change-Id: Iff7fb9507f0872b320d08afc08679751ed1b28bc Reviewed-on: https://go-review.googlesource.com/2153 Reviewed-by: Russ Cox <rsc@golang.org>
2014-12-28 00:17:01 -08:00
if startCond == ^syntax.EmptyOp(0) { // impossible
regexp: split bit-state execution out of machine struct This allows the bit-state executions to have their own pool of allocated structures. A step toward eliminating the per-Regexp machine cache. Note especially the -92% on MatchParallelShared. This is real but not a complete story: the other execution engines still need to be de-shared, but the benchmark was only using bit-state. The tiny slowdowns in unrelated code are noise. name old time/op new time/op delta Find-12 264ns ± 3% 254ns ± 0% -3.86% (p=0.000 n=10+9) FindAllNoMatches-12 140ns ± 2% 135ns ± 0% -3.91% (p=0.000 n=10+9) FindString-12 256ns ± 0% 247ns ± 0% -3.52% (p=0.000 n=8+8) FindSubmatch-12 339ns ± 1% 334ns ± 0% -1.41% (p=0.000 n=9+10) FindStringSubmatch-12 322ns ± 0% 321ns ± 0% -0.21% (p=0.005 n=8+9) Literal-12 100ns ± 2% 92ns ± 0% -8.10% (p=0.000 n=10+9) NotLiteral-12 1.50µs ± 0% 1.47µs ± 0% -1.91% (p=0.000 n=8+9) MatchClass-12 2.18µs ± 0% 2.17µs ± 0% -0.20% (p=0.001 n=10+7) MatchClass_InRange-12 2.12µs ± 0% 2.13µs ± 0% +0.23% (p=0.000 n=10+10) ReplaceAll-12 1.41µs ± 0% 1.39µs ± 0% -1.30% (p=0.000 n=7+10) AnchoredLiteralShortNonMatch-12 89.8ns ± 0% 83.2ns ± 0% -7.35% (p=0.000 n=8+8) AnchoredLiteralLongNonMatch-12 105ns ± 3% 105ns ± 0% ~ (p=0.186 n=10+10) AnchoredShortMatch-12 141ns ± 0% 131ns ± 0% -7.09% (p=0.000 n=9+10) AnchoredLongMatch-12 276ns ± 4% 267ns ± 0% -3.23% (p=0.000 n=10+10) OnePassShortA-12 620ns ± 0% 611ns ± 0% -1.39% (p=0.000 n=10+9) NotOnePassShortA-12 575ns ± 3% 552ns ± 0% -3.97% (p=0.000 n=10+8) OnePassShortB-12 493ns ± 0% 491ns ± 0% -0.33% (p=0.000 n=8+8) NotOnePassShortB-12 423ns ± 0% 412ns ± 0% -2.60% (p=0.000 n=8+9) OnePassLongPrefix-12 112ns ± 0% 112ns ± 0% ~ (all equal) OnePassLongNotPrefix-12 405ns ± 0% 410ns ± 0% +1.23% (p=0.000 n=8+9) MatchParallelShared-12 501ns ± 1% 39ns ± 1% -92.27% (p=0.000 n=10+10) MatchParallelCopied-12 39.1ns ± 0% 39.2ns ± 3% ~ (p=0.785 n=6+10) QuoteMetaAll-12 94.6ns ± 0% 94.6ns ± 0% ~ (p=0.439 n=10+8) QuoteMetaNone-12 52.7ns ± 0% 52.7ns ± 0% ~ (all equal) Match/Easy0/32-12 79.1ns ± 0% 72.9ns ± 0% -7.85% (p=0.000 n=9+9) Match/Easy0/1K-12 307ns ± 1% 298ns ± 0% -2.99% (p=0.000 n=10+6) Match/Easy0/32K-12 4.65µs ± 2% 4.60µs ± 2% ~ (p=0.159 n=10+10) Match/Easy0/1M-12 234µs ± 0% 235µs ± 0% +0.17% (p=0.003 n=10+10) Match/Easy0/32M-12 7.98ms ± 1% 7.96ms ± 0% ~ (p=0.278 n=9+10) Match/Easy0i/32-12 1.13µs ± 1% 1.09µs ± 0% -3.24% (p=0.000 n=9+8) Match/Easy0i/1K-12 32.5µs ± 0% 31.7µs ± 0% -2.66% (p=0.000 n=9+9) Match/Easy0i/32K-12 1.59ms ± 0% 1.61ms ± 0% +0.75% (p=0.000 n=9+9) Match/Easy0i/1M-12 51.0ms ± 0% 51.4ms ± 0% +0.77% (p=0.000 n=10+8) Match/Easy0i/32M-12 1.63s ± 0% 1.65s ± 1% +1.24% (p=0.000 n=7+9) Match/Easy1/32-12 75.1ns ± 1% 67.9ns ± 0% -9.54% (p=0.000 n=8+8) Match/Easy1/1K-12 861ns ± 0% 884ns ± 0% +2.71% (p=0.000 n=8+9) Match/Easy1/32K-12 39.2µs ± 1% 39.2µs ± 0% ~ (p=0.090 n=10+9) Match/Easy1/1M-12 1.38ms ± 0% 1.39ms ± 0% ~ (p=0.095 n=10+9) Match/Easy1/32M-12 44.2ms ± 1% 44.2ms ± 1% ~ (p=0.218 n=10+10) Match/Medium/32-12 1.04µs ± 1% 1.05µs ± 0% +1.05% (p=0.000 n=9+8) Match/Medium/1K-12 31.3µs ± 0% 31.3µs ± 0% -0.14% (p=0.004 n=9+9) Match/Medium/32K-12 1.44ms ± 0% 1.45ms ± 0% +0.18% (p=0.001 n=8+8) Match/Medium/1M-12 46.1ms ± 0% 46.2ms ± 0% +0.13% (p=0.003 n=6+9) Match/Medium/32M-12 1.48s ± 0% 1.48s ± 0% +0.20% (p=0.002 n=9+8) Match/Hard/32-12 1.54µs ± 1% 1.49µs ± 0% -3.60% (p=0.000 n=9+10) Match/Hard/1K-12 46.4µs ± 1% 45.1µs ± 1% -2.78% (p=0.000 n=9+10) Match/Hard/32K-12 2.19ms ± 0% 2.18ms ± 1% -0.51% (p=0.006 n=8+9) Match/Hard/1M-12 70.1ms ± 0% 69.7ms ± 1% -0.52% (p=0.006 n=8+9) Match/Hard/32M-12 2.24s ± 0% 2.23s ± 1% -0.42% (p=0.046 n=8+9) Match/Hard1/32-12 8.17µs ± 1% 7.89µs ± 0% -3.42% (p=0.000 n=8+9) Match/Hard1/1K-12 254µs ± 2% 244µs ± 0% -3.91% (p=0.000 n=9+9) Match/Hard1/32K-12 9.58ms ± 1% 10.35ms ± 0% +8.00% (p=0.000 n=10+10) Match/Hard1/1M-12 306ms ± 1% 331ms ± 0% +8.27% (p=0.000 n=9+8) Match/Hard1/32M-12 9.79s ± 1% 10.60s ± 0% +8.29% (p=0.000 n=9+8) Match_onepass_regex/32-12 808ns ± 0% 812ns ± 0% +0.47% (p=0.000 n=8+10) Match_onepass_regex/1K-12 27.8µs ± 0% 28.5µs ± 0% +2.32% (p=0.000 n=8+10) Match_onepass_regex/32K-12 925µs ± 0% 936µs ± 0% +1.24% (p=0.000 n=9+10) Match_onepass_regex/1M-12 29.5ms ± 0% 30.2ms ± 0% +2.38% (p=0.000 n=10+10) Match_onepass_regex/32M-12 945ms ± 0% 970ms ± 0% +2.60% (p=0.000 n=9+10) CompileOnepass-12 4.67µs ± 0% 4.63µs ± 1% -0.84% (p=0.000 n=10+10) [Geo mean] 24.5µs 23.3µs -5.04% https://perf.golang.org/search?q=upload:20181004.1 Change-Id: Idbc2b76223718265657819ff38be2d9aba1c54b4 Reviewed-on: https://go-review.googlesource.com/c/139779 Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-09-28 16:37:16 -04:00
return nil
regexp: port RE2's bitstate backtracker to the regexp package This is a port of RE2's bitstate backtracker, which triggers under the same conditions that the RE2 backtracker triggers. However I wasn't sure how to port over some of the optimizations in the RE2 backtracker, and there is a ~2% penalty on benchmarks that don't trigger the backtracker. benchmark old ns/op new ns/op delta BenchmarkLiteral 312 189 -39.42% BenchmarkNotLiteral 4435 3001 -32.33% BenchmarkMatchClass 5758 4378 -23.97% BenchmarkMatchClass_InRange 5385 4084 -24.16% BenchmarkReplaceAll 5291 3505 -33.76% BenchmarkAnchoredLiteralShortNonMatch 190 200 +5.26% BenchmarkAnchoredLiteralLongNonMatch 189 194 +2.65% BenchmarkAnchoredShortMatch 479 304 -36.53% BenchmarkAnchoredLongMatch 478 499 +4.39% BenchmarkOnePassShortA 791 798 +0.88% BenchmarkNotOnePassShortA 3202 1571 -50.94% BenchmarkOnePassShortB 614 633 +3.09% BenchmarkNotOnePassShortB 2685 881 -67.19% BenchmarkOnePassLongPrefix 152 154 +1.32% BenchmarkOnePassLongNotPrefix 505 533 +5.54% BenchmarkMatchEasy0_32 139 171 +23.02% BenchmarkMatchEasy0_1K 653 1797 +175.19% BenchmarkMatchEasy0_32K 12032 13346 +10.92% BenchmarkMatchEasy0_1M 462882 461272 -0.35% BenchmarkMatchEasy0_32M 15015339 15365238 +2.33% BenchmarkMatchEasy1_32 122 168 +37.70% BenchmarkMatchEasy1_1K 3339 2612 -21.77% BenchmarkMatchEasy1_32K 72330 71721 -0.84% BenchmarkMatchEasy1_1M 2545410 2652284 +4.20% BenchmarkMatchEasy1_32M 80072063 82609750 +3.17% BenchmarkMatchMedium_32 2359 1980 -16.07% BenchmarkMatchMedium_1K 75939 58593 -22.84% BenchmarkMatchMedium_32K 2450907 2501106 +2.05% BenchmarkMatchMedium_1M 78707697 80174418 +1.86% BenchmarkMatchMedium_32M 2535146010 2570896441 +1.41% BenchmarkMatchHard_32 4297 2960 -31.11% BenchmarkMatchHard_1K 133592 88997 -33.38% BenchmarkMatchHard_32K 4240445 4336907 +2.27% BenchmarkMatchHard_1M 136187006 139350238 +2.32% BenchmarkMatchHard_32M 4350855890 4478537306 +2.93% benchmark old MB/s new MB/s speedup BenchmarkMatchEasy0_32 228.74 186.11 0.81x BenchmarkMatchEasy0_1K 1565.91 569.64 0.36x BenchmarkMatchEasy0_32K 2723.31 2455.10 0.90x BenchmarkMatchEasy0_1M 2265.32 2273.22 1.00x BenchmarkMatchEasy0_32M 2234.68 2183.79 0.98x BenchmarkMatchEasy1_32 261.08 190.22 0.73x BenchmarkMatchEasy1_1K 306.59 391.91 1.28x BenchmarkMatchEasy1_32K 453.03 456.88 1.01x BenchmarkMatchEasy1_1M 411.95 395.35 0.96x BenchmarkMatchEasy1_32M 419.05 406.18 0.97x BenchmarkMatchMedium_32 13.56 16.16 1.19x BenchmarkMatchMedium_1K 13.48 17.48 1.30x BenchmarkMatchMedium_32K 13.37 13.10 0.98x BenchmarkMatchMedium_1M 13.32 13.08 0.98x BenchmarkMatchMedium_32M 13.24 13.05 0.99x BenchmarkMatchHard_32 7.45 10.81 1.45x BenchmarkMatchHard_1K 7.67 11.51 1.50x BenchmarkMatchHard_32K 7.73 7.56 0.98x BenchmarkMatchHard_1M 7.70 7.52 0.98x BenchmarkMatchHard_32M 7.71 7.49 0.97x Fixes #4154 Change-Id: Iff7fb9507f0872b320d08afc08679751ed1b28bc Reviewed-on: https://go-review.googlesource.com/2153 Reviewed-by: Russ Cox <rsc@golang.org>
2014-12-28 00:17:01 -08:00
}
if startCond&syntax.EmptyBeginText != 0 && pos != 0 {
// Anchored match, past beginning of text.
regexp: split bit-state execution out of machine struct This allows the bit-state executions to have their own pool of allocated structures. A step toward eliminating the per-Regexp machine cache. Note especially the -92% on MatchParallelShared. This is real but not a complete story: the other execution engines still need to be de-shared, but the benchmark was only using bit-state. The tiny slowdowns in unrelated code are noise. name old time/op new time/op delta Find-12 264ns ± 3% 254ns ± 0% -3.86% (p=0.000 n=10+9) FindAllNoMatches-12 140ns ± 2% 135ns ± 0% -3.91% (p=0.000 n=10+9) FindString-12 256ns ± 0% 247ns ± 0% -3.52% (p=0.000 n=8+8) FindSubmatch-12 339ns ± 1% 334ns ± 0% -1.41% (p=0.000 n=9+10) FindStringSubmatch-12 322ns ± 0% 321ns ± 0% -0.21% (p=0.005 n=8+9) Literal-12 100ns ± 2% 92ns ± 0% -8.10% (p=0.000 n=10+9) NotLiteral-12 1.50µs ± 0% 1.47µs ± 0% -1.91% (p=0.000 n=8+9) MatchClass-12 2.18µs ± 0% 2.17µs ± 0% -0.20% (p=0.001 n=10+7) MatchClass_InRange-12 2.12µs ± 0% 2.13µs ± 0% +0.23% (p=0.000 n=10+10) ReplaceAll-12 1.41µs ± 0% 1.39µs ± 0% -1.30% (p=0.000 n=7+10) AnchoredLiteralShortNonMatch-12 89.8ns ± 0% 83.2ns ± 0% -7.35% (p=0.000 n=8+8) AnchoredLiteralLongNonMatch-12 105ns ± 3% 105ns ± 0% ~ (p=0.186 n=10+10) AnchoredShortMatch-12 141ns ± 0% 131ns ± 0% -7.09% (p=0.000 n=9+10) AnchoredLongMatch-12 276ns ± 4% 267ns ± 0% -3.23% (p=0.000 n=10+10) OnePassShortA-12 620ns ± 0% 611ns ± 0% -1.39% (p=0.000 n=10+9) NotOnePassShortA-12 575ns ± 3% 552ns ± 0% -3.97% (p=0.000 n=10+8) OnePassShortB-12 493ns ± 0% 491ns ± 0% -0.33% (p=0.000 n=8+8) NotOnePassShortB-12 423ns ± 0% 412ns ± 0% -2.60% (p=0.000 n=8+9) OnePassLongPrefix-12 112ns ± 0% 112ns ± 0% ~ (all equal) OnePassLongNotPrefix-12 405ns ± 0% 410ns ± 0% +1.23% (p=0.000 n=8+9) MatchParallelShared-12 501ns ± 1% 39ns ± 1% -92.27% (p=0.000 n=10+10) MatchParallelCopied-12 39.1ns ± 0% 39.2ns ± 3% ~ (p=0.785 n=6+10) QuoteMetaAll-12 94.6ns ± 0% 94.6ns ± 0% ~ (p=0.439 n=10+8) QuoteMetaNone-12 52.7ns ± 0% 52.7ns ± 0% ~ (all equal) Match/Easy0/32-12 79.1ns ± 0% 72.9ns ± 0% -7.85% (p=0.000 n=9+9) Match/Easy0/1K-12 307ns ± 1% 298ns ± 0% -2.99% (p=0.000 n=10+6) Match/Easy0/32K-12 4.65µs ± 2% 4.60µs ± 2% ~ (p=0.159 n=10+10) Match/Easy0/1M-12 234µs ± 0% 235µs ± 0% +0.17% (p=0.003 n=10+10) Match/Easy0/32M-12 7.98ms ± 1% 7.96ms ± 0% ~ (p=0.278 n=9+10) Match/Easy0i/32-12 1.13µs ± 1% 1.09µs ± 0% -3.24% (p=0.000 n=9+8) Match/Easy0i/1K-12 32.5µs ± 0% 31.7µs ± 0% -2.66% (p=0.000 n=9+9) Match/Easy0i/32K-12 1.59ms ± 0% 1.61ms ± 0% +0.75% (p=0.000 n=9+9) Match/Easy0i/1M-12 51.0ms ± 0% 51.4ms ± 0% +0.77% (p=0.000 n=10+8) Match/Easy0i/32M-12 1.63s ± 0% 1.65s ± 1% +1.24% (p=0.000 n=7+9) Match/Easy1/32-12 75.1ns ± 1% 67.9ns ± 0% -9.54% (p=0.000 n=8+8) Match/Easy1/1K-12 861ns ± 0% 884ns ± 0% +2.71% (p=0.000 n=8+9) Match/Easy1/32K-12 39.2µs ± 1% 39.2µs ± 0% ~ (p=0.090 n=10+9) Match/Easy1/1M-12 1.38ms ± 0% 1.39ms ± 0% ~ (p=0.095 n=10+9) Match/Easy1/32M-12 44.2ms ± 1% 44.2ms ± 1% ~ (p=0.218 n=10+10) Match/Medium/32-12 1.04µs ± 1% 1.05µs ± 0% +1.05% (p=0.000 n=9+8) Match/Medium/1K-12 31.3µs ± 0% 31.3µs ± 0% -0.14% (p=0.004 n=9+9) Match/Medium/32K-12 1.44ms ± 0% 1.45ms ± 0% +0.18% (p=0.001 n=8+8) Match/Medium/1M-12 46.1ms ± 0% 46.2ms ± 0% +0.13% (p=0.003 n=6+9) Match/Medium/32M-12 1.48s ± 0% 1.48s ± 0% +0.20% (p=0.002 n=9+8) Match/Hard/32-12 1.54µs ± 1% 1.49µs ± 0% -3.60% (p=0.000 n=9+10) Match/Hard/1K-12 46.4µs ± 1% 45.1µs ± 1% -2.78% (p=0.000 n=9+10) Match/Hard/32K-12 2.19ms ± 0% 2.18ms ± 1% -0.51% (p=0.006 n=8+9) Match/Hard/1M-12 70.1ms ± 0% 69.7ms ± 1% -0.52% (p=0.006 n=8+9) Match/Hard/32M-12 2.24s ± 0% 2.23s ± 1% -0.42% (p=0.046 n=8+9) Match/Hard1/32-12 8.17µs ± 1% 7.89µs ± 0% -3.42% (p=0.000 n=8+9) Match/Hard1/1K-12 254µs ± 2% 244µs ± 0% -3.91% (p=0.000 n=9+9) Match/Hard1/32K-12 9.58ms ± 1% 10.35ms ± 0% +8.00% (p=0.000 n=10+10) Match/Hard1/1M-12 306ms ± 1% 331ms ± 0% +8.27% (p=0.000 n=9+8) Match/Hard1/32M-12 9.79s ± 1% 10.60s ± 0% +8.29% (p=0.000 n=9+8) Match_onepass_regex/32-12 808ns ± 0% 812ns ± 0% +0.47% (p=0.000 n=8+10) Match_onepass_regex/1K-12 27.8µs ± 0% 28.5µs ± 0% +2.32% (p=0.000 n=8+10) Match_onepass_regex/32K-12 925µs ± 0% 936µs ± 0% +1.24% (p=0.000 n=9+10) Match_onepass_regex/1M-12 29.5ms ± 0% 30.2ms ± 0% +2.38% (p=0.000 n=10+10) Match_onepass_regex/32M-12 945ms ± 0% 970ms ± 0% +2.60% (p=0.000 n=9+10) CompileOnepass-12 4.67µs ± 0% 4.63µs ± 1% -0.84% (p=0.000 n=10+10) [Geo mean] 24.5µs 23.3µs -5.04% https://perf.golang.org/search?q=upload:20181004.1 Change-Id: Idbc2b76223718265657819ff38be2d9aba1c54b4 Reviewed-on: https://go-review.googlesource.com/c/139779 Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-09-28 16:37:16 -04:00
return nil
regexp: port RE2's bitstate backtracker to the regexp package This is a port of RE2's bitstate backtracker, which triggers under the same conditions that the RE2 backtracker triggers. However I wasn't sure how to port over some of the optimizations in the RE2 backtracker, and there is a ~2% penalty on benchmarks that don't trigger the backtracker. benchmark old ns/op new ns/op delta BenchmarkLiteral 312 189 -39.42% BenchmarkNotLiteral 4435 3001 -32.33% BenchmarkMatchClass 5758 4378 -23.97% BenchmarkMatchClass_InRange 5385 4084 -24.16% BenchmarkReplaceAll 5291 3505 -33.76% BenchmarkAnchoredLiteralShortNonMatch 190 200 +5.26% BenchmarkAnchoredLiteralLongNonMatch 189 194 +2.65% BenchmarkAnchoredShortMatch 479 304 -36.53% BenchmarkAnchoredLongMatch 478 499 +4.39% BenchmarkOnePassShortA 791 798 +0.88% BenchmarkNotOnePassShortA 3202 1571 -50.94% BenchmarkOnePassShortB 614 633 +3.09% BenchmarkNotOnePassShortB 2685 881 -67.19% BenchmarkOnePassLongPrefix 152 154 +1.32% BenchmarkOnePassLongNotPrefix 505 533 +5.54% BenchmarkMatchEasy0_32 139 171 +23.02% BenchmarkMatchEasy0_1K 653 1797 +175.19% BenchmarkMatchEasy0_32K 12032 13346 +10.92% BenchmarkMatchEasy0_1M 462882 461272 -0.35% BenchmarkMatchEasy0_32M 15015339 15365238 +2.33% BenchmarkMatchEasy1_32 122 168 +37.70% BenchmarkMatchEasy1_1K 3339 2612 -21.77% BenchmarkMatchEasy1_32K 72330 71721 -0.84% BenchmarkMatchEasy1_1M 2545410 2652284 +4.20% BenchmarkMatchEasy1_32M 80072063 82609750 +3.17% BenchmarkMatchMedium_32 2359 1980 -16.07% BenchmarkMatchMedium_1K 75939 58593 -22.84% BenchmarkMatchMedium_32K 2450907 2501106 +2.05% BenchmarkMatchMedium_1M 78707697 80174418 +1.86% BenchmarkMatchMedium_32M 2535146010 2570896441 +1.41% BenchmarkMatchHard_32 4297 2960 -31.11% BenchmarkMatchHard_1K 133592 88997 -33.38% BenchmarkMatchHard_32K 4240445 4336907 +2.27% BenchmarkMatchHard_1M 136187006 139350238 +2.32% BenchmarkMatchHard_32M 4350855890 4478537306 +2.93% benchmark old MB/s new MB/s speedup BenchmarkMatchEasy0_32 228.74 186.11 0.81x BenchmarkMatchEasy0_1K 1565.91 569.64 0.36x BenchmarkMatchEasy0_32K 2723.31 2455.10 0.90x BenchmarkMatchEasy0_1M 2265.32 2273.22 1.00x BenchmarkMatchEasy0_32M 2234.68 2183.79 0.98x BenchmarkMatchEasy1_32 261.08 190.22 0.73x BenchmarkMatchEasy1_1K 306.59 391.91 1.28x BenchmarkMatchEasy1_32K 453.03 456.88 1.01x BenchmarkMatchEasy1_1M 411.95 395.35 0.96x BenchmarkMatchEasy1_32M 419.05 406.18 0.97x BenchmarkMatchMedium_32 13.56 16.16 1.19x BenchmarkMatchMedium_1K 13.48 17.48 1.30x BenchmarkMatchMedium_32K 13.37 13.10 0.98x BenchmarkMatchMedium_1M 13.32 13.08 0.98x BenchmarkMatchMedium_32M 13.24 13.05 0.99x BenchmarkMatchHard_32 7.45 10.81 1.45x BenchmarkMatchHard_1K 7.67 11.51 1.50x BenchmarkMatchHard_32K 7.73 7.56 0.98x BenchmarkMatchHard_1M 7.70 7.52 0.98x BenchmarkMatchHard_32M 7.71 7.49 0.97x Fixes #4154 Change-Id: Iff7fb9507f0872b320d08afc08679751ed1b28bc Reviewed-on: https://go-review.googlesource.com/2153 Reviewed-by: Russ Cox <rsc@golang.org>
2014-12-28 00:17:01 -08:00
}
regexp: split bit-state execution out of machine struct This allows the bit-state executions to have their own pool of allocated structures. A step toward eliminating the per-Regexp machine cache. Note especially the -92% on MatchParallelShared. This is real but not a complete story: the other execution engines still need to be de-shared, but the benchmark was only using bit-state. The tiny slowdowns in unrelated code are noise. name old time/op new time/op delta Find-12 264ns ± 3% 254ns ± 0% -3.86% (p=0.000 n=10+9) FindAllNoMatches-12 140ns ± 2% 135ns ± 0% -3.91% (p=0.000 n=10+9) FindString-12 256ns ± 0% 247ns ± 0% -3.52% (p=0.000 n=8+8) FindSubmatch-12 339ns ± 1% 334ns ± 0% -1.41% (p=0.000 n=9+10) FindStringSubmatch-12 322ns ± 0% 321ns ± 0% -0.21% (p=0.005 n=8+9) Literal-12 100ns ± 2% 92ns ± 0% -8.10% (p=0.000 n=10+9) NotLiteral-12 1.50µs ± 0% 1.47µs ± 0% -1.91% (p=0.000 n=8+9) MatchClass-12 2.18µs ± 0% 2.17µs ± 0% -0.20% (p=0.001 n=10+7) MatchClass_InRange-12 2.12µs ± 0% 2.13µs ± 0% +0.23% (p=0.000 n=10+10) ReplaceAll-12 1.41µs ± 0% 1.39µs ± 0% -1.30% (p=0.000 n=7+10) AnchoredLiteralShortNonMatch-12 89.8ns ± 0% 83.2ns ± 0% -7.35% (p=0.000 n=8+8) AnchoredLiteralLongNonMatch-12 105ns ± 3% 105ns ± 0% ~ (p=0.186 n=10+10) AnchoredShortMatch-12 141ns ± 0% 131ns ± 0% -7.09% (p=0.000 n=9+10) AnchoredLongMatch-12 276ns ± 4% 267ns ± 0% -3.23% (p=0.000 n=10+10) OnePassShortA-12 620ns ± 0% 611ns ± 0% -1.39% (p=0.000 n=10+9) NotOnePassShortA-12 575ns ± 3% 552ns ± 0% -3.97% (p=0.000 n=10+8) OnePassShortB-12 493ns ± 0% 491ns ± 0% -0.33% (p=0.000 n=8+8) NotOnePassShortB-12 423ns ± 0% 412ns ± 0% -2.60% (p=0.000 n=8+9) OnePassLongPrefix-12 112ns ± 0% 112ns ± 0% ~ (all equal) OnePassLongNotPrefix-12 405ns ± 0% 410ns ± 0% +1.23% (p=0.000 n=8+9) MatchParallelShared-12 501ns ± 1% 39ns ± 1% -92.27% (p=0.000 n=10+10) MatchParallelCopied-12 39.1ns ± 0% 39.2ns ± 3% ~ (p=0.785 n=6+10) QuoteMetaAll-12 94.6ns ± 0% 94.6ns ± 0% ~ (p=0.439 n=10+8) QuoteMetaNone-12 52.7ns ± 0% 52.7ns ± 0% ~ (all equal) Match/Easy0/32-12 79.1ns ± 0% 72.9ns ± 0% -7.85% (p=0.000 n=9+9) Match/Easy0/1K-12 307ns ± 1% 298ns ± 0% -2.99% (p=0.000 n=10+6) Match/Easy0/32K-12 4.65µs ± 2% 4.60µs ± 2% ~ (p=0.159 n=10+10) Match/Easy0/1M-12 234µs ± 0% 235µs ± 0% +0.17% (p=0.003 n=10+10) Match/Easy0/32M-12 7.98ms ± 1% 7.96ms ± 0% ~ (p=0.278 n=9+10) Match/Easy0i/32-12 1.13µs ± 1% 1.09µs ± 0% -3.24% (p=0.000 n=9+8) Match/Easy0i/1K-12 32.5µs ± 0% 31.7µs ± 0% -2.66% (p=0.000 n=9+9) Match/Easy0i/32K-12 1.59ms ± 0% 1.61ms ± 0% +0.75% (p=0.000 n=9+9) Match/Easy0i/1M-12 51.0ms ± 0% 51.4ms ± 0% +0.77% (p=0.000 n=10+8) Match/Easy0i/32M-12 1.63s ± 0% 1.65s ± 1% +1.24% (p=0.000 n=7+9) Match/Easy1/32-12 75.1ns ± 1% 67.9ns ± 0% -9.54% (p=0.000 n=8+8) Match/Easy1/1K-12 861ns ± 0% 884ns ± 0% +2.71% (p=0.000 n=8+9) Match/Easy1/32K-12 39.2µs ± 1% 39.2µs ± 0% ~ (p=0.090 n=10+9) Match/Easy1/1M-12 1.38ms ± 0% 1.39ms ± 0% ~ (p=0.095 n=10+9) Match/Easy1/32M-12 44.2ms ± 1% 44.2ms ± 1% ~ (p=0.218 n=10+10) Match/Medium/32-12 1.04µs ± 1% 1.05µs ± 0% +1.05% (p=0.000 n=9+8) Match/Medium/1K-12 31.3µs ± 0% 31.3µs ± 0% -0.14% (p=0.004 n=9+9) Match/Medium/32K-12 1.44ms ± 0% 1.45ms ± 0% +0.18% (p=0.001 n=8+8) Match/Medium/1M-12 46.1ms ± 0% 46.2ms ± 0% +0.13% (p=0.003 n=6+9) Match/Medium/32M-12 1.48s ± 0% 1.48s ± 0% +0.20% (p=0.002 n=9+8) Match/Hard/32-12 1.54µs ± 1% 1.49µs ± 0% -3.60% (p=0.000 n=9+10) Match/Hard/1K-12 46.4µs ± 1% 45.1µs ± 1% -2.78% (p=0.000 n=9+10) Match/Hard/32K-12 2.19ms ± 0% 2.18ms ± 1% -0.51% (p=0.006 n=8+9) Match/Hard/1M-12 70.1ms ± 0% 69.7ms ± 1% -0.52% (p=0.006 n=8+9) Match/Hard/32M-12 2.24s ± 0% 2.23s ± 1% -0.42% (p=0.046 n=8+9) Match/Hard1/32-12 8.17µs ± 1% 7.89µs ± 0% -3.42% (p=0.000 n=8+9) Match/Hard1/1K-12 254µs ± 2% 244µs ± 0% -3.91% (p=0.000 n=9+9) Match/Hard1/32K-12 9.58ms ± 1% 10.35ms ± 0% +8.00% (p=0.000 n=10+10) Match/Hard1/1M-12 306ms ± 1% 331ms ± 0% +8.27% (p=0.000 n=9+8) Match/Hard1/32M-12 9.79s ± 1% 10.60s ± 0% +8.29% (p=0.000 n=9+8) Match_onepass_regex/32-12 808ns ± 0% 812ns ± 0% +0.47% (p=0.000 n=8+10) Match_onepass_regex/1K-12 27.8µs ± 0% 28.5µs ± 0% +2.32% (p=0.000 n=8+10) Match_onepass_regex/32K-12 925µs ± 0% 936µs ± 0% +1.24% (p=0.000 n=9+10) Match_onepass_regex/1M-12 29.5ms ± 0% 30.2ms ± 0% +2.38% (p=0.000 n=10+10) Match_onepass_regex/32M-12 945ms ± 0% 970ms ± 0% +2.60% (p=0.000 n=9+10) CompileOnepass-12 4.67µs ± 0% 4.63µs ± 1% -0.84% (p=0.000 n=10+10) [Geo mean] 24.5µs 23.3µs -5.04% https://perf.golang.org/search?q=upload:20181004.1 Change-Id: Idbc2b76223718265657819ff38be2d9aba1c54b4 Reviewed-on: https://go-review.googlesource.com/c/139779 Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-09-28 16:37:16 -04:00
b := newBitState()
i, end := b.inputs.init(nil, ib, is)
b.reset(re.prog, end, ncap)
regexp: port RE2's bitstate backtracker to the regexp package This is a port of RE2's bitstate backtracker, which triggers under the same conditions that the RE2 backtracker triggers. However I wasn't sure how to port over some of the optimizations in the RE2 backtracker, and there is a ~2% penalty on benchmarks that don't trigger the backtracker. benchmark old ns/op new ns/op delta BenchmarkLiteral 312 189 -39.42% BenchmarkNotLiteral 4435 3001 -32.33% BenchmarkMatchClass 5758 4378 -23.97% BenchmarkMatchClass_InRange 5385 4084 -24.16% BenchmarkReplaceAll 5291 3505 -33.76% BenchmarkAnchoredLiteralShortNonMatch 190 200 +5.26% BenchmarkAnchoredLiteralLongNonMatch 189 194 +2.65% BenchmarkAnchoredShortMatch 479 304 -36.53% BenchmarkAnchoredLongMatch 478 499 +4.39% BenchmarkOnePassShortA 791 798 +0.88% BenchmarkNotOnePassShortA 3202 1571 -50.94% BenchmarkOnePassShortB 614 633 +3.09% BenchmarkNotOnePassShortB 2685 881 -67.19% BenchmarkOnePassLongPrefix 152 154 +1.32% BenchmarkOnePassLongNotPrefix 505 533 +5.54% BenchmarkMatchEasy0_32 139 171 +23.02% BenchmarkMatchEasy0_1K 653 1797 +175.19% BenchmarkMatchEasy0_32K 12032 13346 +10.92% BenchmarkMatchEasy0_1M 462882 461272 -0.35% BenchmarkMatchEasy0_32M 15015339 15365238 +2.33% BenchmarkMatchEasy1_32 122 168 +37.70% BenchmarkMatchEasy1_1K 3339 2612 -21.77% BenchmarkMatchEasy1_32K 72330 71721 -0.84% BenchmarkMatchEasy1_1M 2545410 2652284 +4.20% BenchmarkMatchEasy1_32M 80072063 82609750 +3.17% BenchmarkMatchMedium_32 2359 1980 -16.07% BenchmarkMatchMedium_1K 75939 58593 -22.84% BenchmarkMatchMedium_32K 2450907 2501106 +2.05% BenchmarkMatchMedium_1M 78707697 80174418 +1.86% BenchmarkMatchMedium_32M 2535146010 2570896441 +1.41% BenchmarkMatchHard_32 4297 2960 -31.11% BenchmarkMatchHard_1K 133592 88997 -33.38% BenchmarkMatchHard_32K 4240445 4336907 +2.27% BenchmarkMatchHard_1M 136187006 139350238 +2.32% BenchmarkMatchHard_32M 4350855890 4478537306 +2.93% benchmark old MB/s new MB/s speedup BenchmarkMatchEasy0_32 228.74 186.11 0.81x BenchmarkMatchEasy0_1K 1565.91 569.64 0.36x BenchmarkMatchEasy0_32K 2723.31 2455.10 0.90x BenchmarkMatchEasy0_1M 2265.32 2273.22 1.00x BenchmarkMatchEasy0_32M 2234.68 2183.79 0.98x BenchmarkMatchEasy1_32 261.08 190.22 0.73x BenchmarkMatchEasy1_1K 306.59 391.91 1.28x BenchmarkMatchEasy1_32K 453.03 456.88 1.01x BenchmarkMatchEasy1_1M 411.95 395.35 0.96x BenchmarkMatchEasy1_32M 419.05 406.18 0.97x BenchmarkMatchMedium_32 13.56 16.16 1.19x BenchmarkMatchMedium_1K 13.48 17.48 1.30x BenchmarkMatchMedium_32K 13.37 13.10 0.98x BenchmarkMatchMedium_1M 13.32 13.08 0.98x BenchmarkMatchMedium_32M 13.24 13.05 0.99x BenchmarkMatchHard_32 7.45 10.81 1.45x BenchmarkMatchHard_1K 7.67 11.51 1.50x BenchmarkMatchHard_32K 7.73 7.56 0.98x BenchmarkMatchHard_1M 7.70 7.52 0.98x BenchmarkMatchHard_32M 7.71 7.49 0.97x Fixes #4154 Change-Id: Iff7fb9507f0872b320d08afc08679751ed1b28bc Reviewed-on: https://go-review.googlesource.com/2153 Reviewed-by: Russ Cox <rsc@golang.org>
2014-12-28 00:17:01 -08:00
// Anchored search must start at the beginning of the input
if startCond&syntax.EmptyBeginText != 0 {
if len(b.cap) > 0 {
b.cap[0] = pos
}
regexp: split bit-state execution out of machine struct This allows the bit-state executions to have their own pool of allocated structures. A step toward eliminating the per-Regexp machine cache. Note especially the -92% on MatchParallelShared. This is real but not a complete story: the other execution engines still need to be de-shared, but the benchmark was only using bit-state. The tiny slowdowns in unrelated code are noise. name old time/op new time/op delta Find-12 264ns ± 3% 254ns ± 0% -3.86% (p=0.000 n=10+9) FindAllNoMatches-12 140ns ± 2% 135ns ± 0% -3.91% (p=0.000 n=10+9) FindString-12 256ns ± 0% 247ns ± 0% -3.52% (p=0.000 n=8+8) FindSubmatch-12 339ns ± 1% 334ns ± 0% -1.41% (p=0.000 n=9+10) FindStringSubmatch-12 322ns ± 0% 321ns ± 0% -0.21% (p=0.005 n=8+9) Literal-12 100ns ± 2% 92ns ± 0% -8.10% (p=0.000 n=10+9) NotLiteral-12 1.50µs ± 0% 1.47µs ± 0% -1.91% (p=0.000 n=8+9) MatchClass-12 2.18µs ± 0% 2.17µs ± 0% -0.20% (p=0.001 n=10+7) MatchClass_InRange-12 2.12µs ± 0% 2.13µs ± 0% +0.23% (p=0.000 n=10+10) ReplaceAll-12 1.41µs ± 0% 1.39µs ± 0% -1.30% (p=0.000 n=7+10) AnchoredLiteralShortNonMatch-12 89.8ns ± 0% 83.2ns ± 0% -7.35% (p=0.000 n=8+8) AnchoredLiteralLongNonMatch-12 105ns ± 3% 105ns ± 0% ~ (p=0.186 n=10+10) AnchoredShortMatch-12 141ns ± 0% 131ns ± 0% -7.09% (p=0.000 n=9+10) AnchoredLongMatch-12 276ns ± 4% 267ns ± 0% -3.23% (p=0.000 n=10+10) OnePassShortA-12 620ns ± 0% 611ns ± 0% -1.39% (p=0.000 n=10+9) NotOnePassShortA-12 575ns ± 3% 552ns ± 0% -3.97% (p=0.000 n=10+8) OnePassShortB-12 493ns ± 0% 491ns ± 0% -0.33% (p=0.000 n=8+8) NotOnePassShortB-12 423ns ± 0% 412ns ± 0% -2.60% (p=0.000 n=8+9) OnePassLongPrefix-12 112ns ± 0% 112ns ± 0% ~ (all equal) OnePassLongNotPrefix-12 405ns ± 0% 410ns ± 0% +1.23% (p=0.000 n=8+9) MatchParallelShared-12 501ns ± 1% 39ns ± 1% -92.27% (p=0.000 n=10+10) MatchParallelCopied-12 39.1ns ± 0% 39.2ns ± 3% ~ (p=0.785 n=6+10) QuoteMetaAll-12 94.6ns ± 0% 94.6ns ± 0% ~ (p=0.439 n=10+8) QuoteMetaNone-12 52.7ns ± 0% 52.7ns ± 0% ~ (all equal) Match/Easy0/32-12 79.1ns ± 0% 72.9ns ± 0% -7.85% (p=0.000 n=9+9) Match/Easy0/1K-12 307ns ± 1% 298ns ± 0% -2.99% (p=0.000 n=10+6) Match/Easy0/32K-12 4.65µs ± 2% 4.60µs ± 2% ~ (p=0.159 n=10+10) Match/Easy0/1M-12 234µs ± 0% 235µs ± 0% +0.17% (p=0.003 n=10+10) Match/Easy0/32M-12 7.98ms ± 1% 7.96ms ± 0% ~ (p=0.278 n=9+10) Match/Easy0i/32-12 1.13µs ± 1% 1.09µs ± 0% -3.24% (p=0.000 n=9+8) Match/Easy0i/1K-12 32.5µs ± 0% 31.7µs ± 0% -2.66% (p=0.000 n=9+9) Match/Easy0i/32K-12 1.59ms ± 0% 1.61ms ± 0% +0.75% (p=0.000 n=9+9) Match/Easy0i/1M-12 51.0ms ± 0% 51.4ms ± 0% +0.77% (p=0.000 n=10+8) Match/Easy0i/32M-12 1.63s ± 0% 1.65s ± 1% +1.24% (p=0.000 n=7+9) Match/Easy1/32-12 75.1ns ± 1% 67.9ns ± 0% -9.54% (p=0.000 n=8+8) Match/Easy1/1K-12 861ns ± 0% 884ns ± 0% +2.71% (p=0.000 n=8+9) Match/Easy1/32K-12 39.2µs ± 1% 39.2µs ± 0% ~ (p=0.090 n=10+9) Match/Easy1/1M-12 1.38ms ± 0% 1.39ms ± 0% ~ (p=0.095 n=10+9) Match/Easy1/32M-12 44.2ms ± 1% 44.2ms ± 1% ~ (p=0.218 n=10+10) Match/Medium/32-12 1.04µs ± 1% 1.05µs ± 0% +1.05% (p=0.000 n=9+8) Match/Medium/1K-12 31.3µs ± 0% 31.3µs ± 0% -0.14% (p=0.004 n=9+9) Match/Medium/32K-12 1.44ms ± 0% 1.45ms ± 0% +0.18% (p=0.001 n=8+8) Match/Medium/1M-12 46.1ms ± 0% 46.2ms ± 0% +0.13% (p=0.003 n=6+9) Match/Medium/32M-12 1.48s ± 0% 1.48s ± 0% +0.20% (p=0.002 n=9+8) Match/Hard/32-12 1.54µs ± 1% 1.49µs ± 0% -3.60% (p=0.000 n=9+10) Match/Hard/1K-12 46.4µs ± 1% 45.1µs ± 1% -2.78% (p=0.000 n=9+10) Match/Hard/32K-12 2.19ms ± 0% 2.18ms ± 1% -0.51% (p=0.006 n=8+9) Match/Hard/1M-12 70.1ms ± 0% 69.7ms ± 1% -0.52% (p=0.006 n=8+9) Match/Hard/32M-12 2.24s ± 0% 2.23s ± 1% -0.42% (p=0.046 n=8+9) Match/Hard1/32-12 8.17µs ± 1% 7.89µs ± 0% -3.42% (p=0.000 n=8+9) Match/Hard1/1K-12 254µs ± 2% 244µs ± 0% -3.91% (p=0.000 n=9+9) Match/Hard1/32K-12 9.58ms ± 1% 10.35ms ± 0% +8.00% (p=0.000 n=10+10) Match/Hard1/1M-12 306ms ± 1% 331ms ± 0% +8.27% (p=0.000 n=9+8) Match/Hard1/32M-12 9.79s ± 1% 10.60s ± 0% +8.29% (p=0.000 n=9+8) Match_onepass_regex/32-12 808ns ± 0% 812ns ± 0% +0.47% (p=0.000 n=8+10) Match_onepass_regex/1K-12 27.8µs ± 0% 28.5µs ± 0% +2.32% (p=0.000 n=8+10) Match_onepass_regex/32K-12 925µs ± 0% 936µs ± 0% +1.24% (p=0.000 n=9+10) Match_onepass_regex/1M-12 29.5ms ± 0% 30.2ms ± 0% +2.38% (p=0.000 n=10+10) Match_onepass_regex/32M-12 945ms ± 0% 970ms ± 0% +2.60% (p=0.000 n=9+10) CompileOnepass-12 4.67µs ± 0% 4.63µs ± 1% -0.84% (p=0.000 n=10+10) [Geo mean] 24.5µs 23.3µs -5.04% https://perf.golang.org/search?q=upload:20181004.1 Change-Id: Idbc2b76223718265657819ff38be2d9aba1c54b4 Reviewed-on: https://go-review.googlesource.com/c/139779 Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-09-28 16:37:16 -04:00
if !re.tryBacktrack(b, i, uint32(re.prog.Start), pos) {
freeBitState(b)
return nil
}
} else {
regexp: port RE2's bitstate backtracker to the regexp package This is a port of RE2's bitstate backtracker, which triggers under the same conditions that the RE2 backtracker triggers. However I wasn't sure how to port over some of the optimizations in the RE2 backtracker, and there is a ~2% penalty on benchmarks that don't trigger the backtracker. benchmark old ns/op new ns/op delta BenchmarkLiteral 312 189 -39.42% BenchmarkNotLiteral 4435 3001 -32.33% BenchmarkMatchClass 5758 4378 -23.97% BenchmarkMatchClass_InRange 5385 4084 -24.16% BenchmarkReplaceAll 5291 3505 -33.76% BenchmarkAnchoredLiteralShortNonMatch 190 200 +5.26% BenchmarkAnchoredLiteralLongNonMatch 189 194 +2.65% BenchmarkAnchoredShortMatch 479 304 -36.53% BenchmarkAnchoredLongMatch 478 499 +4.39% BenchmarkOnePassShortA 791 798 +0.88% BenchmarkNotOnePassShortA 3202 1571 -50.94% BenchmarkOnePassShortB 614 633 +3.09% BenchmarkNotOnePassShortB 2685 881 -67.19% BenchmarkOnePassLongPrefix 152 154 +1.32% BenchmarkOnePassLongNotPrefix 505 533 +5.54% BenchmarkMatchEasy0_32 139 171 +23.02% BenchmarkMatchEasy0_1K 653 1797 +175.19% BenchmarkMatchEasy0_32K 12032 13346 +10.92% BenchmarkMatchEasy0_1M 462882 461272 -0.35% BenchmarkMatchEasy0_32M 15015339 15365238 +2.33% BenchmarkMatchEasy1_32 122 168 +37.70% BenchmarkMatchEasy1_1K 3339 2612 -21.77% BenchmarkMatchEasy1_32K 72330 71721 -0.84% BenchmarkMatchEasy1_1M 2545410 2652284 +4.20% BenchmarkMatchEasy1_32M 80072063 82609750 +3.17% BenchmarkMatchMedium_32 2359 1980 -16.07% BenchmarkMatchMedium_1K 75939 58593 -22.84% BenchmarkMatchMedium_32K 2450907 2501106 +2.05% BenchmarkMatchMedium_1M 78707697 80174418 +1.86% BenchmarkMatchMedium_32M 2535146010 2570896441 +1.41% BenchmarkMatchHard_32 4297 2960 -31.11% BenchmarkMatchHard_1K 133592 88997 -33.38% BenchmarkMatchHard_32K 4240445 4336907 +2.27% BenchmarkMatchHard_1M 136187006 139350238 +2.32% BenchmarkMatchHard_32M 4350855890 4478537306 +2.93% benchmark old MB/s new MB/s speedup BenchmarkMatchEasy0_32 228.74 186.11 0.81x BenchmarkMatchEasy0_1K 1565.91 569.64 0.36x BenchmarkMatchEasy0_32K 2723.31 2455.10 0.90x BenchmarkMatchEasy0_1M 2265.32 2273.22 1.00x BenchmarkMatchEasy0_32M 2234.68 2183.79 0.98x BenchmarkMatchEasy1_32 261.08 190.22 0.73x BenchmarkMatchEasy1_1K 306.59 391.91 1.28x BenchmarkMatchEasy1_32K 453.03 456.88 1.01x BenchmarkMatchEasy1_1M 411.95 395.35 0.96x BenchmarkMatchEasy1_32M 419.05 406.18 0.97x BenchmarkMatchMedium_32 13.56 16.16 1.19x BenchmarkMatchMedium_1K 13.48 17.48 1.30x BenchmarkMatchMedium_32K 13.37 13.10 0.98x BenchmarkMatchMedium_1M 13.32 13.08 0.98x BenchmarkMatchMedium_32M 13.24 13.05 0.99x BenchmarkMatchHard_32 7.45 10.81 1.45x BenchmarkMatchHard_1K 7.67 11.51 1.50x BenchmarkMatchHard_32K 7.73 7.56 0.98x BenchmarkMatchHard_1M 7.70 7.52 0.98x BenchmarkMatchHard_32M 7.71 7.49 0.97x Fixes #4154 Change-Id: Iff7fb9507f0872b320d08afc08679751ed1b28bc Reviewed-on: https://go-review.googlesource.com/2153 Reviewed-by: Russ Cox <rsc@golang.org>
2014-12-28 00:17:01 -08:00
regexp: split bit-state execution out of machine struct This allows the bit-state executions to have their own pool of allocated structures. A step toward eliminating the per-Regexp machine cache. Note especially the -92% on MatchParallelShared. This is real but not a complete story: the other execution engines still need to be de-shared, but the benchmark was only using bit-state. The tiny slowdowns in unrelated code are noise. name old time/op new time/op delta Find-12 264ns ± 3% 254ns ± 0% -3.86% (p=0.000 n=10+9) FindAllNoMatches-12 140ns ± 2% 135ns ± 0% -3.91% (p=0.000 n=10+9) FindString-12 256ns ± 0% 247ns ± 0% -3.52% (p=0.000 n=8+8) FindSubmatch-12 339ns ± 1% 334ns ± 0% -1.41% (p=0.000 n=9+10) FindStringSubmatch-12 322ns ± 0% 321ns ± 0% -0.21% (p=0.005 n=8+9) Literal-12 100ns ± 2% 92ns ± 0% -8.10% (p=0.000 n=10+9) NotLiteral-12 1.50µs ± 0% 1.47µs ± 0% -1.91% (p=0.000 n=8+9) MatchClass-12 2.18µs ± 0% 2.17µs ± 0% -0.20% (p=0.001 n=10+7) MatchClass_InRange-12 2.12µs ± 0% 2.13µs ± 0% +0.23% (p=0.000 n=10+10) ReplaceAll-12 1.41µs ± 0% 1.39µs ± 0% -1.30% (p=0.000 n=7+10) AnchoredLiteralShortNonMatch-12 89.8ns ± 0% 83.2ns ± 0% -7.35% (p=0.000 n=8+8) AnchoredLiteralLongNonMatch-12 105ns ± 3% 105ns ± 0% ~ (p=0.186 n=10+10) AnchoredShortMatch-12 141ns ± 0% 131ns ± 0% -7.09% (p=0.000 n=9+10) AnchoredLongMatch-12 276ns ± 4% 267ns ± 0% -3.23% (p=0.000 n=10+10) OnePassShortA-12 620ns ± 0% 611ns ± 0% -1.39% (p=0.000 n=10+9) NotOnePassShortA-12 575ns ± 3% 552ns ± 0% -3.97% (p=0.000 n=10+8) OnePassShortB-12 493ns ± 0% 491ns ± 0% -0.33% (p=0.000 n=8+8) NotOnePassShortB-12 423ns ± 0% 412ns ± 0% -2.60% (p=0.000 n=8+9) OnePassLongPrefix-12 112ns ± 0% 112ns ± 0% ~ (all equal) OnePassLongNotPrefix-12 405ns ± 0% 410ns ± 0% +1.23% (p=0.000 n=8+9) MatchParallelShared-12 501ns ± 1% 39ns ± 1% -92.27% (p=0.000 n=10+10) MatchParallelCopied-12 39.1ns ± 0% 39.2ns ± 3% ~ (p=0.785 n=6+10) QuoteMetaAll-12 94.6ns ± 0% 94.6ns ± 0% ~ (p=0.439 n=10+8) QuoteMetaNone-12 52.7ns ± 0% 52.7ns ± 0% ~ (all equal) Match/Easy0/32-12 79.1ns ± 0% 72.9ns ± 0% -7.85% (p=0.000 n=9+9) Match/Easy0/1K-12 307ns ± 1% 298ns ± 0% -2.99% (p=0.000 n=10+6) Match/Easy0/32K-12 4.65µs ± 2% 4.60µs ± 2% ~ (p=0.159 n=10+10) Match/Easy0/1M-12 234µs ± 0% 235µs ± 0% +0.17% (p=0.003 n=10+10) Match/Easy0/32M-12 7.98ms ± 1% 7.96ms ± 0% ~ (p=0.278 n=9+10) Match/Easy0i/32-12 1.13µs ± 1% 1.09µs ± 0% -3.24% (p=0.000 n=9+8) Match/Easy0i/1K-12 32.5µs ± 0% 31.7µs ± 0% -2.66% (p=0.000 n=9+9) Match/Easy0i/32K-12 1.59ms ± 0% 1.61ms ± 0% +0.75% (p=0.000 n=9+9) Match/Easy0i/1M-12 51.0ms ± 0% 51.4ms ± 0% +0.77% (p=0.000 n=10+8) Match/Easy0i/32M-12 1.63s ± 0% 1.65s ± 1% +1.24% (p=0.000 n=7+9) Match/Easy1/32-12 75.1ns ± 1% 67.9ns ± 0% -9.54% (p=0.000 n=8+8) Match/Easy1/1K-12 861ns ± 0% 884ns ± 0% +2.71% (p=0.000 n=8+9) Match/Easy1/32K-12 39.2µs ± 1% 39.2µs ± 0% ~ (p=0.090 n=10+9) Match/Easy1/1M-12 1.38ms ± 0% 1.39ms ± 0% ~ (p=0.095 n=10+9) Match/Easy1/32M-12 44.2ms ± 1% 44.2ms ± 1% ~ (p=0.218 n=10+10) Match/Medium/32-12 1.04µs ± 1% 1.05µs ± 0% +1.05% (p=0.000 n=9+8) Match/Medium/1K-12 31.3µs ± 0% 31.3µs ± 0% -0.14% (p=0.004 n=9+9) Match/Medium/32K-12 1.44ms ± 0% 1.45ms ± 0% +0.18% (p=0.001 n=8+8) Match/Medium/1M-12 46.1ms ± 0% 46.2ms ± 0% +0.13% (p=0.003 n=6+9) Match/Medium/32M-12 1.48s ± 0% 1.48s ± 0% +0.20% (p=0.002 n=9+8) Match/Hard/32-12 1.54µs ± 1% 1.49µs ± 0% -3.60% (p=0.000 n=9+10) Match/Hard/1K-12 46.4µs ± 1% 45.1µs ± 1% -2.78% (p=0.000 n=9+10) Match/Hard/32K-12 2.19ms ± 0% 2.18ms ± 1% -0.51% (p=0.006 n=8+9) Match/Hard/1M-12 70.1ms ± 0% 69.7ms ± 1% -0.52% (p=0.006 n=8+9) Match/Hard/32M-12 2.24s ± 0% 2.23s ± 1% -0.42% (p=0.046 n=8+9) Match/Hard1/32-12 8.17µs ± 1% 7.89µs ± 0% -3.42% (p=0.000 n=8+9) Match/Hard1/1K-12 254µs ± 2% 244µs ± 0% -3.91% (p=0.000 n=9+9) Match/Hard1/32K-12 9.58ms ± 1% 10.35ms ± 0% +8.00% (p=0.000 n=10+10) Match/Hard1/1M-12 306ms ± 1% 331ms ± 0% +8.27% (p=0.000 n=9+8) Match/Hard1/32M-12 9.79s ± 1% 10.60s ± 0% +8.29% (p=0.000 n=9+8) Match_onepass_regex/32-12 808ns ± 0% 812ns ± 0% +0.47% (p=0.000 n=8+10) Match_onepass_regex/1K-12 27.8µs ± 0% 28.5µs ± 0% +2.32% (p=0.000 n=8+10) Match_onepass_regex/32K-12 925µs ± 0% 936µs ± 0% +1.24% (p=0.000 n=9+10) Match_onepass_regex/1M-12 29.5ms ± 0% 30.2ms ± 0% +2.38% (p=0.000 n=10+10) Match_onepass_regex/32M-12 945ms ± 0% 970ms ± 0% +2.60% (p=0.000 n=9+10) CompileOnepass-12 4.67µs ± 0% 4.63µs ± 1% -0.84% (p=0.000 n=10+10) [Geo mean] 24.5µs 23.3µs -5.04% https://perf.golang.org/search?q=upload:20181004.1 Change-Id: Idbc2b76223718265657819ff38be2d9aba1c54b4 Reviewed-on: https://go-review.googlesource.com/c/139779 Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-09-28 16:37:16 -04:00
// Unanchored search, starting from each possible text position.
// Notice that we have to try the empty string at the end of
// the text, so the loop condition is pos <= end, not pos < end.
// This looks like it's quadratic in the size of the text,
// but we are not clearing visited between calls to TrySearch,
// so no work is duplicated and it ends up still being linear.
width := -1
for ; pos <= end && width != 0; pos += width {
if len(re.prefix) > 0 {
// Match requires literal prefix; fast search for it.
advance := i.index(re, pos)
if advance < 0 {
freeBitState(b)
return nil
}
pos += advance
regexp: port RE2's bitstate backtracker to the regexp package This is a port of RE2's bitstate backtracker, which triggers under the same conditions that the RE2 backtracker triggers. However I wasn't sure how to port over some of the optimizations in the RE2 backtracker, and there is a ~2% penalty on benchmarks that don't trigger the backtracker. benchmark old ns/op new ns/op delta BenchmarkLiteral 312 189 -39.42% BenchmarkNotLiteral 4435 3001 -32.33% BenchmarkMatchClass 5758 4378 -23.97% BenchmarkMatchClass_InRange 5385 4084 -24.16% BenchmarkReplaceAll 5291 3505 -33.76% BenchmarkAnchoredLiteralShortNonMatch 190 200 +5.26% BenchmarkAnchoredLiteralLongNonMatch 189 194 +2.65% BenchmarkAnchoredShortMatch 479 304 -36.53% BenchmarkAnchoredLongMatch 478 499 +4.39% BenchmarkOnePassShortA 791 798 +0.88% BenchmarkNotOnePassShortA 3202 1571 -50.94% BenchmarkOnePassShortB 614 633 +3.09% BenchmarkNotOnePassShortB 2685 881 -67.19% BenchmarkOnePassLongPrefix 152 154 +1.32% BenchmarkOnePassLongNotPrefix 505 533 +5.54% BenchmarkMatchEasy0_32 139 171 +23.02% BenchmarkMatchEasy0_1K 653 1797 +175.19% BenchmarkMatchEasy0_32K 12032 13346 +10.92% BenchmarkMatchEasy0_1M 462882 461272 -0.35% BenchmarkMatchEasy0_32M 15015339 15365238 +2.33% BenchmarkMatchEasy1_32 122 168 +37.70% BenchmarkMatchEasy1_1K 3339 2612 -21.77% BenchmarkMatchEasy1_32K 72330 71721 -0.84% BenchmarkMatchEasy1_1M 2545410 2652284 +4.20% BenchmarkMatchEasy1_32M 80072063 82609750 +3.17% BenchmarkMatchMedium_32 2359 1980 -16.07% BenchmarkMatchMedium_1K 75939 58593 -22.84% BenchmarkMatchMedium_32K 2450907 2501106 +2.05% BenchmarkMatchMedium_1M 78707697 80174418 +1.86% BenchmarkMatchMedium_32M 2535146010 2570896441 +1.41% BenchmarkMatchHard_32 4297 2960 -31.11% BenchmarkMatchHard_1K 133592 88997 -33.38% BenchmarkMatchHard_32K 4240445 4336907 +2.27% BenchmarkMatchHard_1M 136187006 139350238 +2.32% BenchmarkMatchHard_32M 4350855890 4478537306 +2.93% benchmark old MB/s new MB/s speedup BenchmarkMatchEasy0_32 228.74 186.11 0.81x BenchmarkMatchEasy0_1K 1565.91 569.64 0.36x BenchmarkMatchEasy0_32K 2723.31 2455.10 0.90x BenchmarkMatchEasy0_1M 2265.32 2273.22 1.00x BenchmarkMatchEasy0_32M 2234.68 2183.79 0.98x BenchmarkMatchEasy1_32 261.08 190.22 0.73x BenchmarkMatchEasy1_1K 306.59 391.91 1.28x BenchmarkMatchEasy1_32K 453.03 456.88 1.01x BenchmarkMatchEasy1_1M 411.95 395.35 0.96x BenchmarkMatchEasy1_32M 419.05 406.18 0.97x BenchmarkMatchMedium_32 13.56 16.16 1.19x BenchmarkMatchMedium_1K 13.48 17.48 1.30x BenchmarkMatchMedium_32K 13.37 13.10 0.98x BenchmarkMatchMedium_1M 13.32 13.08 0.98x BenchmarkMatchMedium_32M 13.24 13.05 0.99x BenchmarkMatchHard_32 7.45 10.81 1.45x BenchmarkMatchHard_1K 7.67 11.51 1.50x BenchmarkMatchHard_32K 7.73 7.56 0.98x BenchmarkMatchHard_1M 7.70 7.52 0.98x BenchmarkMatchHard_32M 7.71 7.49 0.97x Fixes #4154 Change-Id: Iff7fb9507f0872b320d08afc08679751ed1b28bc Reviewed-on: https://go-review.googlesource.com/2153 Reviewed-by: Russ Cox <rsc@golang.org>
2014-12-28 00:17:01 -08:00
}
regexp: split bit-state execution out of machine struct This allows the bit-state executions to have their own pool of allocated structures. A step toward eliminating the per-Regexp machine cache. Note especially the -92% on MatchParallelShared. This is real but not a complete story: the other execution engines still need to be de-shared, but the benchmark was only using bit-state. The tiny slowdowns in unrelated code are noise. name old time/op new time/op delta Find-12 264ns ± 3% 254ns ± 0% -3.86% (p=0.000 n=10+9) FindAllNoMatches-12 140ns ± 2% 135ns ± 0% -3.91% (p=0.000 n=10+9) FindString-12 256ns ± 0% 247ns ± 0% -3.52% (p=0.000 n=8+8) FindSubmatch-12 339ns ± 1% 334ns ± 0% -1.41% (p=0.000 n=9+10) FindStringSubmatch-12 322ns ± 0% 321ns ± 0% -0.21% (p=0.005 n=8+9) Literal-12 100ns ± 2% 92ns ± 0% -8.10% (p=0.000 n=10+9) NotLiteral-12 1.50µs ± 0% 1.47µs ± 0% -1.91% (p=0.000 n=8+9) MatchClass-12 2.18µs ± 0% 2.17µs ± 0% -0.20% (p=0.001 n=10+7) MatchClass_InRange-12 2.12µs ± 0% 2.13µs ± 0% +0.23% (p=0.000 n=10+10) ReplaceAll-12 1.41µs ± 0% 1.39µs ± 0% -1.30% (p=0.000 n=7+10) AnchoredLiteralShortNonMatch-12 89.8ns ± 0% 83.2ns ± 0% -7.35% (p=0.000 n=8+8) AnchoredLiteralLongNonMatch-12 105ns ± 3% 105ns ± 0% ~ (p=0.186 n=10+10) AnchoredShortMatch-12 141ns ± 0% 131ns ± 0% -7.09% (p=0.000 n=9+10) AnchoredLongMatch-12 276ns ± 4% 267ns ± 0% -3.23% (p=0.000 n=10+10) OnePassShortA-12 620ns ± 0% 611ns ± 0% -1.39% (p=0.000 n=10+9) NotOnePassShortA-12 575ns ± 3% 552ns ± 0% -3.97% (p=0.000 n=10+8) OnePassShortB-12 493ns ± 0% 491ns ± 0% -0.33% (p=0.000 n=8+8) NotOnePassShortB-12 423ns ± 0% 412ns ± 0% -2.60% (p=0.000 n=8+9) OnePassLongPrefix-12 112ns ± 0% 112ns ± 0% ~ (all equal) OnePassLongNotPrefix-12 405ns ± 0% 410ns ± 0% +1.23% (p=0.000 n=8+9) MatchParallelShared-12 501ns ± 1% 39ns ± 1% -92.27% (p=0.000 n=10+10) MatchParallelCopied-12 39.1ns ± 0% 39.2ns ± 3% ~ (p=0.785 n=6+10) QuoteMetaAll-12 94.6ns ± 0% 94.6ns ± 0% ~ (p=0.439 n=10+8) QuoteMetaNone-12 52.7ns ± 0% 52.7ns ± 0% ~ (all equal) Match/Easy0/32-12 79.1ns ± 0% 72.9ns ± 0% -7.85% (p=0.000 n=9+9) Match/Easy0/1K-12 307ns ± 1% 298ns ± 0% -2.99% (p=0.000 n=10+6) Match/Easy0/32K-12 4.65µs ± 2% 4.60µs ± 2% ~ (p=0.159 n=10+10) Match/Easy0/1M-12 234µs ± 0% 235µs ± 0% +0.17% (p=0.003 n=10+10) Match/Easy0/32M-12 7.98ms ± 1% 7.96ms ± 0% ~ (p=0.278 n=9+10) Match/Easy0i/32-12 1.13µs ± 1% 1.09µs ± 0% -3.24% (p=0.000 n=9+8) Match/Easy0i/1K-12 32.5µs ± 0% 31.7µs ± 0% -2.66% (p=0.000 n=9+9) Match/Easy0i/32K-12 1.59ms ± 0% 1.61ms ± 0% +0.75% (p=0.000 n=9+9) Match/Easy0i/1M-12 51.0ms ± 0% 51.4ms ± 0% +0.77% (p=0.000 n=10+8) Match/Easy0i/32M-12 1.63s ± 0% 1.65s ± 1% +1.24% (p=0.000 n=7+9) Match/Easy1/32-12 75.1ns ± 1% 67.9ns ± 0% -9.54% (p=0.000 n=8+8) Match/Easy1/1K-12 861ns ± 0% 884ns ± 0% +2.71% (p=0.000 n=8+9) Match/Easy1/32K-12 39.2µs ± 1% 39.2µs ± 0% ~ (p=0.090 n=10+9) Match/Easy1/1M-12 1.38ms ± 0% 1.39ms ± 0% ~ (p=0.095 n=10+9) Match/Easy1/32M-12 44.2ms ± 1% 44.2ms ± 1% ~ (p=0.218 n=10+10) Match/Medium/32-12 1.04µs ± 1% 1.05µs ± 0% +1.05% (p=0.000 n=9+8) Match/Medium/1K-12 31.3µs ± 0% 31.3µs ± 0% -0.14% (p=0.004 n=9+9) Match/Medium/32K-12 1.44ms ± 0% 1.45ms ± 0% +0.18% (p=0.001 n=8+8) Match/Medium/1M-12 46.1ms ± 0% 46.2ms ± 0% +0.13% (p=0.003 n=6+9) Match/Medium/32M-12 1.48s ± 0% 1.48s ± 0% +0.20% (p=0.002 n=9+8) Match/Hard/32-12 1.54µs ± 1% 1.49µs ± 0% -3.60% (p=0.000 n=9+10) Match/Hard/1K-12 46.4µs ± 1% 45.1µs ± 1% -2.78% (p=0.000 n=9+10) Match/Hard/32K-12 2.19ms ± 0% 2.18ms ± 1% -0.51% (p=0.006 n=8+9) Match/Hard/1M-12 70.1ms ± 0% 69.7ms ± 1% -0.52% (p=0.006 n=8+9) Match/Hard/32M-12 2.24s ± 0% 2.23s ± 1% -0.42% (p=0.046 n=8+9) Match/Hard1/32-12 8.17µs ± 1% 7.89µs ± 0% -3.42% (p=0.000 n=8+9) Match/Hard1/1K-12 254µs ± 2% 244µs ± 0% -3.91% (p=0.000 n=9+9) Match/Hard1/32K-12 9.58ms ± 1% 10.35ms ± 0% +8.00% (p=0.000 n=10+10) Match/Hard1/1M-12 306ms ± 1% 331ms ± 0% +8.27% (p=0.000 n=9+8) Match/Hard1/32M-12 9.79s ± 1% 10.60s ± 0% +8.29% (p=0.000 n=9+8) Match_onepass_regex/32-12 808ns ± 0% 812ns ± 0% +0.47% (p=0.000 n=8+10) Match_onepass_regex/1K-12 27.8µs ± 0% 28.5µs ± 0% +2.32% (p=0.000 n=8+10) Match_onepass_regex/32K-12 925µs ± 0% 936µs ± 0% +1.24% (p=0.000 n=9+10) Match_onepass_regex/1M-12 29.5ms ± 0% 30.2ms ± 0% +2.38% (p=0.000 n=10+10) Match_onepass_regex/32M-12 945ms ± 0% 970ms ± 0% +2.60% (p=0.000 n=9+10) CompileOnepass-12 4.67µs ± 0% 4.63µs ± 1% -0.84% (p=0.000 n=10+10) [Geo mean] 24.5µs 23.3µs -5.04% https://perf.golang.org/search?q=upload:20181004.1 Change-Id: Idbc2b76223718265657819ff38be2d9aba1c54b4 Reviewed-on: https://go-review.googlesource.com/c/139779 Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-09-28 16:37:16 -04:00
if len(b.cap) > 0 {
b.cap[0] = pos
}
if re.tryBacktrack(b, i, uint32(re.prog.Start), pos) {
// Match must be leftmost; done.
goto Match
}
_, width = i.step(pos)
regexp: port RE2's bitstate backtracker to the regexp package This is a port of RE2's bitstate backtracker, which triggers under the same conditions that the RE2 backtracker triggers. However I wasn't sure how to port over some of the optimizations in the RE2 backtracker, and there is a ~2% penalty on benchmarks that don't trigger the backtracker. benchmark old ns/op new ns/op delta BenchmarkLiteral 312 189 -39.42% BenchmarkNotLiteral 4435 3001 -32.33% BenchmarkMatchClass 5758 4378 -23.97% BenchmarkMatchClass_InRange 5385 4084 -24.16% BenchmarkReplaceAll 5291 3505 -33.76% BenchmarkAnchoredLiteralShortNonMatch 190 200 +5.26% BenchmarkAnchoredLiteralLongNonMatch 189 194 +2.65% BenchmarkAnchoredShortMatch 479 304 -36.53% BenchmarkAnchoredLongMatch 478 499 +4.39% BenchmarkOnePassShortA 791 798 +0.88% BenchmarkNotOnePassShortA 3202 1571 -50.94% BenchmarkOnePassShortB 614 633 +3.09% BenchmarkNotOnePassShortB 2685 881 -67.19% BenchmarkOnePassLongPrefix 152 154 +1.32% BenchmarkOnePassLongNotPrefix 505 533 +5.54% BenchmarkMatchEasy0_32 139 171 +23.02% BenchmarkMatchEasy0_1K 653 1797 +175.19% BenchmarkMatchEasy0_32K 12032 13346 +10.92% BenchmarkMatchEasy0_1M 462882 461272 -0.35% BenchmarkMatchEasy0_32M 15015339 15365238 +2.33% BenchmarkMatchEasy1_32 122 168 +37.70% BenchmarkMatchEasy1_1K 3339 2612 -21.77% BenchmarkMatchEasy1_32K 72330 71721 -0.84% BenchmarkMatchEasy1_1M 2545410 2652284 +4.20% BenchmarkMatchEasy1_32M 80072063 82609750 +3.17% BenchmarkMatchMedium_32 2359 1980 -16.07% BenchmarkMatchMedium_1K 75939 58593 -22.84% BenchmarkMatchMedium_32K 2450907 2501106 +2.05% BenchmarkMatchMedium_1M 78707697 80174418 +1.86% BenchmarkMatchMedium_32M 2535146010 2570896441 +1.41% BenchmarkMatchHard_32 4297 2960 -31.11% BenchmarkMatchHard_1K 133592 88997 -33.38% BenchmarkMatchHard_32K 4240445 4336907 +2.27% BenchmarkMatchHard_1M 136187006 139350238 +2.32% BenchmarkMatchHard_32M 4350855890 4478537306 +2.93% benchmark old MB/s new MB/s speedup BenchmarkMatchEasy0_32 228.74 186.11 0.81x BenchmarkMatchEasy0_1K 1565.91 569.64 0.36x BenchmarkMatchEasy0_32K 2723.31 2455.10 0.90x BenchmarkMatchEasy0_1M 2265.32 2273.22 1.00x BenchmarkMatchEasy0_32M 2234.68 2183.79 0.98x BenchmarkMatchEasy1_32 261.08 190.22 0.73x BenchmarkMatchEasy1_1K 306.59 391.91 1.28x BenchmarkMatchEasy1_32K 453.03 456.88 1.01x BenchmarkMatchEasy1_1M 411.95 395.35 0.96x BenchmarkMatchEasy1_32M 419.05 406.18 0.97x BenchmarkMatchMedium_32 13.56 16.16 1.19x BenchmarkMatchMedium_1K 13.48 17.48 1.30x BenchmarkMatchMedium_32K 13.37 13.10 0.98x BenchmarkMatchMedium_1M 13.32 13.08 0.98x BenchmarkMatchMedium_32M 13.24 13.05 0.99x BenchmarkMatchHard_32 7.45 10.81 1.45x BenchmarkMatchHard_1K 7.67 11.51 1.50x BenchmarkMatchHard_32K 7.73 7.56 0.98x BenchmarkMatchHard_1M 7.70 7.52 0.98x BenchmarkMatchHard_32M 7.71 7.49 0.97x Fixes #4154 Change-Id: Iff7fb9507f0872b320d08afc08679751ed1b28bc Reviewed-on: https://go-review.googlesource.com/2153 Reviewed-by: Russ Cox <rsc@golang.org>
2014-12-28 00:17:01 -08:00
}
regexp: split bit-state execution out of machine struct This allows the bit-state executions to have their own pool of allocated structures. A step toward eliminating the per-Regexp machine cache. Note especially the -92% on MatchParallelShared. This is real but not a complete story: the other execution engines still need to be de-shared, but the benchmark was only using bit-state. The tiny slowdowns in unrelated code are noise. name old time/op new time/op delta Find-12 264ns ± 3% 254ns ± 0% -3.86% (p=0.000 n=10+9) FindAllNoMatches-12 140ns ± 2% 135ns ± 0% -3.91% (p=0.000 n=10+9) FindString-12 256ns ± 0% 247ns ± 0% -3.52% (p=0.000 n=8+8) FindSubmatch-12 339ns ± 1% 334ns ± 0% -1.41% (p=0.000 n=9+10) FindStringSubmatch-12 322ns ± 0% 321ns ± 0% -0.21% (p=0.005 n=8+9) Literal-12 100ns ± 2% 92ns ± 0% -8.10% (p=0.000 n=10+9) NotLiteral-12 1.50µs ± 0% 1.47µs ± 0% -1.91% (p=0.000 n=8+9) MatchClass-12 2.18µs ± 0% 2.17µs ± 0% -0.20% (p=0.001 n=10+7) MatchClass_InRange-12 2.12µs ± 0% 2.13µs ± 0% +0.23% (p=0.000 n=10+10) ReplaceAll-12 1.41µs ± 0% 1.39µs ± 0% -1.30% (p=0.000 n=7+10) AnchoredLiteralShortNonMatch-12 89.8ns ± 0% 83.2ns ± 0% -7.35% (p=0.000 n=8+8) AnchoredLiteralLongNonMatch-12 105ns ± 3% 105ns ± 0% ~ (p=0.186 n=10+10) AnchoredShortMatch-12 141ns ± 0% 131ns ± 0% -7.09% (p=0.000 n=9+10) AnchoredLongMatch-12 276ns ± 4% 267ns ± 0% -3.23% (p=0.000 n=10+10) OnePassShortA-12 620ns ± 0% 611ns ± 0% -1.39% (p=0.000 n=10+9) NotOnePassShortA-12 575ns ± 3% 552ns ± 0% -3.97% (p=0.000 n=10+8) OnePassShortB-12 493ns ± 0% 491ns ± 0% -0.33% (p=0.000 n=8+8) NotOnePassShortB-12 423ns ± 0% 412ns ± 0% -2.60% (p=0.000 n=8+9) OnePassLongPrefix-12 112ns ± 0% 112ns ± 0% ~ (all equal) OnePassLongNotPrefix-12 405ns ± 0% 410ns ± 0% +1.23% (p=0.000 n=8+9) MatchParallelShared-12 501ns ± 1% 39ns ± 1% -92.27% (p=0.000 n=10+10) MatchParallelCopied-12 39.1ns ± 0% 39.2ns ± 3% ~ (p=0.785 n=6+10) QuoteMetaAll-12 94.6ns ± 0% 94.6ns ± 0% ~ (p=0.439 n=10+8) QuoteMetaNone-12 52.7ns ± 0% 52.7ns ± 0% ~ (all equal) Match/Easy0/32-12 79.1ns ± 0% 72.9ns ± 0% -7.85% (p=0.000 n=9+9) Match/Easy0/1K-12 307ns ± 1% 298ns ± 0% -2.99% (p=0.000 n=10+6) Match/Easy0/32K-12 4.65µs ± 2% 4.60µs ± 2% ~ (p=0.159 n=10+10) Match/Easy0/1M-12 234µs ± 0% 235µs ± 0% +0.17% (p=0.003 n=10+10) Match/Easy0/32M-12 7.98ms ± 1% 7.96ms ± 0% ~ (p=0.278 n=9+10) Match/Easy0i/32-12 1.13µs ± 1% 1.09µs ± 0% -3.24% (p=0.000 n=9+8) Match/Easy0i/1K-12 32.5µs ± 0% 31.7µs ± 0% -2.66% (p=0.000 n=9+9) Match/Easy0i/32K-12 1.59ms ± 0% 1.61ms ± 0% +0.75% (p=0.000 n=9+9) Match/Easy0i/1M-12 51.0ms ± 0% 51.4ms ± 0% +0.77% (p=0.000 n=10+8) Match/Easy0i/32M-12 1.63s ± 0% 1.65s ± 1% +1.24% (p=0.000 n=7+9) Match/Easy1/32-12 75.1ns ± 1% 67.9ns ± 0% -9.54% (p=0.000 n=8+8) Match/Easy1/1K-12 861ns ± 0% 884ns ± 0% +2.71% (p=0.000 n=8+9) Match/Easy1/32K-12 39.2µs ± 1% 39.2µs ± 0% ~ (p=0.090 n=10+9) Match/Easy1/1M-12 1.38ms ± 0% 1.39ms ± 0% ~ (p=0.095 n=10+9) Match/Easy1/32M-12 44.2ms ± 1% 44.2ms ± 1% ~ (p=0.218 n=10+10) Match/Medium/32-12 1.04µs ± 1% 1.05µs ± 0% +1.05% (p=0.000 n=9+8) Match/Medium/1K-12 31.3µs ± 0% 31.3µs ± 0% -0.14% (p=0.004 n=9+9) Match/Medium/32K-12 1.44ms ± 0% 1.45ms ± 0% +0.18% (p=0.001 n=8+8) Match/Medium/1M-12 46.1ms ± 0% 46.2ms ± 0% +0.13% (p=0.003 n=6+9) Match/Medium/32M-12 1.48s ± 0% 1.48s ± 0% +0.20% (p=0.002 n=9+8) Match/Hard/32-12 1.54µs ± 1% 1.49µs ± 0% -3.60% (p=0.000 n=9+10) Match/Hard/1K-12 46.4µs ± 1% 45.1µs ± 1% -2.78% (p=0.000 n=9+10) Match/Hard/32K-12 2.19ms ± 0% 2.18ms ± 1% -0.51% (p=0.006 n=8+9) Match/Hard/1M-12 70.1ms ± 0% 69.7ms ± 1% -0.52% (p=0.006 n=8+9) Match/Hard/32M-12 2.24s ± 0% 2.23s ± 1% -0.42% (p=0.046 n=8+9) Match/Hard1/32-12 8.17µs ± 1% 7.89µs ± 0% -3.42% (p=0.000 n=8+9) Match/Hard1/1K-12 254µs ± 2% 244µs ± 0% -3.91% (p=0.000 n=9+9) Match/Hard1/32K-12 9.58ms ± 1% 10.35ms ± 0% +8.00% (p=0.000 n=10+10) Match/Hard1/1M-12 306ms ± 1% 331ms ± 0% +8.27% (p=0.000 n=9+8) Match/Hard1/32M-12 9.79s ± 1% 10.60s ± 0% +8.29% (p=0.000 n=9+8) Match_onepass_regex/32-12 808ns ± 0% 812ns ± 0% +0.47% (p=0.000 n=8+10) Match_onepass_regex/1K-12 27.8µs ± 0% 28.5µs ± 0% +2.32% (p=0.000 n=8+10) Match_onepass_regex/32K-12 925µs ± 0% 936µs ± 0% +1.24% (p=0.000 n=9+10) Match_onepass_regex/1M-12 29.5ms ± 0% 30.2ms ± 0% +2.38% (p=0.000 n=10+10) Match_onepass_regex/32M-12 945ms ± 0% 970ms ± 0% +2.60% (p=0.000 n=9+10) CompileOnepass-12 4.67µs ± 0% 4.63µs ± 1% -0.84% (p=0.000 n=10+10) [Geo mean] 24.5µs 23.3µs -5.04% https://perf.golang.org/search?q=upload:20181004.1 Change-Id: Idbc2b76223718265657819ff38be2d9aba1c54b4 Reviewed-on: https://go-review.googlesource.com/c/139779 Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-09-28 16:37:16 -04:00
freeBitState(b)
return nil
regexp: port RE2's bitstate backtracker to the regexp package This is a port of RE2's bitstate backtracker, which triggers under the same conditions that the RE2 backtracker triggers. However I wasn't sure how to port over some of the optimizations in the RE2 backtracker, and there is a ~2% penalty on benchmarks that don't trigger the backtracker. benchmark old ns/op new ns/op delta BenchmarkLiteral 312 189 -39.42% BenchmarkNotLiteral 4435 3001 -32.33% BenchmarkMatchClass 5758 4378 -23.97% BenchmarkMatchClass_InRange 5385 4084 -24.16% BenchmarkReplaceAll 5291 3505 -33.76% BenchmarkAnchoredLiteralShortNonMatch 190 200 +5.26% BenchmarkAnchoredLiteralLongNonMatch 189 194 +2.65% BenchmarkAnchoredShortMatch 479 304 -36.53% BenchmarkAnchoredLongMatch 478 499 +4.39% BenchmarkOnePassShortA 791 798 +0.88% BenchmarkNotOnePassShortA 3202 1571 -50.94% BenchmarkOnePassShortB 614 633 +3.09% BenchmarkNotOnePassShortB 2685 881 -67.19% BenchmarkOnePassLongPrefix 152 154 +1.32% BenchmarkOnePassLongNotPrefix 505 533 +5.54% BenchmarkMatchEasy0_32 139 171 +23.02% BenchmarkMatchEasy0_1K 653 1797 +175.19% BenchmarkMatchEasy0_32K 12032 13346 +10.92% BenchmarkMatchEasy0_1M 462882 461272 -0.35% BenchmarkMatchEasy0_32M 15015339 15365238 +2.33% BenchmarkMatchEasy1_32 122 168 +37.70% BenchmarkMatchEasy1_1K 3339 2612 -21.77% BenchmarkMatchEasy1_32K 72330 71721 -0.84% BenchmarkMatchEasy1_1M 2545410 2652284 +4.20% BenchmarkMatchEasy1_32M 80072063 82609750 +3.17% BenchmarkMatchMedium_32 2359 1980 -16.07% BenchmarkMatchMedium_1K 75939 58593 -22.84% BenchmarkMatchMedium_32K 2450907 2501106 +2.05% BenchmarkMatchMedium_1M 78707697 80174418 +1.86% BenchmarkMatchMedium_32M 2535146010 2570896441 +1.41% BenchmarkMatchHard_32 4297 2960 -31.11% BenchmarkMatchHard_1K 133592 88997 -33.38% BenchmarkMatchHard_32K 4240445 4336907 +2.27% BenchmarkMatchHard_1M 136187006 139350238 +2.32% BenchmarkMatchHard_32M 4350855890 4478537306 +2.93% benchmark old MB/s new MB/s speedup BenchmarkMatchEasy0_32 228.74 186.11 0.81x BenchmarkMatchEasy0_1K 1565.91 569.64 0.36x BenchmarkMatchEasy0_32K 2723.31 2455.10 0.90x BenchmarkMatchEasy0_1M 2265.32 2273.22 1.00x BenchmarkMatchEasy0_32M 2234.68 2183.79 0.98x BenchmarkMatchEasy1_32 261.08 190.22 0.73x BenchmarkMatchEasy1_1K 306.59 391.91 1.28x BenchmarkMatchEasy1_32K 453.03 456.88 1.01x BenchmarkMatchEasy1_1M 411.95 395.35 0.96x BenchmarkMatchEasy1_32M 419.05 406.18 0.97x BenchmarkMatchMedium_32 13.56 16.16 1.19x BenchmarkMatchMedium_1K 13.48 17.48 1.30x BenchmarkMatchMedium_32K 13.37 13.10 0.98x BenchmarkMatchMedium_1M 13.32 13.08 0.98x BenchmarkMatchMedium_32M 13.24 13.05 0.99x BenchmarkMatchHard_32 7.45 10.81 1.45x BenchmarkMatchHard_1K 7.67 11.51 1.50x BenchmarkMatchHard_32K 7.73 7.56 0.98x BenchmarkMatchHard_1M 7.70 7.52 0.98x BenchmarkMatchHard_32M 7.71 7.49 0.97x Fixes #4154 Change-Id: Iff7fb9507f0872b320d08afc08679751ed1b28bc Reviewed-on: https://go-review.googlesource.com/2153 Reviewed-by: Russ Cox <rsc@golang.org>
2014-12-28 00:17:01 -08:00
}
regexp: split bit-state execution out of machine struct This allows the bit-state executions to have their own pool of allocated structures. A step toward eliminating the per-Regexp machine cache. Note especially the -92% on MatchParallelShared. This is real but not a complete story: the other execution engines still need to be de-shared, but the benchmark was only using bit-state. The tiny slowdowns in unrelated code are noise. name old time/op new time/op delta Find-12 264ns ± 3% 254ns ± 0% -3.86% (p=0.000 n=10+9) FindAllNoMatches-12 140ns ± 2% 135ns ± 0% -3.91% (p=0.000 n=10+9) FindString-12 256ns ± 0% 247ns ± 0% -3.52% (p=0.000 n=8+8) FindSubmatch-12 339ns ± 1% 334ns ± 0% -1.41% (p=0.000 n=9+10) FindStringSubmatch-12 322ns ± 0% 321ns ± 0% -0.21% (p=0.005 n=8+9) Literal-12 100ns ± 2% 92ns ± 0% -8.10% (p=0.000 n=10+9) NotLiteral-12 1.50µs ± 0% 1.47µs ± 0% -1.91% (p=0.000 n=8+9) MatchClass-12 2.18µs ± 0% 2.17µs ± 0% -0.20% (p=0.001 n=10+7) MatchClass_InRange-12 2.12µs ± 0% 2.13µs ± 0% +0.23% (p=0.000 n=10+10) ReplaceAll-12 1.41µs ± 0% 1.39µs ± 0% -1.30% (p=0.000 n=7+10) AnchoredLiteralShortNonMatch-12 89.8ns ± 0% 83.2ns ± 0% -7.35% (p=0.000 n=8+8) AnchoredLiteralLongNonMatch-12 105ns ± 3% 105ns ± 0% ~ (p=0.186 n=10+10) AnchoredShortMatch-12 141ns ± 0% 131ns ± 0% -7.09% (p=0.000 n=9+10) AnchoredLongMatch-12 276ns ± 4% 267ns ± 0% -3.23% (p=0.000 n=10+10) OnePassShortA-12 620ns ± 0% 611ns ± 0% -1.39% (p=0.000 n=10+9) NotOnePassShortA-12 575ns ± 3% 552ns ± 0% -3.97% (p=0.000 n=10+8) OnePassShortB-12 493ns ± 0% 491ns ± 0% -0.33% (p=0.000 n=8+8) NotOnePassShortB-12 423ns ± 0% 412ns ± 0% -2.60% (p=0.000 n=8+9) OnePassLongPrefix-12 112ns ± 0% 112ns ± 0% ~ (all equal) OnePassLongNotPrefix-12 405ns ± 0% 410ns ± 0% +1.23% (p=0.000 n=8+9) MatchParallelShared-12 501ns ± 1% 39ns ± 1% -92.27% (p=0.000 n=10+10) MatchParallelCopied-12 39.1ns ± 0% 39.2ns ± 3% ~ (p=0.785 n=6+10) QuoteMetaAll-12 94.6ns ± 0% 94.6ns ± 0% ~ (p=0.439 n=10+8) QuoteMetaNone-12 52.7ns ± 0% 52.7ns ± 0% ~ (all equal) Match/Easy0/32-12 79.1ns ± 0% 72.9ns ± 0% -7.85% (p=0.000 n=9+9) Match/Easy0/1K-12 307ns ± 1% 298ns ± 0% -2.99% (p=0.000 n=10+6) Match/Easy0/32K-12 4.65µs ± 2% 4.60µs ± 2% ~ (p=0.159 n=10+10) Match/Easy0/1M-12 234µs ± 0% 235µs ± 0% +0.17% (p=0.003 n=10+10) Match/Easy0/32M-12 7.98ms ± 1% 7.96ms ± 0% ~ (p=0.278 n=9+10) Match/Easy0i/32-12 1.13µs ± 1% 1.09µs ± 0% -3.24% (p=0.000 n=9+8) Match/Easy0i/1K-12 32.5µs ± 0% 31.7µs ± 0% -2.66% (p=0.000 n=9+9) Match/Easy0i/32K-12 1.59ms ± 0% 1.61ms ± 0% +0.75% (p=0.000 n=9+9) Match/Easy0i/1M-12 51.0ms ± 0% 51.4ms ± 0% +0.77% (p=0.000 n=10+8) Match/Easy0i/32M-12 1.63s ± 0% 1.65s ± 1% +1.24% (p=0.000 n=7+9) Match/Easy1/32-12 75.1ns ± 1% 67.9ns ± 0% -9.54% (p=0.000 n=8+8) Match/Easy1/1K-12 861ns ± 0% 884ns ± 0% +2.71% (p=0.000 n=8+9) Match/Easy1/32K-12 39.2µs ± 1% 39.2µs ± 0% ~ (p=0.090 n=10+9) Match/Easy1/1M-12 1.38ms ± 0% 1.39ms ± 0% ~ (p=0.095 n=10+9) Match/Easy1/32M-12 44.2ms ± 1% 44.2ms ± 1% ~ (p=0.218 n=10+10) Match/Medium/32-12 1.04µs ± 1% 1.05µs ± 0% +1.05% (p=0.000 n=9+8) Match/Medium/1K-12 31.3µs ± 0% 31.3µs ± 0% -0.14% (p=0.004 n=9+9) Match/Medium/32K-12 1.44ms ± 0% 1.45ms ± 0% +0.18% (p=0.001 n=8+8) Match/Medium/1M-12 46.1ms ± 0% 46.2ms ± 0% +0.13% (p=0.003 n=6+9) Match/Medium/32M-12 1.48s ± 0% 1.48s ± 0% +0.20% (p=0.002 n=9+8) Match/Hard/32-12 1.54µs ± 1% 1.49µs ± 0% -3.60% (p=0.000 n=9+10) Match/Hard/1K-12 46.4µs ± 1% 45.1µs ± 1% -2.78% (p=0.000 n=9+10) Match/Hard/32K-12 2.19ms ± 0% 2.18ms ± 1% -0.51% (p=0.006 n=8+9) Match/Hard/1M-12 70.1ms ± 0% 69.7ms ± 1% -0.52% (p=0.006 n=8+9) Match/Hard/32M-12 2.24s ± 0% 2.23s ± 1% -0.42% (p=0.046 n=8+9) Match/Hard1/32-12 8.17µs ± 1% 7.89µs ± 0% -3.42% (p=0.000 n=8+9) Match/Hard1/1K-12 254µs ± 2% 244µs ± 0% -3.91% (p=0.000 n=9+9) Match/Hard1/32K-12 9.58ms ± 1% 10.35ms ± 0% +8.00% (p=0.000 n=10+10) Match/Hard1/1M-12 306ms ± 1% 331ms ± 0% +8.27% (p=0.000 n=9+8) Match/Hard1/32M-12 9.79s ± 1% 10.60s ± 0% +8.29% (p=0.000 n=9+8) Match_onepass_regex/32-12 808ns ± 0% 812ns ± 0% +0.47% (p=0.000 n=8+10) Match_onepass_regex/1K-12 27.8µs ± 0% 28.5µs ± 0% +2.32% (p=0.000 n=8+10) Match_onepass_regex/32K-12 925µs ± 0% 936µs ± 0% +1.24% (p=0.000 n=9+10) Match_onepass_regex/1M-12 29.5ms ± 0% 30.2ms ± 0% +2.38% (p=0.000 n=10+10) Match_onepass_regex/32M-12 945ms ± 0% 970ms ± 0% +2.60% (p=0.000 n=9+10) CompileOnepass-12 4.67µs ± 0% 4.63µs ± 1% -0.84% (p=0.000 n=10+10) [Geo mean] 24.5µs 23.3µs -5.04% https://perf.golang.org/search?q=upload:20181004.1 Change-Id: Idbc2b76223718265657819ff38be2d9aba1c54b4 Reviewed-on: https://go-review.googlesource.com/c/139779 Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-09-28 16:37:16 -04:00
Match:
dstCap = append(dstCap, b.matchcap...)
freeBitState(b)
return dstCap
regexp: port RE2's bitstate backtracker to the regexp package This is a port of RE2's bitstate backtracker, which triggers under the same conditions that the RE2 backtracker triggers. However I wasn't sure how to port over some of the optimizations in the RE2 backtracker, and there is a ~2% penalty on benchmarks that don't trigger the backtracker. benchmark old ns/op new ns/op delta BenchmarkLiteral 312 189 -39.42% BenchmarkNotLiteral 4435 3001 -32.33% BenchmarkMatchClass 5758 4378 -23.97% BenchmarkMatchClass_InRange 5385 4084 -24.16% BenchmarkReplaceAll 5291 3505 -33.76% BenchmarkAnchoredLiteralShortNonMatch 190 200 +5.26% BenchmarkAnchoredLiteralLongNonMatch 189 194 +2.65% BenchmarkAnchoredShortMatch 479 304 -36.53% BenchmarkAnchoredLongMatch 478 499 +4.39% BenchmarkOnePassShortA 791 798 +0.88% BenchmarkNotOnePassShortA 3202 1571 -50.94% BenchmarkOnePassShortB 614 633 +3.09% BenchmarkNotOnePassShortB 2685 881 -67.19% BenchmarkOnePassLongPrefix 152 154 +1.32% BenchmarkOnePassLongNotPrefix 505 533 +5.54% BenchmarkMatchEasy0_32 139 171 +23.02% BenchmarkMatchEasy0_1K 653 1797 +175.19% BenchmarkMatchEasy0_32K 12032 13346 +10.92% BenchmarkMatchEasy0_1M 462882 461272 -0.35% BenchmarkMatchEasy0_32M 15015339 15365238 +2.33% BenchmarkMatchEasy1_32 122 168 +37.70% BenchmarkMatchEasy1_1K 3339 2612 -21.77% BenchmarkMatchEasy1_32K 72330 71721 -0.84% BenchmarkMatchEasy1_1M 2545410 2652284 +4.20% BenchmarkMatchEasy1_32M 80072063 82609750 +3.17% BenchmarkMatchMedium_32 2359 1980 -16.07% BenchmarkMatchMedium_1K 75939 58593 -22.84% BenchmarkMatchMedium_32K 2450907 2501106 +2.05% BenchmarkMatchMedium_1M 78707697 80174418 +1.86% BenchmarkMatchMedium_32M 2535146010 2570896441 +1.41% BenchmarkMatchHard_32 4297 2960 -31.11% BenchmarkMatchHard_1K 133592 88997 -33.38% BenchmarkMatchHard_32K 4240445 4336907 +2.27% BenchmarkMatchHard_1M 136187006 139350238 +2.32% BenchmarkMatchHard_32M 4350855890 4478537306 +2.93% benchmark old MB/s new MB/s speedup BenchmarkMatchEasy0_32 228.74 186.11 0.81x BenchmarkMatchEasy0_1K 1565.91 569.64 0.36x BenchmarkMatchEasy0_32K 2723.31 2455.10 0.90x BenchmarkMatchEasy0_1M 2265.32 2273.22 1.00x BenchmarkMatchEasy0_32M 2234.68 2183.79 0.98x BenchmarkMatchEasy1_32 261.08 190.22 0.73x BenchmarkMatchEasy1_1K 306.59 391.91 1.28x BenchmarkMatchEasy1_32K 453.03 456.88 1.01x BenchmarkMatchEasy1_1M 411.95 395.35 0.96x BenchmarkMatchEasy1_32M 419.05 406.18 0.97x BenchmarkMatchMedium_32 13.56 16.16 1.19x BenchmarkMatchMedium_1K 13.48 17.48 1.30x BenchmarkMatchMedium_32K 13.37 13.10 0.98x BenchmarkMatchMedium_1M 13.32 13.08 0.98x BenchmarkMatchMedium_32M 13.24 13.05 0.99x BenchmarkMatchHard_32 7.45 10.81 1.45x BenchmarkMatchHard_1K 7.67 11.51 1.50x BenchmarkMatchHard_32K 7.73 7.56 0.98x BenchmarkMatchHard_1M 7.70 7.52 0.98x BenchmarkMatchHard_32M 7.71 7.49 0.97x Fixes #4154 Change-Id: Iff7fb9507f0872b320d08afc08679751ed1b28bc Reviewed-on: https://go-review.googlesource.com/2153 Reviewed-by: Russ Cox <rsc@golang.org>
2014-12-28 00:17:01 -08:00
}