Skip to content

perf: cache dependency refs to skip redundant registration in validate() - #1033

Open
saquibsaifee wants to merge 5 commits into
CycloneDX:mainfrom
saquibsaifee:perf-optimize-bom-validate-17515006840806688594
Open

saquibsaifee wants to merge 5 commits into
CycloneDX:mainfrom
saquibsaifee:perf-optimize-bom-validate-17515006840806688594

Conversation

@saquibsaifee

@saquibsaifee saquibsaifee commented Aug 31, 2026 •

Copy link
Copy Markdown
Contributor

Description

Optimizes Bom.validate() from $O(N^2)$ to $O(N \log N)$ by eliminating redundant linear scans over self.dependencies when ensuring dependable elements are registered, directly adding missing entries while tracking seen references in $O(1)$.

Changes:

  • Track existing dependency references dynamically to skip redundant registration for already-registered components and services.
  • Directly add missing dependable entries to _dependencies with active set tracking, eliminating repeated linear filter scans over the dependency collection.
  • Clean up collection comprehensions in dependency graph validation.

Affirmation

@saquibsaifee
saquibsaifee requested a review from a team as a code owner August 31, 2026 15:22
@saquibsaifee

saquibsaifee commented Aug 31, 2026 •

Copy link
Copy Markdown
Contributor Author

During the generation of large SBOMs, validation times were high due to generator evaluation.
With this change, the Bom.validate() running time on an SBOM with 2500 nested components and 2500 services executed 10 times drops from 49.4 seconds down to 5.1 seconds. This yields a 10x execution speedup in terms of validation execution alone.

@codacy-production

codacy-production Bot commented Aug 31, 2026 •

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 7 complexity · 0 duplication

Metric Results
Complexity 7
Duplication 0

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@read-the-docs-community

read-the-docs-community Bot commented Aug 31, 2026 •

Copy link
Copy Markdown

@saquibsaifee

Copy link
Copy Markdown
Contributor Author

@jkowalleck can you take a look at this PR to boost SBOM generation turn around

Signed-off-by: saquibsaifee <saquibsaifee2@gmail.com>
@saquibsaifee
saquibsaifee force-pushed the perf-optimize-bom-validate-17515006840806688594 branch from 6f5dc72 to e05bb2f Compare August 31, 2026 16:08
@saquibsaifee saquibsaifee changed the title perf: Optimize SBOM validation by removing itertools.chain perf: optimize validation by removing itertools.chain Sep 16, 2026
@saquibsaifee saquibsaifee changed the title perf: optimize validation by removing itertools.chain perf: cache dependency refs to skip redundant registration in validate() Sep 16, 2026
@saquibsaifee

Copy link
Copy Markdown
Contributor Author

Need to look into this again, might not be adding any performance improvement at all

…n validate()

Signed-off-by: Saquib Saifee <66195765+saquibsaifee@users.noreply.github.com>
 into perf-optimize-bom-validate-17515006840806688594
@saquibsaifee

Copy link
Copy Markdown
Contributor Author

@jkowalleck, this PR is ready for review.

@kmlyz kmlyz left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested test_model_bom and JSON/XML v1.6 serialization across this branch and #1007 (which also addresses #1006). Both produce identical output and reduce BomRef.__eq__ calls in validate() at N = 4000 from 8,051,885 to 49,884. Reading self._dependencies directly in Step 0 and keeping set(chain(...)) in Step 1 avoids per-iteration loop overhead (162 ms vs 176 ms). The added component and service shared bom_ref test is useful coverage either way.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants