MINOR: Move candidateClients set creation outside of task loop for StickyTaskAssignor (#19511)

This PR moves the computation of the "client list", which is the same
for all tasks,  out of the loop, to avoid unnecessary re-computation.

Reviewers: Matthias J. Sax <matthias@confluent.io>
This commit is contained in:
lorcan 2025-04-30 18:22:04 +01:00 committed by GitHub
parent 53afb1e0c5
commit 009fc7cdbf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 2 additions and 2 deletions

View File

@ -178,10 +178,10 @@ public class StickyTaskAssignor implements TaskAssignor {
// assign any remaining unassigned tasks
final List<TaskId> sortedTasks = new ArrayList<>(unassigned);
Collections.sort(sortedTasks);
for (final TaskId taskId : sortedTasks) {
final Set<ProcessId> candidateClients = clients.stream()
final Set<ProcessId> candidateClients = clients.stream()
.map(KafkaStreamsState::processId)
.collect(Collectors.toSet());
for (final TaskId taskId : sortedTasks) {
final ProcessId bestClient = assignmentState.findBestClientForTask(taskId, candidateClients);
assignmentState.finalizeAssignment(taskId, bestClient, AssignedTask.Type.ACTIVE);
}