Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve scanner.Map's performance by caching resolved tags #128

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

fangwentong
Copy link

scanner.Map方法通过反射获取key name,开销较大,这里通过缓存结构体的key name解析结果来提升性能。

具体表现如下,通过使用缓存可以将scanner.Map接口的吞吐提升1-2倍。

$ go test -run=BenchmarkMap -bench=BenchmarkMap -cpu=1,2,4,8 -benchtime=20000000x -benchmem
goos: darwin
goarch: amd64
pkg: github.com/didi/gendry/scanner
cpu: Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
BenchmarkMapWithCache           20000000               265.4 ns/op           360 B/op          4 allocs/op
BenchmarkMapWithCache-2         20000000               152.2 ns/op           360 B/op          4 allocs/op
BenchmarkMapWithCache-4         20000000                88.22 ns/op          360 B/op          4 allocs/op
BenchmarkMapWithCache-8         20000000                70.87 ns/op          360 B/op          4 allocs/op
BenchmarkMapDisableCache        20000000               695.3 ns/op           400 B/op          9 allocs/op
BenchmarkMapDisableCache-2      20000000               348.7 ns/op           400 B/op          9 allocs/op
BenchmarkMapDisableCache-4      20000000               195.2 ns/op           400 B/op          9 allocs/op
BenchmarkMapDisableCache-8      20000000               169.8 ns/op           400 B/op          9 allocs/op
PASS
ok      github.com/didi/gendry/scanner  39.892s

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant