-
Notifications
You must be signed in to change notification settings - Fork 246
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
feat(base): Make Store::get_rooms
wayyy faster
#3552
Conversation
`Store::get_rooms` worked as follows: For each room ID, call * Take the read lock for `rooms`, * For each entry in `rooms`, take the room ID (the key), then call `Store::get_room`, which… * Take the read lock for `rooms`, * Based on the room ID (the key), read the room (the value) from `rooms`. So calling `get_rooms` calls `get_room` for each room, which takes the lock every time. This patch modifies that by fetching the values (the rooms) directly from `rooms`, without calling `get_room`. In my benchmark, it took 1.2ms to read 10'000 rooms. Now it takes 542µs. Performance time has improved by -55.8%.
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! (Would be nice to have a formal benchmark for this, that we can run with cargo-bench
, but the change is so obvious and trivial…)
Can you also fix get_rooms_filtered
, while you're at it, please? It does something similar.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #3552 +/- ##
==========================================
+ Coverage 83.80% 83.82% +0.01%
==========================================
Files 253 253
Lines 25854 25890 +36
==========================================
+ Hits 21668 21703 +35
- Misses 4186 4187 +1 ☔ View full report in Codecov by Sentry. |
About the benchmark, I've sadly lost it! Never run |
Just like in matrix-org#3552, this patch updates `Store::rooms_filtered` to not call `Store::room` so that it doesn't lock `rooms` for each item, thus making it way faster.
Just like in matrix-org#3552, this patch updates `Store::rooms_filtered` to not call `Store::room` so that it doesn't lock `rooms` for each item, thus making it way faster.
Just like in matrix-org#3552, this patch updates `Store::rooms_filtered` to not call `Store::room` so that it doesn't lock `rooms` for each item, thus making it way faster.
|
Store::get_rooms
worked as follows: For each room ID, callrooms
,rooms
, take the room ID (the key), then callStore::get_room
, which…rooms
,rooms
.So calling
get_rooms
callsget_room
for each room, which takes the lock every time.This patch modifies that by fetching the values (the rooms) directly from
rooms
, without callingget_room
.In my benchmark, it took 1.2ms to read 10'000 rooms. Now it takes 542µs. Performance time has improved by -55.8%.
Client::rooms_stream
#3068