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

KAFKA-16669: Remove extra collection copy when generating DescribeAclsResource #15924

Open
wants to merge 2 commits into
base: trunk
Choose a base branch
from

Conversation

chiacyu
Copy link
Contributor

@chiacyu chiacyu commented May 11, 2024

This pr reduced the occurrence of collection copy when generating DescribeAclsResource.

@chia7712
Copy link
Contributor

auth.acls(filter).forEach(returnedAcls.add)

@chiacyu we don't need to collect all items to a new collection, right?

ResourcePattern key = entry.getKey();
List<AclDescription> aclDescriptions = new ArrayList<>();
List<AclDescription> aclDescriptions = new ArrayList<>(128);
Copy link
Contributor

Choose a reason for hiding this comment

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

why not using entry.getValue().size()?

@@ -69,7 +69,7 @@ class AclApis(authHelper: AuthHelper,
case Some(auth) =>
val filter = describeAclsRequest.filter
val returnedAcls = new util.HashSet[AclBinding]()
auth.acls(filter).forEach(returnedAcls.add)
returnedAcls.add(auth.acls(filter).iterator().next())
Copy link
Contributor

Choose a reason for hiding this comment

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

Originally we will add all auth.acls(filter) content into returnedAcls, but after this change, we only add the first element. Why do we need this change?

Copy link
Contributor

Choose a reason for hiding this comment

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

OK, I know why you did this change now.

we don't need to collect all items to a new collection, right?

I believe what @chia7712 meant is we don't have to do a collection copy here because we already allow passing Iterable into aclsResource method. To make it clear, in the JIRA, we said:

  1. Iterable -> HashSet

This is the collection copy we want to avoid here. So we don't need returnedAcls anymore, we can pass the result of auth.acls(filter) into aclsResource directly. Is that clear?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants