Skip to content

Fix/clean unused components performance#2030

Merged
DerManoMann merged 3 commits into
zircote:masterfrom
DerManoMann:fix/clean-unused-components-performance
Jun 29, 2026
Merged

Fix/clean unused components performance#2030
DerManoMann merged 3 commits into
zircote:masterfrom
DerManoMann:fix/clean-unused-components-performance

Conversation

@DerManoMann

@DerManoMann DerManoMann commented Jun 29, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Replace O(n²) tree traversal in CleanUnusedComponents with direct Analysis::removeAnnotation() calls
  • Consolidate removeAnnotationRecursive() into shared AnnotationTrait

Fixes #1792, fixes #1739

Test plan

  • Added performance test (300 schemas, 40% unused) asserting cleanup overhead < 1.5x
  • All 1037 existing tests pass
  • composer performance runs the benchmark in isolation

DerManoMann and others added 3 commits June 29, 2026 17:32
Replace the O(n*m) AnnotationTrait-based removal with direct recursive
removal via Analysis::removeAnnotation(), and use isset() instead of
in_array() for ref lookups. This eliminates the expensive full-tree
traversal that occurred for every removed component.

Adds a performance regression test (composer performance) that asserts
cleanup overhead stays below 1.5x of base generation time.

Benchmarked: 1000 schemas, 500 unused — old code: 313s, new code: 5s.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The recurseCleanup flag was a no-op — AnnotationTrait::removeAnnotation
always collected the full subtree regardless, and traversal of the root
SplObjectStorage didn't depend on the flag for removal.

Migrates PathFilter to use Analysis::removeAnnotation() for consistency
with other processors, and removes the AnnotationTrait dependency.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Both CleanUnusedComponents and PathFilter had identical local
implementations. Move the shared method into AnnotationTrait, replacing
the old collectAnnotations/traverseAnnotations/removeAnnotation methods
that are no longer used.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@DerManoMann DerManoMann force-pushed the fix/clean-unused-components-performance branch from 217e454 to 966be6a Compare June 29, 2026 05:33
@DerManoMann DerManoMann merged commit 2f117df into zircote:master Jun 29, 2026
17 checks passed
@DerManoMann DerManoMann deleted the fix/clean-unused-components-performance branch June 29, 2026 05:37
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.

Processor CleanUnusedComponents gets slow between tags 4.7.16 and 4.11.1 Cleanup performance

1 participant