Commit a306a851 authored by Takuto Ikuta's avatar Takuto Ikuta Committed by Brad Fitzpatrick

regexp: Use []bool instead of map[uint32]bool in makeOnePass

Variable m is accessed like variable onePassRunes.
So, we can use array instead of map for variable m.

Onepass compile performance is improved 10~20%.

name                                      old time/op    new time/op    delta
CompileOnepass/^(?:(?:(?:.(?:$))?))...-4    4.60µs ± 1%    4.10µs ± 1%  -10.98%  (p=0.008 n=5+5)
CompileOnepass/^abcd$-4                     3.76µs ± 2%    3.33µs ± 1%  -11.43%  (p=0.008 n=5+5)
CompileOnepass/^(?:(?:a{0,})*?)$-4          4.47µs ± 1%    4.14µs ± 1%   -7.49%  (p=0.008 n=5+5)
CompileOnepass/^(?:(?:a+)*)$-4              4.07µs ± 1%    3.81µs ± 2%   -6.60%  (p=0.008 n=5+5)
CompileOnepass/^(?:(?:a|(?:aa)))$-4         5.21µs ± 1%    4.80µs ± 2%   -7.90%  (p=0.008 n=5+5)
CompileOnepass/^(?:[^\s\S])$-4              3.26µs ± 1%    3.06µs ± 1%   -6.15%  (p=0.008 n=5+5)
CompileOnepass/^(?:(?:(?:a*)+))$-4          4.33µs ± 0%    4.04µs ± 3%   -6.78%  (p=0.008 n=5+5)
CompileOnepass/^[a-c]+$-4                   3.33µs ± 1%    3.06µs ± 4%   -8.24%  (p=0.008 n=5+5)
CompileOnepass/^[a-c]*$-4                   3.69µs ± 1%    3.39µs ± 4%   -8.26%  (p=0.008 n=5+5)
CompileOnepass/^(?:a*)$-4                   3.78µs ± 2%    3.36µs ± 0%  -11.09%  (p=0.008 n=5+5)
CompileOnepass/^(?:(?:aa)|a)$-4             5.11µs ± 1%    4.60µs ± 1%   -9.85%  (p=0.008 n=5+5)
CompileOnepass/^...$-4                      3.51µs ± 1%    3.25µs ± 1%   -7.37%  (p=0.008 n=5+5)
CompileOnepass/^(?:a|(?:aa))$-4             5.05µs ± 1%    4.59µs ± 1%   -9.13%  (p=0.008 n=5+5)
CompileOnepass/^a((b))c$-4                  5.24µs ± 1%    4.66µs ± 1%  -11.16%  (p=0.008 n=5+5)
CompileOnepass/^a.[l-nA-Cg-j]?e$-4          5.94µs ± 7%    5.02µs ± 1%  -15.62%  (p=0.008 n=5+5)
CompileOnepass/^a((b))$-4                   5.34µs ± 7%    4.21µs ± 2%  -21.05%  (p=0.008 n=5+5)
CompileOnepass/^a(?:(b)|(c))c$-4            7.25µs ± 7%    5.86µs ± 1%  -19.17%  (p=0.008 n=5+5)
CompileOnepass/^a(?:b|c)$-4                 4.13µs ± 9%    3.35µs ± 1%  -18.99%  (p=0.008 n=5+5)
CompileOnepass/^a(?:b?|c)$-4                6.48µs ± 4%    5.05µs ± 1%  -22.16%  (p=0.008 n=5+5)
CompileOnepass/^a(?:b?|c+)$-4               7.05µs ± 7%    5.48µs ± 1%  -22.21%  (p=0.008 n=5+5)
CompileOnepass/^a(?:bc)+$-4                 4.71µs ± 4%    3.85µs ± 0%  -18.14%  (p=0.008 n=5+5)
CompileOnepass/^a(?:[bcd])+$-4              4.10µs ± 2%    3.69µs ± 1%   -9.98%  (p=0.008 n=5+5)
CompileOnepass/^a((?:[bcd])+)$-4            5.20µs ± 1%    4.59µs ± 0%  -11.72%  (p=0.008 n=5+5)
CompileOnepass/^a(:?b|c)*d$-4               9.29µs ± 2%    8.23µs ± 1%  -11.43%  (p=0.008 n=5+5)
CompileOnepass/^.bc(d|e)*$-4                6.33µs ± 3%    5.51µs ± 5%  -12.95%  (p=0.008 n=5+5)
CompileOnepass/^loooooooooooooooooo...-4     162µs ± 0%     138µs ± 2%  -14.70%  (p=0.008 n=5+5)

