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

fix(sdk): Improve performance of RoomEvents::maybe_apply_new_redaction #4616

Conversation

Hywan
Copy link
Member

@Hywan Hywan commented Feb 4, 2025

This patch improves the performance of
RoomEvents::maybe_apply_new_redaction. This method deserialises all the events it receives, entirely. If the event is not an m.room.redaction, then the method returns early. Most of the time, the event is deserialised for nothing because most events aren't of kind m.room.redaction!

This patch first uses Raw::get_field("type") to detect the type of the event. If it's a m.room.redaction, then the event is entirely deserialised, otherwise the method returns.

When running the test_lazy_back_pagination from
#4594 with 10'000 events, prior to this patch, this method takes 11% of the execution time. With this patch, this method takes 2.5%.

Call tree before this patch:

Screenshot 2025-02-04 at 09 11 52

After this patch:

Screenshot 2025-02-04 at 09 15 20


…on`.

This patch improves the performance of
`RoomEvents::maybe_apply_new_redaction`. This method deserialises
all the events it receives, entirely. If the event is not an
`m.room.redaction`, then the method returns early. Most of the time,
the event is deserialised for nothing because most events aren't of kind
`m.room.redaction`!

This patch first uses `Raw::get_field("type")` to detect the type of
the event. If it's a `m.room.redaction`, then the event is entirely
deserialized, otherwise the method returns.

When running the `test_lazy_back_pagination` from
matrix-org#4594 with 10'000
events, prior to this patch, this method takes 11% of the execution
time. With this patch, this method takes 2.5%.
@Hywan Hywan requested a review from a team as a code owner February 4, 2025 08:28
@Hywan Hywan requested review from jmartinesp and removed request for a team February 4, 2025 08:28
Copy link
Contributor

@jmartinesp jmartinesp left a comment

Choose a reason for hiding this comment

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

LGTM!

Copy link

codecov bot commented Feb 4, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 85.73%. Comparing base (8513547) to head (d655359).
Report is 3 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4616   +/-   ##
=======================================
  Coverage   85.73%   85.73%           
=======================================
  Files         291      291           
  Lines       33309    33311    +2     
=======================================
+ Hits        28557    28559    +2     
  Misses       4752     4752           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@Hywan Hywan merged commit 3f71d9a into matrix-org:main Feb 4, 2025
40 checks passed
@bnjbvr
Copy link
Member

bnjbvr commented Feb 4, 2025

Nice. This calls for a deserialization cache, because we keep deserializing events all over the place…

@Hywan
Copy link
Member Author

Hywan commented Feb 4, 2025

Indeed. I was working on this but stopped due to lack of time, but it's definitely something that may improve the performance.

Hywan added a commit to Hywan/matrix-rust-sdk that referenced this pull request Feb 4, 2025
Hywan added a commit to Hywan/matrix-rust-sdk that referenced this pull request Feb 4, 2025
Hywan added a commit that referenced this pull request Feb 4, 2025
This patch adds #4601, #4608, #4612 and #4616 in their respective
`CHANGELOG.md`s.
toger5 pushed a commit to toger5/matrix-rust-sdk that referenced this pull request Feb 15, 2025
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.

3 participants