Decrease startup-time by avoiding linear-time iteration over key mappings #851
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.
This commit makes adding, removing and finding key maps an O(1) operation instead of O(n), where n is the number of pre-existing key mappings.
In my testing, averaged over 100 iterations, this reduces the time spent initializing NERDTree at Vim startup from ~73ms to ~9.7ms. That's with only the default included key maps. I've also confirmed that adding more key mappings doesn't meaningfully increase NERDTree startup time with this patch, and that it does without it.
I chose to add an internal
s:KeyMap.all
function to initialize and return the key map dictionary so that the publics:KeyMap.All
function's signature stays the same, returning a sorted list of key maps.Let me know if there're any revisions you'd like to see!