-
-
Notifications
You must be signed in to change notification settings - Fork 37
Decide on sort order #186
Comments
Is this just from Level/subleveldown#64 or has this been coming up a lot? I like the straightforwardness of option 3, even if there is a bit of a cost. It's not a terribly huge cost but maybe benchmarks would help quantify if we have benchmarks we can throw at before & after. As for "reduced type support." how much of a problem is this going to be? leveldown only supports strings and Buffers and abstract-leveldown only really says strings and Buffers are important for implementations. Have you seen downstream use cases where people aren't using strings or Buffers (or Buffer-like arrays)? |
Also
True, it's not a problem if you use
What "important" means here is that only these types are supported across the board and tested in the abstract test suite. An implementation that supports other types is itself responsible for testing them.
Admittedly, apart from my own use, no. We've been trying to take |
Another option: have both I'm starting to like this option, because First, lemme get back to the |
This sounds almost like option 3? I'd go for any option that solves real issues and I prefer solutions that simplify and remove confusion. It seems to me this cost is paid by conversion costs and that's fine if that cost isn't too high. |
Yeah, it's 3, but also applied to |
@peakji Any thoughts? Even if you only use leveldown (any perspective is welcome). |
I propose the following changes:
The custom type support was a worthwhile experiment IMO that incidentally helped to clean up code overall. In absence of actual usage, we can end this experiment. This GH thread has been open long enough for people to raise objections. |
sgtm, you could even consider aiming for switching memdown (maybe even abstract-leveldown) to ArrayBuffers too, migrate as much as possible to |
Later. The primary goal is to increase compatibility with the level ecosystem (which mostly deals with Buffers) so I want to stick with Buffers for now. The proposed changes will fix issues with |
@Level/core The way that
memdown
compares keys is starting to show its limitations. To fix that (or not) we have a few options. The goal is to increase ecosystem compatibility (like integrating withsubleveldown
), which doesn't necessarily mean "behave exactly like leveldown".1. Keep
memdown
as-is.Drawback: you can only safely use one key type in your db. When mixing types - e.g.
db.put(str)
followed bydb.put(buf)
- keys may unexpectedly be treated as equal. This issue exists with strings vs buffers, strings vs numbers and more.Ref: Level/subleveldown#64, Level/level-ttl#68 (comment), Level/community#58 (comment), Level/abstract-leveldown#310 and possibly kappa-db/kappa-view-level@fdf775d.
2. Bring
memdown
closer tolevel-js
, by sorting keys by type first, then content (#185)Mixing types in your db is OK. The behavior does however differ from
leveldown
, where buffers and strings are both stored as byte arrays, whilememdown
will sort and store them separately. For example,db.put('a')
will write to a different key thandb.put(Buffer.from('a'))
.3. Bring
memdown
closer toleveldown
, by storing everything as a Buffer.Drawbacks: conversion cost (especially when you're solely working with strings, which is common), reduced type support.
4. Bring
memdown
closer toleveldown
, by comparing strings and buffers bytewisePossibly combined with #185, I don't know what it would look like. Downside: this will be a third distinct behavior, sitting in between
leveldown
andlevel-js
. Alternatively (and radically) we could drop support of key types other than strings and buffers.5. Long-term: bring encodings into
abstract-leveldown
(Level/community#58)This could potentially allow implementations to be smarter about how they store and return types.
The text was updated successfully, but these errors were encountered: