Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf(acl) rewrite for performance, jit and caching #2736

Merged
merged 1 commit into from
Aug 31, 2017

Conversation

Tieske
Copy link
Member

@Tieske Tieske commented Jul 26, 2017

Rewritten logic.

I put some serious lightning into its flux capacitor, it will now take you back to the future any time.

(not to mention we dropped the awesome utils.table_contains usage from this one)

@Tieske Tieske self-assigned this Jul 26, 2017
@Tieske Tieske changed the base branch from feat/acl-plugin-consumer to master July 26, 2017 21:02
@Tieske Tieske force-pushed the perf/acl-plugin branch from e955ec8 to 06e1ff8 Compare July 26, 2017 21:56
local block = (reverse.type == WHITE)
for i = 1, #acls do
if reverse.groups[acls[i].group] then
block = (reverse.type == BLACK)
Copy link
Member

Choose a reason for hiding this comment

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

Side note: while quite neat, this logic also requires a certain cognitive load on the reader... There could be a simpler (just as efficient way probably) of deciding whether to block or not (and since this is cached anyways, we barely care about a slightly less performance solution).

Not a blocker though imo!

Copy link
Member Author

Choose a reason for hiding this comment

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

updated this one, I had the same thought before, just picked one


else
-- allowed, create the header
local str_acls = {}
Copy link
Member

Choose a reason for hiding this comment

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

perf: we can pre-allocate the slots in this table with new_tab(#acls, 0)

And instead of the double O(n) #acls, do:

local n = #acls
local str_acls = new_tab(n, 0)

for i = 1, n do
  -- ..
end

Copy link
Member Author

Choose a reason for hiding this comment

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

updated, though imo the local n = #acls is a bit over the top, considering the same cognitive load argument. But hey, this was a performance rewrite 😄

Copy link
Member

Choose a reason for hiding this comment

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

We do this quite commonly across (newer parts of) the code base (or any LuaJIT written for OpenResty components)

end

if block then
if cached_result == true then -- NOTE: we only catch the boolean here!
Copy link
Member

@thibaultcha thibaultcha Jul 27, 2017

Choose a reason for hiding this comment

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

Could we rename cached_result to cached_block to preserve the semantics around that value through the code?

@Tieske Tieske force-pushed the perf/acl-plugin branch from 06e1ff8 to 3d3af17 Compare July 28, 2017 05:51
thibaultcha
thibaultcha previously approved these changes Jul 28, 2017
Copy link
Member

@thibaultcha thibaultcha left a comment

Choose a reason for hiding this comment

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

LGTM! (minor style thing)

Let's keep this on hold until 0.11/0.10.4, shall we?

block = true
break
end
end
else
Copy link
Member

Choose a reason for hiding this comment

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

style: missing an empty line above this else

Copy link
Member Author

Choose a reason for hiding this comment

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

👀

@thibaultcha thibaultcha added pr/ready (but hold merge) No more concerns, but do not merge yet (probably a conflict of interest with another PR or release) and removed pr/status/please review labels Jul 28, 2017
@Tieske Tieske force-pushed the perf/acl-plugin branch 2 times, most recently from 39df3c1 to 808f0e0 Compare July 28, 2017 08:58
@thibaultcha thibaultcha merged commit 159d290 into master Aug 31, 2017
@Tieske Tieske deleted the perf/acl-plugin branch September 9, 2017 09:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr/ready (but hold merge) No more concerns, but do not merge yet (probably a conflict of interest with another PR or release)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants