Skip to content

Optimize issue lookup in UpgradeDependencies task#50966

Closed
lucasrmendonca7 wants to merge 2 commits into
spring-projects:mainfrom
lucasrmendonca7:perf/update-dependencies-data-structure
Closed

Optimize issue lookup in UpgradeDependencies task#50966
lucasrmendonca7 wants to merge 2 commits into
spring-projects:mainfrom
lucasrmendonca7:perf/update-dependencies-data-structure

Conversation

@lucasrmendonca7

Copy link
Copy Markdown

Replace linear search with HashMap lookup in UpgradeDependencies.findExistingUpgradeIssue

This PR refactors the issue lookup logic in UpgradeDependencies to use a HashMap instead of a linear search, reducing the algorithmic complexity from O(N * M) to O(N + M).

Problem

The method findExistingUpgradeIssue iterates through the entire list of existing issues for each upgrade, resulting in O(N * M) complexity where N is the number of upgrades and M is the number of existing issues. While functionally correct, this pattern doesn't scale well and doesn't clearly express the intent of finding an issue by its title.

Solution

  • Pre-index existing upgrade issues into a HashMap<String, Issue> keyed by normalized title, at a cost of O(M).
  • Replace the loop in findExistingUpgradeIssue with a direct Map.get() call, reducing the per-upgrade lookup from O(M) to O(1).
  • Change method signature to accept Map<String, Issue> instead of List<Issue>.
  • Overall complexity reduced from O(N * M) to O(N + M).

Why this is better

  • Complexity: O(N * M) → O(N + M)
  • Intent: A map clearly signals "I want to find an issue by its title"
  • Readability: One line instead of a loop with string manipulation
  • Consistency: Follows the principle of using the right data structure for the job

Testing

All existing tests in buildSrc pass successfully.

Replace the nested loop linear search (O(N*M)) with a HashMap-based lookup (O(N+M)). This significantly reduces the execution time for the dependency upgrade process by caching library information and performing direct lookups.

Signed-off-by: lucasrmendonca7 <lucas80002@gmail.com>
Signed-off-by: lucasrmendonca7 <lucas80002@gmail.com>
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jul 16, 2026
@lucasrmendonca7
lucasrmendonca7 force-pushed the perf/update-dependencies-data-structure branch from 8415773 to dea5cb9 Compare July 16, 2026 20:12
@snicoll

snicoll commented Jul 16, 2026

Copy link
Copy Markdown
Member

Thanks but we don't need to optimize this. The issue you described is impactful with a large number of issues and irrelevant for what this part of the code handles.

@snicoll snicoll closed this Jul 16, 2026
@snicoll snicoll added status: declined A suggestion or change that we don't feel we should currently apply and removed status: waiting-for-triage An issue we've not yet triaged labels Jul 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status: declined A suggestion or change that we don't feel we should currently apply

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants