Skip to content

perf(search): cache the tantivy IndexReader on RoomIndex#6707

Merged
stefanceriu merged 1 commit into
matrix-org:mainfrom
procr1337:search-reader-recreation-fix
Jul 2, 2026
Merged

perf(search): cache the tantivy IndexReader on RoomIndex#6707
stefanceriu merged 1 commit into
matrix-org:mainfrom
procr1337:search-reader-recreation-fix

Conversation

@procr1337

@procr1337 procr1337 commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

This is a fix for a performance issue we encountered when backfilling events into the search engine in a real matrix room with 10k+ messages. The issue is that RoomIndex::bulk_execute performs reading operations between each write (e.g. inside ::add(), it calls ::contains(), which transitively calls ::get_reader()). The reader creation would take about ~30ms in this case per inserted event, which is highly prohibitive.

  • I've documented the public API changes in the appropriate changelog files
  • This PR was made with the help of AI.

Signed-off-by: Procr <193802945+procr1337@users.noreply.github.com>
@procr1337 procr1337 force-pushed the search-reader-recreation-fix branch from e0bf201 to 0346d34 Compare June 30, 2026 21:19
@procr1337 procr1337 marked this pull request as ready for review June 30, 2026 21:20
@procr1337 procr1337 requested a review from a team as a code owner June 30, 2026 21:20
@procr1337 procr1337 requested review from stefanceriu and removed request for a team June 30, 2026 21:20
@codecov

codecov Bot commented Jun 30, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 90.90909% with 1 line in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (main@023f5bd). Learn more about missing BASE report.
⚠️ Report is 6 commits behind head on main.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
crates/matrix-sdk-search/src/index/mod.rs 90.90% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #6707   +/-   ##
=======================================
  Coverage        ?   89.95%           
=======================================
  Files           ?      397           
  Lines           ?   110660           
  Branches        ?   110660           
=======================================
  Hits            ?    99539           
  Misses          ?     7351           
  Partials        ?     3770           

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

@procr1337

procr1337 commented Jun 30, 2026

Copy link
Copy Markdown
Contributor Author

@stefanceriu the codecov report seems broken, it doesn't show any info about covered or uncovered lines. It just says "No Files covered by tests were changed"

@codspeed-hq

codspeed-hq Bot commented Jun 30, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 50 untouched benchmarks


Comparing procr1337:search-reader-recreation-fix (0346d34) with main (023f5bd)

Open in CodSpeed

@stefanceriu stefanceriu left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks great to me, thank you for taking the time!

@stefanceriu stefanceriu enabled auto-merge (rebase) July 1, 2026 08:22
@stefanceriu stefanceriu merged commit c3fd7eb into matrix-org:main Jul 2, 2026
125 of 131 checks passed
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.

2 participants