Improve startup time by storing plugin function in module variable instead of using tagging and inspect
I've created benchmark that compares your current approach with the one I'm suggesting.
You can run this with pytest and with pytest-benchmark installed. But here's the result on my machine
----------------------------------------------------------------------------------------- benchmark: 2 tests ----------------------------------------------------------------------------------------
Name (time in ns) Min Max Mean StdDev Median IQR Outliers(*) Rounds Iterations
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
test_strategies[store] 277.6878 (1.0) 12,090.6252 (1.0) 306.9411 (1.0) 77.6767 (1.0) 285.0002 (1.0) 5.2505 (1.0) 13192;46481 199721 16
test_strategies[tag] 139,222.0001 (501.36) 436,723.9890 (36.12) 147,089.0559 (479.21) 23,119.3189 (297.64) 140,545.0021 (493.14) 772.4993 (147.13) 77;2841399 1
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
(*) Outliers: 1 Standard Deviation from Mean; 1.5 IQR (InterQuartile Range) from 1st Quartile and 3rd Quartile.
============================================================================= 2 passed in 3.77 seconds ==============================================================================
As you can see your current approach is almost 500 times slower.
I can see only one reason for not changing that - which is some user could have defined this _store variable, but
1. This can be mitigated by using some more or less unique name.
2. You already have this problem in class decorators. Because if user for some evil reason had class attribute _nvim_plugin you would overwrite it.
So you already have the same problem with exactly the same solution (using unique name).
Notice that for 100 functions the time that is needed to find tagged function is more than 100 ms. That's 100 ms of startup time of neovim. For me neovim startup time is about 300-400 ms. That means that for users, that use a lot of python plugins (or plugins that exports a lot of functions) this can be significant portion of startup time. And that's one of the things that I like about vim/neovim. That is so fast to start. Another 100 ms would make it even better.
Very nice. I don't think anyone's attached to the current approach. Are you willing to send a PR? cc @bfredl @tarruda
@justinmk Okay, It seems that working late isn't good for me, because I've mistakenly thought that 139,222.0001 ns is 139 ms, but in fact it is 139 us, which isn't that bad. But I'm still enthusiastic about relative performance improvement. I will try to create pull request later.
@purpleP Ok, first thing to do would be to verify that startup time of nvim improves after making the change. Else the change won't be worth it.
Well, I'll do that just for fun (if I would have time) and you can decide wether you want to merge it or not.