Skip to content
This repository has been archived by the owner on Nov 25, 2024. It is now read-only.

Optimize PrevEventIDs when getting thousands of backwards extremeties #3308

Merged
merged 14 commits into from
Jan 20, 2024

Conversation

S7evinK
Copy link
Contributor

@S7evinK S7evinK commented Jan 18, 2024

Changes how many PrevEventIDs we send to other servers when backfilling, capped to 100 events.

Unsure about how representative this benchmark is..

goos: linux
goarch: amd64
pkg: github.com/matrix-org/dendrite/roomserver/api
cpu: Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz
                            │    old.txt     │               new.txt               │
                            │     sec/op     │   sec/op     vs base                │
PrevEventIDs/Original1-8         264.9n ± 5%   237.4n ± 7%  -10.36% (p=0.000 n=10)
PrevEventIDs/Original10-8        3.101µ ± 4%   1.590µ ± 2%  -48.72% (p=0.000 n=10)
PrevEventIDs/Original100-8       44.32µ ± 2%   12.80µ ± 4%  -71.11% (p=0.000 n=10)
PrevEventIDs/Original500-8     263.835µ ± 4%   7.907µ ± 4%  -97.00% (p=0.000 n=10)
PrevEventIDs/Original1000-8    578.798µ ± 2%   7.620µ ± 2%  -98.68% (p=0.000 n=10)
PrevEventIDs/Original2000-8   1272.039µ ± 2%   8.241µ ± 9%  -99.35% (p=0.000 n=10)
geomean                          43.81µ        3.659µ       -91.65%

                            │    old.txt     │               new.txt                │
                            │      B/op      │     B/op      vs base                │
PrevEventIDs/Original1-8          72.00 ± 0%     48.00 ± 0%  -33.33% (p=0.000 n=10)
PrevEventIDs/Original10-8        1512.0 ± 0%     500.0 ± 0%  -66.93% (p=0.000 n=10)
PrevEventIDs/Original100-8     11.977Ki ± 0%   7.023Ki ± 0%  -41.36% (p=0.000 n=10)
PrevEventIDs/Original500-8     67.227Ki ± 0%   7.023Ki ± 0%  -89.55% (p=0.000 n=10)
PrevEventIDs/Original1000-8   163.227Ki ± 0%   7.023Ki ± 0%  -95.70% (p=0.000 n=10)
PrevEventIDs/Original2000-8   347.227Ki ± 0%   7.023Ki ± 0%  -97.98% (p=0.000 n=10)
geomean                         12.96Ki        1.954Ki       -84.92%

                            │   old.txt   │              new.txt               │
                            │  allocs/op  │ allocs/op   vs base                │
PrevEventIDs/Original1-8       2.000 ± 0%   1.000 ± 0%  -50.00% (p=0.000 n=10)
PrevEventIDs/Original10-8      6.000 ± 0%   2.000 ± 0%  -66.67% (p=0.000 n=10)
PrevEventIDs/Original100-8     9.000 ± 0%   3.000 ± 0%  -66.67% (p=0.000 n=10)
PrevEventIDs/Original500-8    12.000 ± 0%   3.000 ± 0%  -75.00% (p=0.000 n=10)
PrevEventIDs/Original1000-8   14.000 ± 0%   3.000 ± 0%  -78.57% (p=0.000 n=10)
PrevEventIDs/Original2000-8   16.000 ± 0%   3.000 ± 0%  -81.25% (p=0.000 n=10)
geomean                        8.137        2.335       -71.31%

Copy link

codecov bot commented Jan 18, 2024

Codecov Report

Attention: 3 lines in your changes are missing coverage. Please review.

Comparison is base (d357615) 65.50% compared to head (2d31de9) 65.34%.

Files Patch % Lines
federationapi/routing/backfill.go 0.00% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3308      +/-   ##
==========================================
- Coverage   65.50%   65.34%   -0.16%     
==========================================
  Files         509      509              
  Lines       57493    57514      +21     
==========================================
- Hits        37659    37585      -74     
- Misses      15960    16030      +70     
- Partials     3874     3899      +25     
Flag Coverage Δ
unittests 50.08% <88.00%> (+0.03%) ⬆️

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

This comment was marked as outdated.

@S7evinK S7evinK marked this pull request as ready for review January 19, 2024 09:16
@S7evinK S7evinK requested a review from a team as a code owner January 19, 2024 09:16
Copy link
Member

@kegsay kegsay left a comment

Choose a reason for hiding this comment

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

Needs more documentation, the general idea LGTM though.

roomserver/api/perform.go Outdated Show resolved Hide resolved
roomserver/api/perform.go Outdated Show resolved Hide resolved
roomserver/api/perform.go Outdated Show resolved Hide resolved
}
prevEventIDs = util.UniqueStrings(prevEventIDs)
// If we still have > 100 eventIDs, only return the first 100
if len(prevEventIDs) > 100 {
return prevEventIDs[:100]
Copy link
Member

Choose a reason for hiding this comment

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

Again, arbitrary and needs justification. Also need to justify why we just spent all this time getting 1000 only to take 100 of them. At what point would a map[string]struct{} be better than this?

Copy link
Contributor Author

@S7evinK S7evinK Jan 20, 2024

Choose a reason for hiding this comment

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

Looks like map[string]struct{} has the best results - 1 more alloc compared to the "original" change and otherwise much better, see updated PR description.

roomserver/api/perform_test.go Show resolved Hide resolved
roomserver/api/perform_test.go Show resolved Hide resolved
@S7evinK S7evinK merged commit 8e4dc6b into main Jan 20, 2024
20 checks passed
@S7evinK S7evinK deleted the s7evink/backfill-prev-eventIDs branch January 20, 2024 21:26
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants