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

Use sync.Cond instead of channel for broadcast #4

Merged
merged 11 commits into from Dec 26, 2022
Merged

Use sync.Cond instead of channel for broadcast #4

merged 11 commits into from Dec 26, 2022

Conversation

kelindar
Copy link
Owner

This PR removes the usage of channel for broadcast and instead makes use of sync.Cond primitive directly. Subscribers are also flushed periodically to avoid lock contention. This results in ~2-4x performance improvement depending on the conditions.

Before

cpu: Intel(R) Core(TM) i7-9700K CPU @ 3.60GHz
BenchmarkEvent/1x1-8            21888343               109.0 ns/op         9175415 ev/s        0 B/op          0 allocs/op
BenchmarkEvent/1x10-8            3311071               724.4 ns/op        13803201 ev/s        0 B/op          0 allocs/op
BenchmarkEvent/1x100-8            514850              4750 ns/op          21049985 ev/s        0 B/op          0 allocs/op
BenchmarkEvent/10x1-8            2458360               975.9 ns/op        10245150 ev/s        0 B/op          0 allocs/op
BenchmarkEvent/10x10-8            447559              5236 ns/op          19085895 ev/s        0 B/op          0 allocs/op
BenchmarkEvent/10x100-8            30741             82802 ns/op          12080138 ev/s       14 B/op          0 allocs/op

After

BenchmarkEvent/1x1-8            69634809                38.07 ns/op       26245794 ev/s        0 B/op          0 allocs/op
BenchmarkEvent/1x10-8           15903538               188.2 ns/op        53029988 ev/s       10 B/op          0 allocs/op
BenchmarkEvent/1x100-8           1345704              1679 ns/op          59502067 ev/s       68 B/op          0 allocs/op
BenchmarkEvent/10x1-8            6537975               504.9 ns/op        19796366 ev/s        0 B/op          0 allocs/op
BenchmarkEvent/10x10-8           1740412              1979 ns/op          50472108 ev/s       87 B/op          0 allocs/op
BenchmarkEvent/10x100-8           160111             17376 ns/op          57290578 ev/s     2616 B/op          0 allocs/op

@kelindar kelindar merged commit 5ac9b3a into master Dec 26, 2022
@kelindar kelindar deleted the cond branch December 26, 2022 11:47
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.

None yet

1 participant