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

acl: Avoid allocations when checking implied ops #12114

Merged

Conversation

StephanDollberg
Copy link
Member

@StephanDollberg StephanDollberg commented Jul 14, 2023

acl_implied_ops was quite visible (~3%) in the callchains leading to operator new() in the LRC profile.

It's called for every partition so this is not entirely surprising when using larger partition counts.

Avoid the allocations by "inlining" the check into the function so that no vector has to be allocated.

(cherry picked from commit 74ea237)

Fixes #12097

Backports Required

  • none - not a bug fix
  • none - this is a backport
  • none - issue does not exist in previous branches
  • none - papercut/not impactful enough to backport
  • v23.1.x
  • v22.3.x
  • v22.2.x

Release Notes

  • none

`acl_implied_ops` was quite visible (~3%) in the callchains leading to
`operator new()` in the LRC profile.

It's called for every partition so this is not entirely surprising when
using larger partition counts.

Avoid the allocations by "inlining" the check into the function so that
no vector has to be allocated.

(cherry picked from commit 74ea237)
@emaxerrno
Copy link
Contributor

lgtm. well done.

/*
* Compute the implied operations based on the specified operation.
*/
inline std::vector<acl_operation> acl_implied_ops(acl_operation operation) {
Copy link
Contributor

Choose a reason for hiding this comment

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

i suppose you could return const-ref iterator pointers to static constexpr arrays as a std::pair<> but this is a good design. lgtm.

Copy link
Contributor

@emaxerrno emaxerrno left a comment

Choose a reason for hiding this comment

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

lgtm.

i suppose a fewer LOC change is to return a std::pair of pointers to begin, end of static constexpr arrays. though i bet your version just inlines the whole thing into a jump table anyway, so is even more efficient. kinda sad the compiler didn't see through this relatively simple case structure by default.

@StephanDollberg
Copy link
Member Author

i suppose a fewer LOC change is to return a std::pair of pointers to begin, end of static constexpr arrays. though i bet your version just inlines the whole thing into a jump table anyway, so is even more efficient. kinda sad the compiler didn't see through this relatively simple case structure by default.

I wanted to do that first but the problem is the default cause where we return a one-sized array of the input op so that makes it difficult.

@StephanDollberg StephanDollberg merged commit 4bb8ca3 into redpanda-data:v22.3.x Jul 17, 2023
@BenPope BenPope added this to the v22.3.23 milestone Aug 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants