Skip to content
This repository has been archived by the owner on Dec 2, 2024. It is now read-only.

Prefer backpressure over snapshot guarantees #86

Closed
vweevers opened this issue May 24, 2018 · 7 comments
Closed

Prefer backpressure over snapshot guarantees #86

vweevers opened this issue May 24, 2018 · 7 comments
Labels
enhancement New feature or request semver-major Changes that break backward compatibility

Comments

@vweevers
Copy link
Member

Continuing from #68.

TBD if this should go in v3.

@vweevers vweevers added this to the v3 milestone May 24, 2018
@vweevers
Copy link
Member Author

I'm not sure whether to include this in v3 or exactly how to implement it. It can also be added in a minor later, but the thing that bothers me is that the readme states "Store large amounts of data in modern browsers". You can write large amounts of data, sure, but without backpressure, you're gonna run into trouble when reading.

@vweevers
Copy link
Member Author

@ralphtheninja thoughts?

@ralphtheninja
Copy link
Member

I'd skip it for v3 so we can get level-browserify out and later level. Then we can work on the minor as you mentioned.

@vweevers vweevers modified the milestones: v3, v3.1 Jun 17, 2018
@vweevers vweevers added the enhancement New feature or request label Jan 1, 2019
@vweevers
Copy link
Member Author

Relevant: Level/community#63 (comment) and Level/community#63 (comment). IMO offering proper backpressure is a higher priority now.

@vweevers
Copy link
Member Author

I now prefer that we forgo snapshotting guarantees, in favor of backpressure and avoiding a blocking transaction.

@vweevers vweevers changed the title Add option to prefer backpressure over snapshot guarantees Prefer backpressure over snapshot guarantees Mar 30, 2019
@vweevers vweevers added the semver-major Changes that break backward compatibility label Mar 30, 2019
@vweevers
Copy link
Member Author

Plan:

@vweevers vweevers added this to Level Nov 20, 2021
@vweevers vweevers moved this to Todo in Level Nov 20, 2021
vweevers added a commit to Level/browser-level that referenced this issue Mar 5, 2022
Previously (in `level-js`) an iterator would keep reading in the
background so as to keep the IndexedDB transaction alive and thus
not see the data of simultaneous writes. I.e. it was reading from
a snapshot in time.

The downsides of that approach:

- Memory usage on large databases
- IndexedDB doesn't actually use a snapshot (Chrome used to) but
  rather a blocking transaction. Meaning you can't write while an
  iterator is reading.

So instead, an iterator now reads a few entries ahead and then opens
a new transaction on the next read. A "few" means all entries for
`iterator.all()`, `size` amount of entries for `iterator.nextv(size)`
and a hardcoded 100 entries for `iterator.next()`. Individual calls
to those methods still have snapshot guarantees, but repeated calls
do not.

Reading should now be faster too, because it uses the `getAll()` and
`getAllKeys()` methods of IndexedDB, instead of a cursor. This means
multiple entries are transferred from IndexedDB to JS in a single
turn of the JS event loop, rather than one turn per entry. Reverse
iterators do still use a cursor and are therefor slower.

To reflect the new behavior, `db.supports.snapshots` is now false.

Ref Level/level-js#86
@vweevers
Copy link
Member Author

vweevers commented Mar 5, 2022

Done in browser-level.

@vweevers vweevers closed this as completed Mar 5, 2022
Repository owner moved this from Todo to Done in Level Mar 5, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request semver-major Changes that break backward compatibility
Projects
Status: Done
Development

No branches or pull requests

2 participants