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

Improve pouchDB performances #1537

Merged
merged 2 commits into from
Oct 3, 2024
Merged

Improve pouchDB performances #1537

merged 2 commits into from
Oct 3, 2024

Conversation

paultranvan
Copy link
Contributor

We noticed severe performances issues when using pouchdb in a react-native environment.
See commit descriptions for more insights

BEFORE

Indexing time : 53 868 ms
Query time : 51 499 ms

AFTER

Indexing time : 31 833 ms
Query time : 1 854 ms

The `view_update_changes_batch_size` parameter is used to determine the
docs batch size when computing view updates. PouchDB default is 50,
which is quite low, and badly hurt performancs when dealing with
thousands of docs and the first view computation.

With a 44K files database, in a react-native env:

**Before:**
Indexing time: 53 868 ms

**After:**
Indexing time: 31 833 ms
The react-native PouchDB adapter does not handle partialIndexes: it
means that any predicate in partialIndex will not be evaluated at
indexing time, but at querying time.
When dealing with huge database, this can be quite impactful because it
will result in full-scan of huge indexes.

Therefore, we now force the indexing of any field in partialIndex, to
guarantee a doc will be indexed if and only if it has all the necessary
attributes.

We measured performances for this query:
https://github.com/cozy/mespapiers/blob/
e456faaa00dcefef13c6eee88459caffcac4f2d4/src/queries/index.js#L64-L105

**Before:**
Query time: 51 499 ms

**After:**
Query time: 1 854 ms
indexedFields = Array.from(
new Set([...indexedFields, ...Object.keys(partialFilter)])
)
// FIXME: should properly handle n-level attributes
Copy link
Member

@Ldoppea Ldoppea Oct 3, 2024

Choose a reason for hiding this comment

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

What's the impact for now? Should we handle this soon? Or it is for an hypothetical future?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For now it means that if we have queries with partialIndex having attributes not on the root level, i.e. with $and: [{...}], we won't benefit from this fix. Thus slow queries.
So hopefully there is no regression regarding the current offline, but we should test it carefully

@paultranvan paultranvan merged commit c6315e6 into master Oct 3, 2024
4 checks passed
@paultranvan paultranvan deleted the pouch-perfs branch October 3, 2024 12:55
Ldoppea added a commit to cozy/cozy-flagship-app that referenced this pull request Oct 3, 2024
`cozy-pouch-link` has been upgraded to `49.1.0` to retrieve performance
improvements on Pouch queries

Related PR: cozy/cozy-client#1537
@Crash--
Copy link
Contributor

Crash-- commented Oct 4, 2024

Nice!

30s to index 40k documents is still huge :(

@paultranvan
Copy link
Contributor Author

30s to index 40k documents is still huge :(

It is indeed. While this time would be dramatically reduced on a more powerful device, this is disappointing, but not so surprising regarding previous performances measures, that tend to show massive performances differences depending on the adapter and document size :
image

Ldoppea added a commit to cozy/cozy-flagship-app that referenced this pull request Nov 12, 2024
`cozy-pouch-link` has been upgraded to `49.1.0` to retrieve performance
improvements on Pouch queries

Related PR: cozy/cozy-client#1537
Ldoppea added a commit to cozy/cozy-flagship-app that referenced this pull request Dec 19, 2024
`cozy-pouch-link` has been upgraded to `49.1.0` to retrieve performance
improvements on Pouch queries

Related PR: cozy/cozy-client#1537
Ldoppea added a commit to cozy/cozy-flagship-app that referenced this pull request Dec 20, 2024
`cozy-pouch-link` has been upgraded to `49.1.0` to retrieve performance
improvements on Pouch queries

Related PR: cozy/cozy-client#1537
Ldoppea added a commit to cozy/cozy-flagship-app that referenced this pull request Dec 20, 2024
`cozy-pouch-link` has been upgraded to `49.1.0` to retrieve performance
improvements on Pouch queries

Related PR: cozy/cozy-client#1537
Ldoppea added a commit to cozy/cozy-flagship-app that referenced this pull request Dec 20, 2024
`cozy-pouch-link` has been upgraded to `49.1.0` to retrieve performance
improvements on Pouch queries

Related PR: cozy/cozy-client#1537
Ldoppea added a commit to cozy/cozy-flagship-app that referenced this pull request Dec 20, 2024
`cozy-pouch-link` has been upgraded to `49.1.0` to retrieve performance
improvements on Pouch queries

Related PR: cozy/cozy-client#1537
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.

3 participants