Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf: optimize the walk() function #587
I noticed that it takes pynvim about 4ms to attach to an nvim instance for me, and 3ms of that is due to the single line: metadata = walk(decode_if_bytes, metadata) This commit reduces the walk() time down to 1.5ms, which brings the total attach time down to 2.5ms. This is helpful for me because in my use case I end up connecting to all of the currently-running nvim processes and this starts to take a noticeable amount of time. Unfortunately parallelization does not help here due to the nature of the slowness. walk() is expensive because it does a very large amount of pure-python manipulation, so this commit is just some tweaks to reduce the overheads: - *args and **kw make the function call slow, and we can avoid needing them by pre-packing the args into fn via functools.partial - The comprehensions can be written to directly construct the objects rather than create a generator which is passed to a constructor - The typechecking is microoptimized by calling type() once and unrolling the `type_ in [list, tuple]` check I did notice that in my setup the metadata contains no byte objects, so the entire call is a noop. I'm not sure if that is something that could be relied on or detected, which could be an even bigger speedup.
- Loading branch information