[ https://issues.apache.org/jira/browse/KAFKA-7344?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Ted Yu updated KAFKA-7344: -------------------------- Description: After re-assigning existing active tasks to clients that previously had the same active task, there is chance that {{taskIds.size() == assigned.size()}}, i.e. all tasks are assigned . The method continues with: {code} final Set<TaskId> unassigned = new HashSet<>(taskIds); unassigned.removeAll(assigned); {code} We can check the above condition and return early before allocating HashSet. Similar optimization can be done before the following (around line 112): {code} // assign any remaining unassigned tasks final List<TaskId> sortedTasks = new ArrayList<>(unassigned); {code} was: After re-assigning existing active tasks to clients that previously had the same active task, there is chance that {{taskIds.size() == assigned.size()}}, i.e. all tasks are assigned . The method continues with: {code} final Set<TaskId> unassigned = new HashSet<>(taskIds); unassigned.removeAll(assigned); {code} We can check the above condition and return early before allocating HashSet. Similar optimization can be done before the following (around line 112): {code} // assign any remaining unassigned tasks final List<TaskId> sortedTasks = new ArrayList<>(unassigned); {code} > Return early when all tasks are assigned in StickyTaskAssignor#assignActive > --------------------------------------------------------------------------- > > Key: KAFKA-7344 > URL: https://issues.apache.org/jira/browse/KAFKA-7344 > Project: Kafka > Issue Type: Improvement > Components: streams > Reporter: Ted Yu > Assignee: kevin.chen > Priority: Minor > Labels: optimization > > After re-assigning existing active tasks to clients that previously had the > same active task, there is chance that {{taskIds.size() == assigned.size()}}, > i.e. all tasks are assigned . > The method continues with: > {code} > final Set<TaskId> unassigned = new HashSet<>(taskIds); > unassigned.removeAll(assigned); > {code} > We can check the above condition and return early before allocating HashSet. > Similar optimization can be done before the following (around line 112): > {code} > // assign any remaining unassigned tasks > final List<TaskId> sortedTasks = new ArrayList<>(unassigned); > {code} -- This message was sent by Atlassian JIRA (v7.6.3#76005)