name                                      old alloc/op   new alloc/op   delta
CompileOnepass/^(?:(?:(?:.(?:$))?))...-4    3.38kB ± 0%    3.27kB ± 0%   -3.08%  (p=0.008 n=5+5)
CompileOnepass/^abcd$-4                     2.74kB ± 0%    2.59kB ± 0%   -5.54%  (p=0.008 n=5+5)
CompileOnepass/^(?:(?:a{0,})*?)$-4          3.34kB ± 0%    3.23kB ± 0%   -3.12%  (p=0.008 n=5+5)
CompileOnepass/^(?:(?:a+)*)$-4              2.95kB ± 0%    2.85kB ± 0%   -3.52%  (p=0.008 n=5+5)
CompileOnepass/^(?:(?:a|(?:aa)))$-4         3.74kB ± 0%    3.58kB ± 0%   -4.07%  (p=0.008 n=5+5)
CompileOnepass/^(?:[^\s\S])$-4              2.45kB ± 0%    2.35kB ± 0%   -4.20%  (p=0.008 n=5+5)
CompileOnepass/^(?:(?:(?:a*)+))$-4          3.13kB ± 0%    3.02kB ± 0%   -3.32%  (p=0.008 n=5+5)
CompileOnepass/^[a-c]+$-4                   2.48kB ± 0%    2.38kB ± 0%   -4.19%  (p=0.008 n=5+5)
CompileOnepass/^[a-c]*$-4                   2.52kB ± 0%    2.42kB ± 0%   -4.13%  (p=0.008 n=5+5)
CompileOnepass/^(?:a*)$-4                   2.63kB ± 0%    2.53kB ± 0%   -3.95%  (p=0.008 n=5+5)
CompileOnepass/^(?:(?:aa)|a)$-4             3.62kB ± 0%    3.47kB ± 0%   -4.19%  (p=0.008 n=5+5)
CompileOnepass/^...$-4                      2.87kB ± 0%    2.78kB ± 0%   -3.34%  (p=0.008 n=5+5)
CompileOnepass/^(?:a|(?:aa))$-4             3.62kB ± 0%    3.47kB ± 0%   -4.19%  (p=0.008 n=5+5)
CompileOnepass/^a((b))c$-4                  4.38kB ± 0%    4.23kB ± 0%   -3.33%  (p=0.008 n=5+5)
CompileOnepass/^a.[l-nA-Cg-j]?e$-4          4.30kB ± 0%    4.15kB ± 0%   -3.35%  (p=0.008 n=5+5)
CompileOnepass/^a((b))$-4                   4.05kB ± 0%    3.90kB ± 0%   -3.56%  (p=0.008 n=5+5)
CompileOnepass/^a(?:(b)|(c))c$-4            5.30kB ± 0%    5.05kB ± 0%   -4.83%  (p=0.008 n=5+5)
CompileOnepass/^a(?:b|c)$-4                 2.87kB ± 0%    2.77kB ± 0%   -3.62%  (p=0.008 n=5+5)
CompileOnepass/^a(?:b?|c)$-4                4.35kB ± 0%    4.21kB ± 0%   -3.31%  (p=0.008 n=5+5)
CompileOnepass/^a(?:b?|c+)$-4               4.58kB ± 0%    4.44kB ± 0%   -3.14%  (p=0.008 n=5+5)
CompileOnepass/^a(?:bc)+$-4                 3.15kB ± 0%    3.00kB ± 0%   -4.82%  (p=0.008 n=5+5)
CompileOnepass/^a(?:[bcd])+$-4              2.94kB ± 0%    2.84kB ± 0%   -3.53%  (p=0.008 n=5+5)
CompileOnepass/^a((?:[bcd])+)$-4            4.08kB ± 0%    3.94kB ± 0%   -3.53%  (p=0.008 n=5+5)
CompileOnepass/^a(:?b|c)*d$-4               6.10kB ± 0%    5.85kB ± 0%   -4.19%  (p=0.008 n=5+5)
CompileOnepass/^.bc(d|e)*$-4                4.46kB ± 0%    4.31kB ± 0%   -3.28%  (p=0.008 n=5+5)
CompileOnepass/^loooooooooooooooooo...-4     135kB ± 0%     127kB ± 0%   -5.88%  (p=0.008 n=5+5)

