-
-
Notifications
You must be signed in to change notification settings - Fork 44
'json' encoding stringifies data before being inserted into db #33
Comments
Do you have some numeric data that shows how much we are losing in term of speed for this unneeded conversion? Some form of serialization happen anyway, and the native one should be faster, but it might not be worth the change here and the added complexity. @dominictarr your work on encodings can help here? |
It's been a while since I opened this issue, so I don't remember all of the context, but if I recall correctly, I was think that if it used IndexedDB's native JSON support, there might be possibilities to take advantage of IndexedDB's indexing as well. |
Here is the problem: by using IndexedDB native indexing on top of LevelUp, you are kind-of violating all possible encapsulation and abstraction layers we placed upon it. If you need some IndexedDB special feature, just use IndexedDB. LevelUp exposes an ordered view of your data, where keys cannot be objects (well, only with typewise), and you code your own indexes. I think we should keep this simple as we are all spread very thin in maintaining all those modules. Any other opinion on this? |
I think this will probably work: function id (e) { return e }
var nothing = {encode: id, decode: id, buffer: false}
levelup({db: levelJs, valueEncoding: nothing}) this should pass values into leveldown without serializing them. |
I think it's okay, although a little bit dirty, to have a module that implements indexeddb like indexing that also detects if it is running on indexeddb and in that case uses native indexes. |
@mcollina good point. I also have a performance concern about this, but it will be good to see if it actually hurts something. It's possible that it doesn't @ianwremmel do you have anything on this? |
Hi @Ivshti, we ended up going a different direction. Our primary motivation for using indexeddb was performance rather than offline access. Instead of focusing on building a database engine (because a year ago, that's really what you had to do to practically use indexeddb, even with helper libraries), we instead worked on improving API response times and adjusting UI feedback to improve the initial-load experience. |
if you want level.js to get the raw values, +1 on this pull request: Level/abstract-leveldown#85 |
abstract-leveldown@2.5.0 is out! so if you want to bypass encoding completely, simply do this: db._serializeKey =
db._serializeValue = function (data) { return data } |
by the way, since we added custom codecs you could do |
The problem was that abstract-leveldown would still (!) convert everything to a string of buffer. That can be bypassed now. So yeah you need to set those options on levelup and leveldown for now. |
oh I see. well, we have |
So when using Since |
Since JSON is the native encoding to IndexedDB, it shouldn't be necessary to stringify data before storing it. Is it AbstractLevelDOWN that does the conversion? Does it make sense to replace 'json' encoding with
raw:true
when the database is opened?I'm using the following to make sure I can cleanly work with JSON in both node and browser environments, but it feels like a hack:
package.json:
index.js:
The text was updated successfully, but these errors were encountered: