Perf: Improve performance of multithreaded --check and undefined-field diagnostic #2738
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
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
--checkI found this recently added multi-threaded
--checkin #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-fielddiagnosticUpon some profiling, the
undefined-fieldcheck is quite time consuming. By looking into the code I found the early break logic of it can be optimized. The#vm.getDefs(src) > 0is used to check if there is any definition for a givensrcobject, 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.jsonthen run with--checklevel=ErrorNOTE: The following is run in single thread to avoid confusion with the above threaded optimization.