Closed tomlau10 closed 3 months ago
Very nice tomlau10! Can we get some insight into how you profiled the LuaLS? I am primarily interested in how you found which functions to optimize.
Great work!
Can we get some insight into how you profiled the LuaLS?
@C3pa Nothing advanced, I just profile each diagnostics one by one π by setting up the .luarc.json
in my workspace like this:
"diagnostics.severity": {
"undefined-field": "Error!"
}
And then I run LuaLS with --check --checklevel=Error
, which will only check against those with severity Error
or above.
(In this example setup is the undefined-field
)
During my profiling, I also found that the invisible
diagnostic is quite time consuming as well (on par with undefined-field
check). But currently I have no idea what can be optimized. π
edit:
I am primarily interested in how you found which functions to optimize.
Oh~ I guess you are asking how I found that #vm.getDefs(src) > 0
can be optimized? Nothing special, just by some programmer instincts π
Interesting. Thanks for your insight! I thought you might have used some kind of profiler setup.
Recently I am integrating LuaLs into our project's CI and I am looking for ways to speed up the process. The following are 2 simple optimizations that I have found:
Work distribution in multi-threaded
--check
I found this recently added multi-threaded
--check
in #2638. Upon some code reviewing I suspect that the hash function used to distribute work across multi threads is not that perfect, which limits its full potential. I simply changed it to Round Robin (after sorting the file list of course), and this yields another10%
performance gain in my project workspace (500+ lua files). Benchmarks as follow:I would like to mention @emmericp here as this function is originally implemented by him, to see if this small optimization can help shaving off a few more seconds in his project π (great work btw π )
Early break in
undefined-field
diagnosticUpon some profiling, the
undefined-field
check is quite time consuming. By looking into the code I found the early break logic of it can be optimized. The#vm.getDefs(src) > 0
is used to check if there is any definition for a givensrc
object, and there is no need to fetch the full definitions list. We can actually return as soon as the 1st definition is found. This yields a25%
performance gain in this single check within my workspace π"diagnostics.severity": { "undefined-field": "Error!" }
in.luarc.json
then run with--checklevel=Error
NOTE: The following is run in single thread to avoid confusion with the above threaded optimization.