Skip to content

Optimize dependency graph building with O(1) lookups#1483

Merged
shs96c merged 1 commit into
bazel-contrib:masterfrom
shs96c:gradle-fast-lookups
Jan 9, 2026
Merged

Optimize dependency graph building with O(1) lookups#1483
shs96c merged 1 commit into
bazel-contrib:masterfrom
shs96c:gradle-fast-lookups

Conversation

@shs96c
Copy link
Copy Markdown
Collaborator

@shs96c shs96c commented Nov 19, 2025

Replace O(n²) linear searches with O(1) hash set lookups when checking if a dependency is in the requested deps list. Previously, isRequestedDep() was called inside nested loops, doing a full stream().anyMatch() scan for every dependency and child dependency, causing long delays on large dependency graphs.

Now creates a Set lookup cache at the start of parseDependencies() and uses constant-time contains() checks instead of linear scans.

@shs96c shs96c requested review from cheister and jin as code owners November 19, 2025 04:53
Replace O(n²) linear searches with O(1) hash set lookups when checking
if a dependency is in the requested deps list. Previously, isRequestedDep()
was called inside nested loops, doing a full stream().anyMatch() scan for
every dependency and child dependency, causing long delays on large
dependency graphs.

Now creates a Set<String> lookup cache at the start of parseDependencies()
and uses constant-time contains() checks instead of linear scans.
@shs96c shs96c force-pushed the gradle-fast-lookups branch from 0280fc4 to ce03807 Compare January 8, 2026 17:42
@shs96c shs96c merged commit fb9c549 into bazel-contrib:master Jan 9, 2026
6 checks passed
@shs96c shs96c deleted the gradle-fast-lookups branch January 9, 2026 17:04
shs96c added a commit to JonathanPerry651/rules_jvm_external that referenced this pull request Feb 3, 2026
* master: (25 commits)
  fix: use forward slash separator in Maven purl format (bazel-contrib#1530)
  Load rules from specific bzl files and add sh_test imports (bazel-contrib#1529)
  Added non-conflicting hash for install files (bazel-contrib#1454)
  Update the maven and coursier resolver tests to create a class index file. (bazel-contrib#1519)
  [ci] Drop Bazel 6 and ensure we run on Bazel 7 and 8 (bazel-contrib#1525)
  Only allow modules specified in known_contributing_modules to contribute artifacts or boms to the root module (bazel-contrib#1523)
  [gradle] Fix false resolution failures when BOM upgrades dependency version (bazel-contrib#1520)
  [gradle] Fix Gradle resolver to respect force_version and include runtime dependencies (bazel-contrib#1516)
  Correctly merge BOMs from non-root modules (bazel-contrib#1518)
  Update more lock files
  Filter test_only artifacts out of artifacts merged into root repos and print a warning when a root artifact version is overridden by a non_root bazel_dep (bazel-contrib#1511)
  Fix SHA mismatch for conflicting dependency versions (bazel-contrib#1513)
  [gradle] Plumb through the force_version attribute (bazel-contrib#1515)
  [gradle] Add dep exclusions to only that dep (bazel-contrib#1514)
  [gradle] Handle aggregating dependencies and relocation version conflicts (bazel-contrib#1512)
  BOM Fixes (bazel-contrib#1506)
  Allow an optional index of dep -> class to be created (bazel-contrib#1492)
  Put files in `ResolutionResult` (bazel-contrib#1484)
  Optimize dependency graph building with O(1) lookups (bazel-contrib#1483)
  Provide a mechanism to list all resolved direct deps for a workspace (bazel-contrib#1510)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants