Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf(util): simplify and optimize parsers (#435)
* refactor(util): turn parse_keys into state machine The parser now requires only 3 states with much simpler conditional structure of only 2 layers: one for the state and another for the character read. Several performance improvements are made as part of this: - Avoid calling t(), which involves string allocation, both in C and in Lua due to gsub(). - Reduced string allocations: avoid string building which is extremely slow in Lua. - Make heavy use of composite conditionals: LuaJIT likes them a lot and testing shows markable improvement in speed with their usage. - Reduced number of table lookups in loops, which includes options lookup (very slow) and object function lookup. All of this net into a startup time improvement of ~10.6%, from 11.3ms[+-0.156] down to 10.1ms[+-0.13] as recorded by lazy.nvim, sampled 10 times. * refactor(util): simplify parse_internal Rewrites parse_internal as a state machine. This reduces the number of variables required to manage the parser, making it simpler to understand. The code is optimized with LuaJIT in mind, in particular: - Make use of composite conditionals on hot path to leverage IR optimizations. - Avoid string building which has quadratic complexity in Lua. Startup time goes from 10.1ms[+-0.13] down to 9.81ms[+-0.165] (~2.8% improvement) with this commit as recorded by lazy.nvim with samples of 10.
- Loading branch information
Showing
1 changed file
with
71 additions
and
74 deletions.
There are no files selected for viewing
This file contains 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