gookit / event

📢 Lightweight event manager and dispatcher implements by Go. Go实现的轻量级的事件管理、调度程序库, 支持设置监听器的优先级, 支持使用通配符来进行一组事件的监听
https://pgk.go.dev/github.com/gookit/event
MIT License
513 stars 59 forks source link

避免内存逃逸 #38

Closed colin1989 closed 1 year ago

colin1989 commented 1 year ago

未修改前:

goos: windows
goarch: amd64
pkg: github.com/gookit/event
cpu: Intel(R) Core(TM) i5-10400F CPU @ 2.90GHz
BenchmarkManager_Fire_no_listener
BenchmarkManager_Fire_no_listener-12             3589737               334.2 ns/
op            72 B/op          2 allocs/op
BenchmarkManager_Fire_normal
BenchmarkManager_Fire_normal-12                  3587448               335.9 ns/
op            72 B/op          2 allocs/op
BenchmarkManager_Fire_wildcard
BenchmarkManager_Fire_wildcard-12                2982114               379.5 ns/
op            72 B/op          2 allocs/op
PASS

修改后:

goos: windows
goarch: amd64
pkg: github.com/gookit/event
cpu: Intel(R) Core(TM) i5-10400F CPU @ 2.90GHz
BenchmarkManager_Fire_no_listener
BenchmarkManager_Fire_no_listener-12             4655372               256.5 ns/
op            48 B/op          1 allocs/op
BenchmarkManager_Fire_normal
BenchmarkManager_Fire_normal-12                  4646497               256.8 ns/
op            48 B/op          1 allocs/op
BenchmarkManager_Fire_wildcard
BenchmarkManager_Fire_wildcard-12                3997699               294.7 ns/
op            48 B/op          1 allocs/op
PASS