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

Speed up loading ACLs on startup #3469

Merged
merged 6 commits into from
Dec 19, 2024
Merged

Speed up loading ACLs on startup #3469

merged 6 commits into from
Dec 19, 2024

Conversation

S7evinK
Copy link
Contributor

@S7evinK S7evinK commented Dec 19, 2024

Currently d.m.org struggles to start, as it is fetching several thousand ACLs on startup.
The reason is that we're loading the entire room state into memory, only to filter out the majority of it, because we only care about certain types.

This change filters the types (tuples) directly when querying the database, so we don't end up with unneeded state.

@S7evinK S7evinK requested a review from a team as a code owner December 19, 2024 10:45
@codecov-commenter
Copy link

codecov-commenter commented Dec 19, 2024

Codecov Report

Attention: Patch coverage is 68.18182% with 21 lines in your changes missing coverage. Please review.

Project coverage is 49.40%. Comparing base (556a5a9) to head (83a2c7d).
Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
roomserver/storage/shared/storage.go 58.33% 13 Missing and 7 partials ⚠️
roomserver/acls/acls.go 94.44% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3469      +/-   ##
==========================================
- Coverage   49.42%   49.40%   -0.02%     
==========================================
  Files         524      524              
  Lines       59674    59737      +63     
==========================================
+ Hits        29493    29513      +20     
- Misses      26713    26743      +30     
- Partials     3468     3481      +13     
Flag Coverage Δ
unittests 49.40% <68.18%> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

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

@S7evinK
Copy link
Contributor Author

S7evinK commented Dec 19, 2024

While I only tested this with the initial attempt of just replacing loadStateAtSnapshot with LoadStateAtSnapshotForStringTuples, the difference is quite obvious:

Only logging the duration:

// old
time="2024-12-19T10:58:27.882602160Z" level=info msg="Got 8 server ACLs in 82.324207ms"
// new
time="2024-12-19T10:58:48.503895143Z" level=info msg="Got 8 server ACLs in 42.418627ms"

Logging returned events per room:

// old
time="2024-12-19T11:09:43.827393764Z" level=info msg="Got 99 state events"
time="2024-12-19T11:09:43.828435599Z" level=info msg="Got 73 state events"
time="2024-12-19T11:09:43.838359808Z" level=info msg="Got 1046 state events"
time="2024-12-19T11:09:43.860218366Z" level=info msg="Got 8331 state events"
time="2024-12-19T11:09:43.874318545Z" level=info msg="Got 4374 state events"
time="2024-12-19T11:09:43.883133614Z" level=info msg="Got 1878 state events"
time="2024-12-19T11:09:43.900711277Z" level=info msg="Got 4196 state events"
time="2024-12-19T11:09:43.905420693Z" level=info msg="Got 342 state events"
// new
time="2024-12-19T11:09:02.512421878Z" level=info msg="Got 1 state events"
time="2024-12-19T11:09:02.513694809Z" level=info msg="Got 1 state events"
time="2024-12-19T11:09:02.521480413Z" level=info msg="Got 1 state events"
time="2024-12-19T11:09:02.529054298Z" level=info msg="Got 1 state events"
time="2024-12-19T11:09:02.533625798Z" level=info msg="Got 1 state events"
time="2024-12-19T11:09:02.538014702Z" level=info msg="Got 1 state events"
time="2024-12-19T11:09:02.543541474Z" level=info msg="Got 1 state events"
time="2024-12-19T11:09:02.550731063Z" level=info msg="Got 1 state events"

@S7evinK S7evinK force-pushed the s7evink/faster-acl-loading branch from 1b98ee5 to 5cd4442 Compare December 19, 2024 19:59
@S7evinK S7evinK force-pushed the s7evink/faster-acl-loading branch from 5cd4442 to 83a2c7d Compare December 19, 2024 20:00
@S7evinK S7evinK enabled auto-merge (squash) December 19, 2024 20:11
@S7evinK S7evinK merged commit add73ec into main Dec 19, 2024
21 checks passed
@S7evinK S7evinK deleted the s7evink/faster-acl-loading branch December 19, 2024 20:24
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