-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Decrease startup-time by avoiding linear-time iteration over key mappings #851
Decrease startup-time by avoiding linear-time iteration over key mappings #851
Conversation
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 maps. 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 think this fixes the majority of the startup time issue #276 |
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'm OK with this. Nice improvement.
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.
This is really great. Well done!
I should have noticed this myself when I was poking around in here a few days ago.
Could you change all()
to _all()
? Private methods should begin with an underscore. It's a NERDTree style convention. Thanks!
Thanks! Just pushed 657be6b to update the private function to add the leading underscore |
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.
Looks great! Thanks!
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!