Decide on sort order
See original GitHub issue@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 with subleveldown
), 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 by db.put(buf)
- keys may unexpectedly be treated as equal. This issue exists with strings vs buffers, strings vs numbers and more.
Ref: https://github.com/Level/subleveldown/issues/64, https://github.com/Level/level-ttl/issues/68#issuecomment-480505112, https://github.com/Level/community/issues/58#issuecomment-487354041, https://github.com/Level/abstract-leveldown/pull/310 and possibly https://github.com/noffle/kappa-view-level/commit/fdf775de76abdffdcbbd73a2318de08a55bd0ec1.
2. Bring memdown
closer to level-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, while memdown
will sort and store them separately. For example, db.put('a')
will write to a different key than db.put(Buffer.from('a'))
.
3. Bring memdown
closer to leveldown
, 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 to leveldown
, by comparing strings and buffers bytewise
Possibly combined with #185, I don’t know what it would look like. Downside: this will be a third distinct behavior, sitting in between leveldown
and level-js
. Alternatively (and radically) we could drop support of key types other than strings and buffers.
5. Long-term: bring encodings into abstract-leveldown
(https://github.com/Level/community/issues/58)
This could potentially allow implementations to be smarter about how they store and return types.
Issue Analytics
- State:
- Created 4 years ago
- Comments:10 (10 by maintainers)
Top GitHub Comments
I propose the following changes:
memdown
andlevel-js
. If someone wants that type support back, they can fork. Long-term we may bring back some of the functionality in another form, depending on what we do with encodings and the merger ofabstract-leveldown
withlevelup
.memdown
, store strings as buffers. We’ll only need one simple comparator. Prefer compatibility over raw performance. If someone doesn’t like the conversion cost, they can fork (or go lower-level, i.e. usingfunctional-red-black-tree
directly).level-js
, store strings as (array)buffers. Continue to use IndexedDB’s native comparator.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.
Continuing at: