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

IDBObjectStore.count is O(n^2) #94

Closed
richvdh opened this issue Dec 29, 2023 · 3 comments
Closed

IDBObjectStore.count is O(n^2) #94

richvdh opened this issue Dec 29, 2023 · 3 comments

Comments

@richvdh
Copy link

richvdh commented Dec 29, 2023

The implementation of IDBObjectStore.count uses a cursor internally, which would be fine, except that iterating a cursor is O(n) in the number of entries in the store (FDBCursor.iterate looks through all entries until it finds one whose position is greater than that of the cursor).

The net result is that IDBObjectStore.count is extremely slow, to the extent that it's much faster to call IDBObjectStore.getAllKeys() and count the results in the array... provided, of course, that it fits in memory.

@dumbmatter
Copy link
Owner

Yeah that is excessively slow! Well, a lot of things in this library are not exactly optimized for speed, but if it's a small amount of code for a big speed up, then that should be done.

Does #95 fix things for your use case?

@richvdh
Copy link
Author

richvdh commented Dec 29, 2023

Wow, that was quick! Yes, that's much better, thank you!

@dumbmatter
Copy link
Owner

I saw the notification and was like "come on, no way it's that slow" so I had to investigate and... it was that slow lol

Released in version 5.0.2

richvdh added a commit to matrix-org/matrix-js-sdk that referenced this issue Jan 2, 2024
richvdh added a commit to matrix-org/matrix-js-sdk that referenced this issue Jan 3, 2024
richvdh added a commit to matrix-org/matrix-js-sdk that referenced this issue Jan 3, 2024
richvdh added a commit to matrix-org/matrix-js-sdk that referenced this issue Jan 8, 2024
richvdh added a commit to matrix-org/matrix-js-sdk that referenced this issue Jan 8, 2024
github-merge-queue bot pushed a commit to matrix-org/matrix-js-sdk that referenced this issue Jan 8, 2024
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

No branches or pull requests

2 participants