lua-resty-core
                                
                                
                                
                                    lua-resty-core copied to clipboard
                            
                            
                            
                        feature: Re-implement ngx_lua's ngx.decode_args API function with FFI
One of our projects had used a lot of ngx.decode_args API function.
When i make a performance test for this project  on the Flame Graph. I found the ngx.decode_args  API function occupied most of CPU utilization, which reduce QPS seriously. So i re-implement the ngx.decode_args API function with FFI.
I use this code to test:
--10 args
 local args = {
     a = "a", b = true, c = "c", d = "d",
     e = "e", f = "f", g = "g", h = "h",
     i = "i", j = "j"
 }
 local str = ngx.encode_args(args)
 local now = ngx.time()
 for i = 1, 1e6 do
     local _ = ngx.decode_args(str)
 end
 ngx.update_time()
 ngx.say(ngx.now() - now)
The result is: for lua c api 2.7109999656677 for ffi 1.3810000419617
It seems 100% faster, that's great! @agentzh What do you think about this PR? And also https://github.com/openresty/lua-nginx-module/pull/1108. Thanks!
It seems FFI+JIT is a gold mine. 😃
+1. 😄
@hongliang5316 This is awesome! I'll have a look as soon as I can manage.
BTW, you can often get better performance in a whole OpenResty application by adding the following line to your init_by_lua* handler:
require "jit.opt".start("minstitch=3")