Skip to content

Commit

Permalink
perf(router): iterate routes with for loop (#11111)
Browse files Browse the repository at this point in the history
for loop has better performance than function ipairs(), especially for huge table.
  • Loading branch information
chronolaw authored Jun 27, 2023
1 parent 71fca6f commit e8173ca
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
8 changes: 6 additions & 2 deletions kong/router/atc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,9 @@ local function new_from_scratch(routes, get_exp_and_priority)

local new_updated_at = 0

for _, r in ipairs(routes) do
for i = 1, routes_n do
local r = routes[i]

local route = r.route
local route_id = route.id

Expand Down Expand Up @@ -240,7 +242,9 @@ local function new_from_previous(routes, get_exp_and_priority, old_router)
local new_updated_at = 0

-- create or update routes
for _, r in ipairs(routes) do
for i = 1, #routes do
local r = routes[i]

local route = r.route
local route_id = route.id

Expand Down
4 changes: 2 additions & 2 deletions kong/router/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -292,8 +292,8 @@ do
local v0 = 0
local v1 = 0

for _, route in ipairs(routes) do
local r = route.route
for i = 1, #routes do
local r = routes[i].route

local paths_t = r.paths or empty_table
local headers_t = r.headers or empty_table
Expand Down

1 comment on commit e8173ca

@khcp-gha-bot
Copy link

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:e8173ca30b902202e289e93ab34cf40a907fd3d6
Artifacts available https://github.com/Kong/kong/actions/runs/5387569118

Please sign in to comment.