Skip to content

Commit

Permalink
perf(*): ngx.re uses are jitted and cached (#12857)
Browse files Browse the repository at this point in the history
This commit ensures that `ngx.re` uses (in critical (proxy path)
codepaths) are both JITted and JIT-cached.
  • Loading branch information
gszr authored Apr 12, 2024
1 parent cb1b163 commit 1b920ca
Show file tree
Hide file tree
Showing 8 changed files with 10 additions and 9 deletions.
2 changes: 1 addition & 1 deletion kong/llm/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,7 @@ function _M:ai_introspect_body(request, system_prompt, http_opts, response_regex
-- this is useful for AI models that pad with assistant text, even when
-- we ask them NOT to.
if response_regex_match then
local matches, err = re_match(new_request_body, response_regex_match, "ijm")
local matches, err = re_match(new_request_body, response_regex_match, "ijom")
if err then
return nil, "failed regex matching ai response: " .. err
end
Expand Down
4 changes: 2 additions & 2 deletions kong/plugins/acme/client.lua
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ local function new(conf)

-- backward compat
local url = conf.api_uri
if not ngx_re_match(url, "/directory$") then
if not ngx_re_match(url, "/$") then
if not ngx_re_match(url, "/directory$", "jo") then
if not ngx_re_match(url, "/$", "jo") then
url = url .. "/"
end
url = url .. "directory"
Expand Down
2 changes: 1 addition & 1 deletion kong/plugins/grpc-gateway/deco.lua
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ end
local function add_to_table( t, path, v, typ )
local tab = t -- set up pointer to table root
local msg_typ = typ;
for m in re_gmatch( path , "([^.]+)(\\.)?") do
for m in re_gmatch( path , "([^.]+)(\\.)?", "jo" ) do
local key, dot = m[1], m[2]
msg_typ = get_field_type(msg_typ, key)

Expand Down
2 changes: 1 addition & 1 deletion kong/plugins/jwt/handler.lua
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ local function retrieve_tokens(conf)
if type(token_header) == "table" then
token_header = token_header[1]
end
local iterator, iter_err = re_gmatch(token_header, "\\s*[Bb]earer\\s+(.+)")
local iterator, iter_err = re_gmatch(token_header, "\\s*[Bb]earer\\s+(.+)", "jo")
if not iterator then
kong.log.err(iter_err)
break
Expand Down
3 changes: 2 additions & 1 deletion kong/plugins/oauth2/access.lua
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,8 @@ local function retrieve_client_credentials(parameters, conf)
from_authorization_header = true

local iterator, iter_err = ngx_re_gmatch(authorization_header,
"\\s*[Bb]asic\\s*(.+)")
"\\s*[Bb]asic\\s*(.+)",
"jo")
if not iterator then
kong.log.err(iter_err)
return
Expand Down
2 changes: 1 addition & 1 deletion kong/plugins/proxy-cache/handler.lua
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ local function overwritable_header(header)
local n_header = lower(header)

return not hop_by_hop_headers[n_header]
and not ngx_re_match(n_header, "ratelimit-remaining")
and not ngx_re_match(n_header, "ratelimit-remaining", "jo")
end

local function set_header(conf, header, value)
Expand Down
2 changes: 1 addition & 1 deletion kong/runloop/plugin_servers/mp_rpc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ local function index_table(table, field)
end

local res = table
for segment, e in ngx.re.gmatch(field, "\\w+", "o") do
for segment, e in ngx.re.gmatch(field, "\\w+", "jo") do
if res[segment[0]] then
res = res[segment[0]]
else
Expand Down
2 changes: 1 addition & 1 deletion kong/runloop/plugin_servers/pb_rpc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ local function index_table(table, field)
end

local res = table
for segment, e in ngx.re.gmatch(field, "\\w+", "o") do
for segment, e in ngx.re.gmatch(field, "\\w+", "jo") do
if res[segment[0]] then
res = res[segment[0]]
else
Expand Down

1 comment on commit 1b920ca

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bazel Build

Docker image available kong/kong:1b920ca144aed6669b2b1dbe5003683b4fcd18d3
Artifacts available https://github.com/Kong/kong/actions/runs/8665125192

Please sign in to comment.