yst726 / redis

Automatically exported from code.google.com/p/redis
0 stars 0 forks source link

[Enhancement] Improve scripting performance with local variables #596

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
Currently, the KEYS and ARGV arguments are passed to Lua scripts by setting 
them in the global environment. It is possible to improve performance thereof 
by using local variables instead.

To do so, the following changes would need to be made:

1. Change the function signature used for luaL_loadbuffer from "function ()" to 
"function (KEYS, ARGV)". This would cause the function to accept KEYS and ARGV 
as its arguments, allowing them to be stored in local variables.

2. Rename luaSetGlobalArray to luaCreateArray, delete the var argument, and 
remove the lua_setglobal call on the end. This would leave the array on the 
stack once it was created.

3. Change the number of arguments in lua_pcall from 0 to 2. This would pass the 
KEYS and ARGV arrays to the function, causing them to fill the KEYS and ARGV 
local variables inside the function body.

This would allow the creation of the arrays to be done entirely on the stack, 
instead of requiring two expensive table set operations. Similarly, access from 
within the functions would be faster, as the arguments would be stored in 
registers instead of the globals table. Finally, it would prevent the 
"pollution" of the globals table which currently occurs.

Original issue reported on code.google.com by LeafStor...@gmail.com on 25 Jun 2011 at 1:11