Skip to content

Optimize lookups of constants and fields in Lua

Hanicef requested to merge Hanicef/SRB2:optimize-lua-value-lookup into next

After doing some profiling using OProfiler, I found that lookups for constants and fields in Lua scripts performed really badly. This is caused by the lookups being only basic loops that checks each value, something that performs horribly for large tables. However, I noticed that all of these tables are static, which makes binary search a good candidate for optimizing this issue, and after doing some tests, the difference is huge! When playing on script-heavy servers, most lag is gone and there's only some minor lag which I can only guess is caused by suboptimal scripts (still need to investigate that, though).

In case you want more information on how binary search works, feel free to read this: https://hanicef.me/document/binary-search

Merge request reports

Loading