-
Notifications
You must be signed in to change notification settings - Fork 6
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
Cache last published event #87
Conversation
d5aed6b
to
8aee172
Compare
I've pushed 4 commits to this, @goodhoko (and others) PTAL. It makes sense to review them one-by-one (and check their messages) if you're curious. It would be also interesting to run |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@strohel Nice, thanks! This looks good but I have some functional and stylistic remarks and questions.
b336f5f
to
789611c
Compare
…ro-sized-type The benchmark results are therefore not comparable before/after (they are 10% to 30% slower on my laptop).
and let subscribers receive it upon subscription. Closes #86
This fixes the performance regression for me, but we need to think whether that's worth the dependency tradeoff.
With a small trick (that unfortunately leaks to a public type) we were able to implement a kind of specialization [1] with perfect behavior: `Event`s don't pay the price for caching, and it is not possible to subscribe_and_receive_latest() to bare `Event`s. Also, it means that we didn't have to add bounds to `Event` [2]. [1] I thought the orphan rule would prevent us from adding the blanked implementation, but not! [2] I've sneaked in the removal of `'static`, but that's mostly aesthetic: `std::any::Any` requires it anyway.
...now that we have it in the dependency tree anyway. Allows us to remove the `RwLock` which in turn allows us to deduplicate subscribe_recipient() vs. subscribe_and_receive_latest(). Let's think about the possible situations of "publishing the first message" vs. "just subscribing and getting latest".
789611c
to
148227a
Compare
@goodhoko @bschwind alright I've:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work, @strohel! Thanks for taking this over, it's a pleasure see you work on something that excites you!
The benchmark results look good! If I read them right, this PR no longer causes noticeable performance regression. This is equally true for using dashmap and intelligent locking (i.e. upgrade()
).
There's a significant (and expected) difference in performance of the cacheable event when there are multiple publishers between Dashmap and intelligent locking. IMO that's totally ok!
I gave this one more thorough read and it looks good, though I have couple last remarks.
@bschwind @goodhoko (sorry I meant to submit this right after the benchmark results Benchmark Observations
Conclusion
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! No nits or issues with the code that I see :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! (I can't formally approve as the author of this PR.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
This was successfully tested in https://github.com/tonarino/portal/pull/3746. Should be good to merge! |
Co-authored-by: Matěj Laitl <[email protected]>
and let subscribers receive it upon subscription.
Optionally, we could provide a separate marker trait for cached events and persist only those. I couldn't figure out how to dynamically query for the type (trait) in
publish
. Somehowdowncast_ref
is not implemented forEvent
(despiteEvent
beingAny
). I'd appreciate some help with that.This causes performance regression for the pub-sub system. Here's output of
cargo bench --bench pub_sub
running on this branch (comparing it to the previous run onmain
):Details
That's likely caused by the contention on
SystemHandle::event_subscribers
RwLock. Previously it only needed exclusive access when subscribing and shared access when publishing. Now it needs exclusive access when subscribing and publishing.Closes #86
This is a semver-breaking change (due to the new bounds on Event).