name                                      old allocs/op  new allocs/op  delta
CompileOnepass/^(?:(?:(?:.(?:$))?))...-4      47.0 ± 0%      46.0 ± 0%   -2.13%  (p=0.008 n=5+5)
CompileOnepass/^abcd$-4                       41.0 ± 0%      40.0 ± 0%   -2.44%  (p=0.008 n=5+5)
CompileOnepass/^(?:(?:a{0,})*?)$-4            49.0 ± 0%      48.0 ± 0%   -2.04%  (p=0.008 n=5+5)
CompileOnepass/^(?:(?:a+)*)$-4                44.0 ± 0%      43.0 ± 0%   -2.27%  (p=0.008 n=5+5)
CompileOnepass/^(?:(?:a|(?:aa)))$-4           54.0 ± 0%      53.0 ± 0%   -1.85%  (p=0.008 n=5+5)
CompileOnepass/^(?:[^\s\S])$-4                33.0 ± 0%      32.0 ± 0%   -3.03%  (p=0.008 n=5+5)
CompileOnepass/^(?:(?:(?:a*)+))$-4            46.0 ± 0%      45.0 ± 0%   -2.17%  (p=0.008 n=5+5)
CompileOnepass/^[a-c]+$-4                     36.0 ± 0%      35.0 ± 0%   -2.78%  (p=0.008 n=5+5)
CompileOnepass/^[a-c]*$-4                     41.0 ± 0%      40.0 ± 0%   -2.44%  (p=0.008 n=5+5)
CompileOnepass/^(?:a*)$-4                     42.0 ± 0%      41.0 ± 0%   -2.38%  (p=0.008 n=5+5)
CompileOnepass/^(?:(?:aa)|a)$-4               53.0 ± 0%      52.0 ± 0%   -1.89%  (p=0.008 n=5+5)
CompileOnepass/^...$-4                        39.0 ± 0%      38.0 ± 0%   -2.56%  (p=0.008 n=5+5)
CompileOnepass/^(?:a|(?:aa))$-4               53.0 ± 0%      52.0 ± 0%   -1.89%  (p=0.008 n=5+5)
CompileOnepass/^a((b))c$-4                    53.0 ± 0%      52.0 ± 0%   -1.89%  (p=0.008 n=5+5)
CompileOnepass/^a.[l-nA-Cg-j]?e$-4            56.0 ± 0%      55.0 ± 0%   -1.79%  (p=0.008 n=5+5)
CompileOnepass/^a((b))$-4                     47.0 ± 0%      46.0 ± 0%   -2.13%  (p=0.008 n=5+5)
CompileOnepass/^a(?:(b)|(c))c$-4              65.0 ± 0%      64.0 ± 0%   -1.54%  (p=0.008 n=5+5)
CompileOnepass/^a(?:b|c)$-4                   40.0 ± 0%      39.0 ± 0%   -2.50%  (p=0.008 n=5+5)
CompileOnepass/^a(?:b?|c)$-4                  57.0 ± 0%      56.0 ± 0%   -1.75%  (p=0.008 n=5+5)
CompileOnepass/^a(?:b?|c+)$-4                 63.0 ± 0%      62.0 ± 0%   -1.59%  (p=0.008 n=5+5)
CompileOnepass/^a(?:bc)+$-4                   46.0 ± 0%      45.0 ± 0%   -2.17%  (p=0.008 n=5+5)
CompileOnepass/^a(?:[bcd])+$-4                43.0 ± 0%      42.0 ± 0%   -2.33%  (p=0.008 n=5+5)
CompileOnepass/^a((?:[bcd])+)$-4              49.0 ± 0%      48.0 ± 0%   -2.04%  (p=0.008 n=5+5)
CompileOnepass/^a(:?b|c)*d$-4                  101 ± 0%       100 ± 0%   -0.99%  (p=0.008 n=5+5)
CompileOnepass/^.bc(d|e)*$-4                  60.0 ± 0%      59.0 ± 0%   -1.67%  (p=0.008 n=5+5)
CompileOnepass/^loooooooooooooooooo...-4     1.09k ± 0%     1.08k ± 0%   -0.74%  (p=0.008 n=5+5)

Fixes #19984

Change-Id: I2268b28d068926a057c62751528de15b6de61a7b
Reviewed-on: https://go-review.googlesource.com/40890Reviewed-by: default avatarRalph Corderoy <ralph@inputplus.co.uk>
Reviewed-by: default avatarBrad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent d71863ad
......@@ -305,13 +305,13 @@ func makeOnePass(p *onePassProg) *onePassProg {
var (
instQueue = newQueue(len(p.Inst))
visitQueue = newQueue(len(p.Inst))
check func(uint32, map[uint32]bool) bool
check func(uint32, []bool) bool
onePassRunes = make([][]rune, len(p.Inst))
)
// check that paths from Alt instructions are unambiguous, and rebuild the new
// program as a onepass program
check = func(pc uint32, m map[uint32]bool) (ok bool) {
check = func(pc uint32, m []bool) (ok bool) {
ok = true
inst := &p.Inst[pc]
if visitQueue.contains(pc) {
......@@ -442,7 +442,7 @@ func makeOnePass(p *onePassProg) *onePassProg {
instQueue.clear()
instQueue.insert(uint32(p.Start))
m := make(map[uint32]bool, len(p.Inst))
m := make([]bool, len(p.Inst))
for !instQueue.empty() {
visitQueue.clear()
pc := instQueue.next()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment