signal/go-uasparser — pull request #4 by sebest (2014-09-21 12:47:29+00:00)
Title: Really slow performance, maybe related to regexp

Hello,

I added a benchmark and i have slow performance on AWS instance (m3.medium): 11.8ms to parse one UserAgent and 4.8ms on my macbook pro i7.

Do you observe the same performance?

Note that profiling cpu on OSX seems broken and this is a known issue.

Here are the full results:
# make profile-txt
go test -v -bench=. -run='Benchmark*' -cpuprofile cpu.pprof
PASS
BenchmarkParse_FindOperaMobileBrowser	100	11819250 ns/op
ok	github.com/sebest/go-uasparser	1.569s
go tool pprof --text ./go-uasparser.test cpu.pprof
Total: 115 samples
33 28.7% 28.7% 34 29.6% regexp.(*machine).add
26 22.6% 51.3% 91 79.1% regexp.(*machine).step
21 18.3% 69.6% 29 25.2% unicode.SimpleFold
8 7.0% 76.5% 111 96.5% regexp.(*machine).match
6 5.2% 81.7% 35 30.4% regexp/syntax.(*Inst).MatchRunePos
6 5.2% 87.0% 6 5.2% regexp/syntax.EmptyOpContext
5 4.3% 91.3% 5 4.3% unicode.ToLower
3 2.6% 93.9% 3 2.6% unicode.ToUpper
1 0.9% 94.8% 1 0.9% MCentral_Grow
1 0.9% 95.7% 3 2.6% github.com/sebest/go-uasparser.(*Manifest).FindRobot
1 0.9% 96.5% 1 0.9% regexp.(*inputString).step
1 0.9% 97.4% 1 0.9% regexp.(*machine).alloc
1 0.9% 98.3% 36 31.3% regexp/syntax.(*Inst).MatchRune
1 0.9% 99.1% 2 1.7% runtime.mallocgc
1 0.9% 100.0% 1 0.9% sync.(*Mutex).Unlock
0 0.0% 100.0% 3 2.6% github.com/sebest/go-uasparser.(*Manifest).IsRobot
0 0.0% 100.0% 115 100.0% github.com/sebest/go-uasparser.(*Manifest).Parse
0 0.0% 100.0% 3 2.6% github.com/sebest/go-uasparser.(*Manifest).ParseBrowserVersion
0 0.0% 100.0% 96 83.5% github.com/sebest/go-uasparser.(*Manifest).ParseDevice
0 0.0% 100.0% 13 11.3% github.com/sebest/go-uasparser.(*Manifest).ParseOs
0 0.0% 100.0% 115 100.0% github.com/sebest/go-uasparser.BenchmarkParse_FindOperaMobileBrowser
0 0.0% 100.0% 3 2.6% regexp.(*Regexp).FindStringSubmatch
0 0.0% 100.0% 109 94.8% regexp.(*Regexp).MatchString
0 0.0% 100.0% 112 97.4% regexp.(*Regexp).doExecute
0 0.0% 100.0% 1 0.9% regexp.(*Regexp).put
0 0.0% 100.0% 1 0.9% runtime.MCache_Refill
0 0.0% 100.0% 1 0.9% runtime.MCentral_CacheSpan
0 0.0% 100.0% 115 100.0% runtime.gosched0
0 0.0% 100.0% 2 1.7% runtime.new
0 0.0% 100.0% 2 1.7% strings.Trim
0 0.0% 100.0% 2 1.7% strings.makeCutsetFunc
0 0.0% 100.0% 115 100.0% testing.(*B).launch
0 0.0% 100.0% 115 100.0% testing.(*B).runN