1
0
mirror of https://github.com/golang/go synced 2024-11-19 16:44:43 -07:00
go/src/regexp
Javier Kohen 7dbf9d43f5 regexp: use sync.Pool to cache regexp.machine objects
Performance optimization for the internals of the Regexp type. This adds
no features and has no user-visible impact beyond performance. Copy now
shares the cache, so memory usage for programs that use Copy a lot
should go down; Copy has effectively become a no-op.

The before v. after benchmark results show a lot of noise from run to
run, but there's a clear improvement to the Shared case and no detriment
to the Copied case.

BenchmarkMatchParallelShared-4                        361           77.9          -78.42%
BenchmarkMatchParallelCopied-4                        70.3          72.2          +2.70%

Macro benchmarks show that the lock contention in Regexp is gone, and my
server is now able to scale linearly 2.5x times more than before (and I
only stopped there because I ran out of CPU in my test machine).

Fixes #24411

Change-Id: Ib33abff2802f27599f5d09084775e95b54e3e1d7
Reviewed-on: https://go-review.googlesource.com/101715
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-04-03 16:03:19 +00:00
..
syntax regexp/syntax: update perl script to preserve \s behavior 2018-03-29 22:31:57 +00:00
testdata
all_test.go regexp: don't allocate when All methods find no matches 2018-02-13 18:44:40 +00:00
backtrack.go regexp: make (*bitState).push inlinable 2017-09-25 19:34:26 +00:00
example_test.go regexp: examples for Regexp.Expand and Regexp.ExpandString functions 2017-08-28 15:34:19 +00:00
exec2_test.go
exec_test.go all: revert "all: prefer strings.IndexByte over strings.Index" 2017-10-05 23:19:10 +00:00
exec.go all: unindent some if bodies by exiting early 2017-10-31 20:07:46 +00:00
find_test.go
onepass_test.go regexp: reduce allocations at onePassCopy 2017-03-28 17:58:10 +00:00
onepass.go all: use strings.Builder instead of bytes.Buffer where appropriate 2018-03-26 23:05:53 +00:00
regexp.go regexp: use sync.Pool to cache regexp.machine objects 2018-04-03 16:03:19 +00:00