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

Factor out ReceiptAccumulator #3319

Merged
merged 2 commits into from
Apr 26, 2023

Conversation

andybalaam
Copy link
Contributor

@andybalaam andybalaam commented Apr 26, 2023

Part of element-hq/element-web#24629

In order to allow us to write simple unit tests, factor out the part of the sync accumulator that does receipt handling. Later changes may well make this more self-contained. This change is intended to be simple enough that we can convince ourselves by examining it that it has the same behaviour as before.

This code is performance-critical, so I added a couple of tests. When I increased the testSize in those tests to 10 million and 1 million, I got these results:

With the old code:

✓ can handle large numbers of identical receipts (8760 ms)
✓ can handle large numbers of receipts for different users and events (12123 ms)

With the new code:

✓ can handle large numbers of identical receipts (9035 ms)
✓ can handle large numbers of receipts for different users and events (10800 ms)

So this change appears to slow us slightly when we have lots of redundant receipts, and speed us up when we have lots of receipts that we want to keep around.

I expect the speed changes are due to the use of a Map instead of an object.

I think the this change is acceptable, and I think using a Map is better generally, but am interested in others' opinions.


This change is marked as an internal change (Task), so will not be included in the changelog.

@andybalaam andybalaam added the T-Task Tasks for the team like planning label Apr 26, 2023
@andybalaam andybalaam force-pushed the andybalaam/factor-out-receipt-accumulator branch from a393d28 to 6bc9128 Compare April 26, 2023 14:05
@andybalaam
Copy link
Contributor Author

Added @weeman1337 as a potential reviewer

Copy link
Contributor

@germain-gg germain-gg left a comment

Choose a reason for hiding this comment

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

💯 ! Thank you

Copy link
Contributor

@weeman1337 weeman1337 left a comment

Choose a reason for hiding this comment

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

Looks good. 👍 Some smaller notes.

src/receipt-accumulator.ts Show resolved Hide resolved
@@ -43,6 +44,12 @@ export interface IMinimalEvent {
unsigned?: IUnsigned;
}

export interface AccumulatedReceipt {
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like this belongs to the ReceiptAccumulator and should eventually be moved to the receipt-accumulator module?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed in next PR: #3320

src/receipt-accumulator.ts Show resolved Hide resolved
@andybalaam
Copy link
Contributor Author

Thank you @weeman1337 - I will address all your comments in my next PR

@andybalaam andybalaam dismissed weeman1337’s stale review April 26, 2023 15:07

Addressed in next PR

@andybalaam andybalaam added this pull request to the merge queue Apr 26, 2023
Merged via the queue into develop with commit 93e2135 Apr 26, 2023
@andybalaam andybalaam deleted the andybalaam/factor-out-receipt-accumulator branch April 26, 2023 15:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T-Task Tasks for the team like planning
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants