-
Notifications
You must be signed in to change notification settings - Fork 220
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Precompile lua functions to prevent wasted CPU cycles
`miniredis.runLuaScript` calls lua.*LState.DoString() for every lua invocation, even if scripts are evaluated via checksums. In turn, lua parses and compiles the same scripts on each call, which can cause high CPU usage on script-heavy test instances. This PR uses `sync.Map` to store pre-compiled lua functions for each script, using the same logic as the Lua library itself: tul/gopher-lua@7a6135d This reduces CPU usage by about 50%.
- Loading branch information
Showing
1 changed file
with
44 additions
and
3 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