apache / apache/maven-dependency-tree

FilteringDependencyNodeVisitor evaluates the filter twice per node

Open
#134 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
27
Forks
31
Avg merge
5h 53m
Merged PRs (30d)
1

Description

## Summary
`FilteringDependencyNodeVisitor` calls `filter.accept(node)` once in `visit(...)` and again in `endVisit(...)`, so every node is filtered twice during a single traversal.

## Affected code
`src/main/java/org/apache/maven/shared/dependency/graph/traversal/FilteringDependencyNodeVisitor.java`
- `visit(...)`: lines 64-74
- `endVisit(...)`: lines 80-90

## Impact
For an inexpensive filter this is a minor constant-factor waste. For expensive filters such as `AncestorOrSelfDependencyNodeFilter` (which walks to the root on each call), it doubles an already costly traversal and compounds the O(N·depth) cost of that filter.

## Suggested fix
Cache the per-node filter result during the walk (e.g. a small map keyed by node, or compute once and reuse for visit/endVisit), or document that filters should be cheap/idempotent.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with src/main/java/org/apache/maven/shared/dependency/graph/traversal/FilteringDependencyNodeVisitor.java, reading visit(...) and endVisit(...) together to understand the traversal lifecycle. Trace how the filter result controls both methods, then verify that each node is evaluated once while traversal behavior is preserved. Done means expensive filters no longer run twice per node.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
build-system
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.