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

Element-R | count() room keys can be a slow operation on big stores, causing send performance degradation when backing up. #26893

Closed
BillCarsonFr opened this issue Jan 18, 2024 · 3 comments · Fixed by matrix-org/matrix-js-sdk#4015
Assignees
Labels
A-Element-R Issues affecting the port of Element's crypto layer to Rust Z-Labs

Comments

@BillCarsonFr
Copy link
Member

During the backup key loop (uploading keys to the remote backup), Element-R will invoke olmMachine.roomKeyCounts().
When this operation become slow, send performaces are degraded.

Step to reproduce

Can be reproduced by typing this in the console:

window.indexedDB.open("matrix-js-sdk::matrix-sdk-crypto", 8).onsuccess = (event) => {
    const db = event.target.result;
    const start = Date.now();
    const tx = db.transaction(["inbound_group_sessions2"], "readonly");
    const object_store = tx.objectStore("inbound_group_sessions2");
    const req = object_store.count()
    req.onsuccess = (event) => { 
        console.log("## Count", event.target.result);
    };
    req.onerror  = (event) => { console.info(" ## fail to count")};
    tx.oncomplete = (() => {
        const now = Date.now();
        console.info("## Perf: count took:", now - start, "ms")
    });
}

Just after starting this, you can try to send a message. It will be blocked until the count request has completed.

The count performances are particularly bad on Firefox M1 from my testing:

Firefox:

23:07:18,566 ## Count 190003 bundle.js:262316:19
23:07:18,579 ## Perf: count took: 39182 ms

23:09:07,297 ## Count 190003 bundle.js:262316:19
23:09:07,322 ## Perf: count took: 38755 ms

There is a threshold on FF (mac M1), where the count performances drops and stop beeing O(n)

image

Not seen in Chrome (mac m1)

image

I tested on another mac (intel chip) on FF and performances stays in O(n).

This also direclty related to the size of keys in the object store (dividing the size of each room key will delay the threshold where performances drop)

@BillCarsonFr BillCarsonFr added the A-Element-R Issues affecting the port of Element's crypto layer to Rust label Jan 18, 2024
@BillCarsonFr
Copy link
Member Author

Related to #26783

This comment was marked as off-topic.

@ara4n
Copy link
Member

ara4n commented Jan 23, 2024

confirmed fixed for me - thanks \o/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Element-R Issues affecting the port of Element's crypto layer to Rust Z-Labs
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants