Skip to content
This repository has been archived by the owner on Mar 23, 2023. It is now read-only.

Optimize prefix search #25

Merged
merged 3 commits into from
Dec 20, 2019
Merged

Optimize prefix search #25

merged 3 commits into from
Dec 20, 2019

Conversation

carsonfarmer
Copy link
Contributor

This improves prefix search slightly by taking advantage of level's built-in query parameters. In particular, it uses gte and lt keys, and lets the db do the prefix searching rather than using a filter. In my (albeit rough) tests, this can lead to pretty significant speedups in cases with many entries with varying key prefixes. The 'trick' is to set gte to prefix and lt to prefix plus the '\xFF' hex escape sequence. Passes tests and does not change the API (though actually I did sneak in a toString() call to support Key-based prefixes). If this is something worth officially supporting, I could also update the docs.

Signed-off-by: Carson Farmer <carson.farmer@gmail.com>
src/index.js Outdated Show resolved Hide resolved
Signed-off-by: Carson Farmer <carson.farmer@gmail.com>
Signed-off-by: Carson Farmer <carson.farmer@gmail.com>
Copy link
Member

@rvagg rvagg left a comment

Choose a reason for hiding this comment

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

is good 👍

@achingbrain
Copy link
Member

Nice spot, thanks!

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.

4 participants