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

raw mode? #17

Open
ronag opened this issue Apr 2, 2022 · 6 comments
Open

raw mode? #17

ronag opened this issue Apr 2, 2022 · 6 comments
Labels
enhancement New feature or request

Comments

@ronag
Copy link
Contributor

ronag commented Apr 2, 2022

In order to get key + value we use entries which are an array of [key,val]. However, allocating an array for each key value pair is slow. Would be nice if we could somehow return a flattened array with key = xs[idx * 2 + 0], val = xs[idx * 2 + 1] and avoid O(n) array allocations.

@vweevers
Copy link
Member

vweevers commented Apr 2, 2022

That makes nextv() slower because that must then "unflatten" the array in JS land. The current approach makes nextv() fast and next() only slightly slower (compared to a flattened array which we used previously in leveldown).

@ronag
Copy link
Contributor Author

ronag commented Apr 2, 2022

That makes nextv() slower because that must then "unflatten" the array in JS land.

I was thinking that the flat array could go all the way to the user in js land, i.e. no need to unflatten. This would of course need a new api. Would help a bit in our use cases.

@vweevers
Copy link
Member

vweevers commented Apr 2, 2022

Related: are you working with binary data? If so, I've been thinking about an entirely different approach, where we allocate one buffer and slice it up in JS. But that would not improve perf if you're working with string data (which includes the json encoding).

@ronag
Copy link
Contributor Author

ronag commented Apr 3, 2022

I'm currently working with json encoding. It's on my roadmap to eventually move to string and then Buffer but that adds significantly complexity so currently I'm trying to find simpler avenues of optimisation.

ronag added a commit to ronag/classic-level that referenced this issue Apr 3, 2022
Adds option for a faster "flat" return format.

Refs: Level#17
@ronag
Copy link
Contributor Author

ronag commented Apr 3, 2022

Ok, now I have 'string' encoding but the optimization is still just as relevant.

@ronag
Copy link
Contributor Author

ronag commented Apr 3, 2022

Another alternative would be to get keys and values in separate arrays? i.e. iterator.all((err, keys, values) => {})

@vweevers vweevers added this to Level May 9, 2022
@vweevers vweevers moved this to Backlog in Level May 9, 2022
@vweevers vweevers added the enhancement New feature or request label May 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: Backlog
Development

No branches or pull requests

2 participants