Open
Conversation
Signed-off-by: tomasz.ziolkowski <tomasz.ziolkowski@allegro.pl>
b67d772 to
9ecadbd
Compare
Signed-off-by: tomasz.ziolkowski <tomasz.ziolkowski@allegro.pl>
Owner
|
Hi, @ziollek! Thank you! I'll take a look into it and merge once I'm done |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Introduction
I've prepared a simplified implementation of an event bus that exposes interfaces very similar to those of the original
Bus. This eliminates the need to use reflection inPublish.Why?
The main goal was to provide a more efficient solution that does not rely entirely on reflection. However, this approach comes with limitations related to how generic types are handled in Go. Specifically, it allows subscribing with callbacks that accept only a single parameter of the type associated with a particular instance of
SimpleBus.How to use it
Key differences:
SubscriptionRefthat allowUnsubscribewithout engaging reflectionPublish, there is no lock held for the entire duration of executing listener callbacks.Performance analysis
To simplify performance comparisons, benchmarks have been added to the test files. Below are the results from my workstation:
Benchmark using a single core:
% GOMAXPROCS=1 go test -bench=. 2 goos: darwin goarch: amd64 pkg: github.com/ziollek/EventBus cpu: Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz BenchmarkSynchronousPublishing 2877297 406.9 ns/op BenchmarkAsynchronousPublishing 548457 2101 ns/op BenchmarkSimpleSynchronousPublishing 3939492 305.5 ns/op BenchmarkSimpleAsynchronousPublishing 1000000 1141 ns/opBenchmark using a two cores:
GOMAXPROCS=2 go test -bench=. 2 goos: darwin goarch: amd64 pkg: github.com/ziollek/EventBus cpu: Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz BenchmarkSynchronousPublishing-2 3146671 379.3 ns/op BenchmarkAsynchronousPublishing-2 1050337 1148 ns/op BenchmarkSimpleSynchronousPublishing-2 5079916 246.0 ns/op BenchmarkSimpleAsynchronousPublishing-2 2124786 548.2 ns/op