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
Batch-optimization #3313
Open
ScottyPoi
wants to merge
21
commits into
master
Choose a base branch
from
batch-optimization
base: master
Could not load branches
Branch not found: {{ refName }}
Could not load tags
Nothing to show
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Batch-optimization #3313
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
4d05198
trie: create file for batch functions
ScottyPoi 30c4c5f
trie: helper function to sort batch keys
ScottyPoi 8668578
trie: create modified _put method for batch use
ScottyPoi 3db7de7
trie: create modified _del method for batch
ScottyPoi f7e0ceb
trie: create intermediate method batchPut
ScottyPoi 674f7e6
trie: implement optimized batch method
ScottyPoi 6c43d64
trie: return updated node stack from _update
ScottyPoi 252ee7b
trie: replace trie.batch with imported batch method
ScottyPoi e4123db
trie: test new batch functions
ScottyPoi 6fd4602
trie: use hashed keys in batch sort (secure trie)
ScottyPoi b2c2624
trie: test batch on secure / pruned trie
ScottyPoi 71535aa
trie: use _del instead of del in batch
ScottyPoi 1a98e2c
trie: test additional trie opts
ScottyPoi f08bd10
remove .only from test
ScottyPoi 2135b9a
trie: modify original trie.put for batch
ScottyPoi 945ace5
trie: modify original trie.del for batch
ScottyPoi 87d0465
trie: modify _batch to use direct trie methods
ScottyPoi f51ff04
trie: remove custom functions from batch.ts
ScottyPoi 4fd15a2
trie: move _batch back to trie.batch
ScottyPoi c3dadd4
trie: move orderBatch function to util file / delete batch.ts
ScottyPoi e075991
trie: condense batch test file
ScottyPoi File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to make both the ordering as well as the caching optional for the
batch()
method, and therefore provide extra configuration parameters to configure.Ordering: Reason for ordering is that the ordering in certain cases does have an effect on the outcome. So if there is first a put for a key and then a delete for the same key this is obviously different then having this the other way around. Same for two puts for the same key but different values. So the whole ordering needs to be deactivated by default (also for backwards compatibility) and the user would need to activate manually.
Caching: Reason that caching would need to also get an option and also would needed to be deactivated by default is that one does not know how big a batch() operation will be (only the user knows (at best)). So this might "overload" the cache respectively there is the risk for out-of-memory situations.
I would suggest that we add a dedicated options dictionary with its own type in
types.ts
calledBatchOpts
for this, seems worth it, and then we add boolean flagssortOperations
(or so) andactivatePathCache
(or so) for this.My tendency actually would be to also include
skipKeyTransform
and then be a bit hacky and change the function signature toasync batch(ops: BatchDBOp[], skipKeyTransformOrOptsDict?: boolean | BatchOpts)
so that we can then do a switch respectively type check for the parameter and either assignskipKeyTransform
directly or use the options dict.Then we can use the method directly with
trie.batch(ops, opts)
(ortrie.batch(ops, { sortOperations: true })
) and do not always need to channel in theskipKeyTransform
default.(let me know if this has serious downsides though I am overlooking. I would think this should still be backwards compatible for people)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did some further research into the effects of this in the context of other modules, and I agree about tweaking the options for how batch works based on the situation.
There are definitely circumstances in which it would be faster to simply iterate through the batch like we currently do, instead of sorting and caching. I also wonder how the results would change if we used different sorting and trie walking algorithms. If there's something useful there, it could be another option in
batch()