This repository was archived by the owner on Jul 23, 2019. It is now read-only.
Optimize add_selection_above and add_selection_below#79
Merged
Conversation
added 5 commits
May 4, 2018 15:01
Instead of using `Vec::remove` when merging adjacent selections, we now construct a new Vec with the merged selections. In the worst case, this corresponds to a single movement of memory from a vector to another and a single malloc. Using `Vec::remove` repeatedly, on the other hand, was causing the vector to be constantly shifted around, which starts becoming slow when the number of selections increases dramatically. In my tests, this change does not introduce slowdowns when dealing with a small number of selections.
This change was driven by the hashing functions showing up in theprofiler. Since we don't need a cryptographic hash function in that codepath, this commit switches to SeaHash which seems to be much faster thanSipHash (Rust default hasher).
This method is very similar to Buffer::mutate_selections in that it allows to manipulate selection sets by supplying an id. The only difference with the latter is that it gives users of this API a readonly slice of the existing selections and allows to return a (not necessarily ordered) vector of new selections to insert.
|
Nice work on this ⚡️ |
This file contains hidden or 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
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Previously, dispatching the "Add Selection Above/Below" command was unusable even when the number of existing selections was relatively low (e.g. < 1000 selections). This pull request introduces a few commits that improve the situation and allow to use this command even with thousands of selections (in my tests, we don't drop any frame even with > 2000 selections):
Buffer::insert_selectionsto efficiently insert a (not necessarily sorted) list of selections (b75e52c)Other than some local tests, I have also introduced a benchmark that proves the above changes have a positive effect on the
Buffer::add_selection_aboveandBuffer::add_selection_belowmethods:Note that, for speed purposes, I have kept the number of selections in the benchmark relatively low. Even in that scenario the proposed changes make a significant difference, but the improvements increase even more when the number of selections gets higher (i.e. thousands as opposed to hundreds of selections). This is largely due to
memmovecalls being still quite efficient whenVecis small./cc: @nathansobo