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

避免内存逃逸 #38

Merged
merged 1 commit into from
Oct 28, 2022
Merged

避免内存逃逸 #38

merged 1 commit into from
Oct 28, 2022

Conversation

colin1989
Copy link

@colin1989 colin1989 commented Oct 28, 2022

未修改前:

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

减少gc压力
@inhere inhere added the enhancement New feature or request label Oct 28, 2022
@inhere inhere self-assigned this Oct 28, 2022
@inhere inhere merged commit 635b210 into gookit:master Oct 28, 2022
name: name,
data: data,
}
}

// Abort event loop exec
func (e *BasicEvent) Abort(abort bool) {
func (e BasicEvent) Abort(abort bool) {
e.aborted = abort
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

此处修改会导致设置的值不生效吧?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

嗯.这里漏考虑了

e.aborted = abort
}

// Fill event data
func (e *BasicEvent) Fill(target interface{}, data M) *BasicEvent {
func (e BasicEvent) Fill(target interface{}, data M) BasicEvent {
if data != nil {
e.data = data
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

非指针不能这么赋值吧?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

是有点问题,单元测试过不了了。

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

Successfully merging this pull request may close these issues.

3 participants