Hi ,
I was going through the documentation of https://github.com/openresty/lua-nginx-module#ngxvarvariable
Here is the use case i just want some understanding on the memory usage and best practice
-- snippet 1 --
local ngx_var = ngx.var
local uri = ngx_var.uri
local args = ngx_var.args
local experssion1 = ngx_var.expression1
local experssion2 = ngx_var.expression2
local experssion3 = ngx_var.expression3
--snippet 2 --
local uri = ngx.var.uri
local args = ngx.var.args
local experssion1 = ngx.var.expression1
local experssion2 = ngx.var.expression2
local experssion3 = ngx.var.expression3
...
the Document Clearly states
WARNING When reading from an Nginx variable, Nginx will allocate memory in the per-request memory pool which is freed only at request termination. So when you need to read from an Nginx variable repeatedly in your Lua code, cache the Nginx variable value to your own Lua variable, for example,
We are currently repeatedly reading from the nginx variable repeatedly as shown in snippet 2 , want to start using snippet 1 , but my team mates think its more of a syntatic sugar than a performance gain , Can you please help me understanding which is better for performance
Thanks,
Ajay