You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
(This is go tool pprof output profiling against my program, so it contains m.backtrack allocations too, but please ignore it (L439).)
For example, regexp.MustCompile("^[a-z]$").Match([]byte("a")) should not allocate memory unnecessarily at L450 (dstCap = append(dstCap, m.matchcap...)), but allocation occurs because len(m.matchcap) == 2.
As for matching of non onepass regex (e.g. .*[a-z] or something), m.backtrack(i, pos, size, ncap) or m.init(ncap) reset m.matchcap length to zero (ncap==0 for regexp.Match) and doesn't allocate memory at L450.
1 allocation for regexp.Match of onepass regexp at L450 (dstCap = append(dstCap, m.matchcap...)).
It's only one needless allocation, but regex will be often called a lot of times.
My program which heavily uses onepass regexp Match actually speedup by about 10% by removing the needless allocation.
System details
go version go1.8 linux/amd64
GOARCH="amd64"
GOBIN="/home/haya14busa/go/bin"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/haya14busa"
GORACE=""
GOROOT="/usr/lib/go"
GOTOOLDIR="/usr/lib/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build371996710=/tmp/go-build -gno-record-gcc-switches"
CXX="g++"
CGO_ENABLED="1"
PKG_CONFIG="pkg-config"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
GOROOT/bin/go version: go version go1.8 linux/amd64
GOROOT/bin/go tool compile -V: compile version go1.8 X:framepointer
uname -sr: Linux 4.4.48-1-MANJARO
LSB Version: n/a
Distributor ID: ManjaroLinux
Description: Manjaro Linux
Release: 16.10
Codename: Fringilla
/usr/lib/libc.so.6: GNU C Library (GNU libc) stable release version 2.24, by Roland McGrath et al.
gdb --version: GNU gdb (GDB) 7.12.1
The text was updated successfully, but these errors were encountered:
Please answer these questions before submitting your issue. Thanks!
What did you do?
I noticed that
regexp.Match
allocates memory unnecessarily while profiling aprogram which uses "onepass regex" a lot (e.g.
^[a-z]$
).(This is go tool pprof output profiling against my program, so it contains m.backtrack allocations too, but please ignore it (L439).)
For example,
regexp.MustCompile("^[a-z]$").Match([]byte("a"))
should not allocate memory unnecessarily at L450 (dstCap = append(dstCap, m.matchcap...)
), but allocation occurs becauselen(m.matchcap) == 2
.As for matching of non onepass regex (e.g.
.*[a-z]
or something),m.backtrack(i, pos, size, ncap)
orm.init(ncap)
resetm.matchcap
length to zero (ncap==0 for regexp.Match) and doesn't allocate memory at L450.What did you expect to see?
No allocation for regexp.Match of onepass regexp.
See CL for benchmark script.
What did you see instead?
1 allocation for regexp.Match of onepass regexp at L450 (
dstCap = append(dstCap, m.matchcap...)
).It's only one needless allocation, but regex will be often called a lot of times.
My program which heavily uses onepass regexp Match actually speedup by about 10% by removing the needless allocation.
System details
The text was updated successfully, but these errors were encountered: