Optimize Gap Analysis by Pruning Gap Analysis Traversal Using Tiered Neo4j Queries to Improve Performance #716
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
🚀 Prune Gap Analysis Search to Save Time and Memory
This PR implements a tiered pruning strategy for Gap Analysis to significantly reduce execution time and memory usage during map analysis.
The change directly addresses Issue #506 and aligns with the original design discussion around stopping early when strong or medium links are found.
🧠 Problem
Gap analysis currently performs an expensive wildcard Neo4j traversal:
This approach:
In practice, we are only interested in the strongest connections between standards.
✅ Solution: Tiered Pruning Strategy
The search is now executed in three tiers, with early exit once results are found.
Tier 1 – Strong Links
Executed first. If any paths are found, the search stops immediately.
Relationships included:
LINKED_TOAUTOMATICALLY_LINKED_TOSAMEThese correspond to the strongest connections (penalty = 0) and include equivalence (
SAME) relationships.Tier 2 – Medium Links
Executed only if Tier 1 returns no results.
Relationships included:
LINKED_TOAUTOMATICALLY_LINKED_TOSAMECONTAINSThis captures hierarchical relationships without falling back to a full wildcard traversal.
Tier 3 – Fallback (Wildcard)
Executed only if Tier 1 and Tier 2 return no paths.
This preserves existing behavior as a fallback to ensure no loss of coverage.
🧪 Testing
A new unit test has been added to verify pruning behavior:
Test command:
All existing gap analysis tests continue to pass.
📈 Impact
🔗 Related Issue
Prune map analysis search to save time and memory
Fixes #506
📝 Notes