Skip to content

perf: optimize vex and progress hot paths#1639

Open
sozercan wants to merge 7 commits into
mainfrom
perf3
Open

perf: optimize vex and progress hot paths#1639
sozercan wants to merge 7 commits into
mainfrom
perf3

Conversation

@sozercan

@sozercan sozercan commented Jul 2, 2026

Copy link
Copy Markdown
Member

Summary

  • Stabilize Node.js e2e CI by filtering the patch report to Node package findings before invoking the Node language patch path.
  • Add focused benchmarks for VEX generation/output, generate tar hardlink rewriting, progress forwarding, and TUI progress bookkeeping.
  • Optimize VEX statement grouping and subcomponent deduplication with indexed lookups, and stream VEX JSON directly to the output file path.
  • Optimize generate tar hardlink handling by caching only actual hardlink targets and writing deferred hardlinks deterministically.
  • Optimize BuildKit progress handling by caching prefixed digest remaps and keeping TUI progress tasks scoped per vertex.

Impact

Representative benchmark improvements from this pass:

  • Large OpenVEX document creation: ~7.63 ms/op → ~5.76 ms/op, with allocations reduced from ~20.7k/op to ~6.3k/op.
  • OpenVEX file output: ~10.2 ms/op → ~9.0 ms/op, with allocated bytes reduced from ~6.38 MB/op to ~5.16 MB/op.
  • Generate tar hardlink rewrite: ~32.4 ms/op → ~29.6 ms/op, with allocated bytes reduced from ~10.9 MB/op to ~6.48 MB/op.
  • Progress digest remapping: ~73,984 ns/op → ~9,274 ns/op, with allocations reduced from 1,328/op to 140/op.
  • TUI progress task bookkeeping: ~402 ms/op → ~57 ms/op, with allocated bytes reduced from ~685 MB/op to ~53 MB/op.

Live end-to-end copa generate comparison on a warmed Alpine report flow showed a modest improvement because BuildKit/package-manager work dominates that scenario:

  • Baseline median: 2.539s
  • Optimized median: 2.485s
  • Median improvement: ~2.1%

This intentionally avoids the performance areas already covered by #1638.

Validation

  • go run mvdan.cc/gofumpt@v0.9.2 -w ...
  • git diff --check
  • go test ./pkg/... -count=1
  • make build
  • go test ./test/e2e/generate -run '^TestGenerateWithVEXOutput$' -count=1 -timeout 30m -args -copa $(pwd)/dist/darwin_arm64/release/copa -addr docker://
  • Targeted benchmark suites for pkg/vex, pkg/generate, pkg/common, and pkg/tui
  • golangci-lint run --new-from-rev=HEAD ./pkg/vex ./pkg/generate ./pkg/common ./pkg/tui0 issues
  • python3 /Users/sozercan/.codex/skills/autoreview/scripts/autoreview --mode local
    • Final result: autoreview clean: no accepted/actionable findings reported
    • overall: patch is correct (0.86)

Notes

  • The Node.js e2e report filtering is intentionally included as a CI stabilization fix for this PR: the failing job was pulling non-Node library findings into the Node patch test, which made it exercise unrelated Go rebuild logic.
  • make lint was run and still reports pre-existing repository-wide lint issues unrelated to this change set (goconst, existing gosec, govet, gocritic, and staticcheck). New lint findings from this change were fixed.
  • Development tracking and raw benchmark notes were kept in /tmp/perf3-copa.md.

Signed-off-by: Sertac Ozercan <sozercan@gmail.com>
@codecov

codecov Bot commented Jul 2, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 80.18018% with 22 lines in your changes missing coverage. Please review.
✅ Project coverage is 44.66%. Comparing base (9e8bba2) to head (dcaca18).

Files with missing lines Patch % Lines
pkg/vex/vex.go 56.66% 7 Missing and 6 partials ⚠️
pkg/vex/openvex.go 80.55% 4 Missing and 3 partials ⚠️
pkg/tui/display.go 90.90% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1639      +/-   ##
==========================================
+ Coverage   44.23%   44.66%   +0.42%     
==========================================
  Files          58       58              
  Lines       10312    10366      +54     
==========================================
+ Hits         4562     4630      +68     
+ Misses       5435     5415      -20     
- Partials      315      321       +6     
Files with missing lines Coverage Δ
pkg/common/progress.go 91.83% <100.00%> (+63.26%) ⬆️
pkg/generate/generate.go 38.75% <100.00%> (+1.52%) ⬆️
pkg/tui/display.go 67.50% <90.90%> (+2.21%) ⬆️
pkg/vex/openvex.go 78.57% <80.55%> (+1.75%) ⬆️
pkg/vex/vex.go 60.52% <56.66%> (-22.81%) ⬇️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR optimizes several non-BuildKit hot paths that were not covered by #1638: VEX document generation/output, the copa generate patch-layer tar hardlink rewrite, progress forwarding across multiplexed builds, and TUI progress bookkeeping. It adds focused microbenchmarks alongside the optimizations, and the changes are largely behavior-preserving refactors that trade repeated work/allocations for indexed lookups and cached values.

Changes:

  • VEX: split CreateVEXDocument into an internal createVEXDocument returning *vex.VEX, stream JSON directly to the output file, and replace O(n) statement/subcomponent scans with indexed maps (statementByVulnerability, seenSubcomponents) plus a precomputed PURL qualifier suffix.
  • Generate: track actual hardlink targets so the second tar pass only buffers needed file contents, and sort hardlink names for deterministic build contexts.
  • Progress/TUI: cache prefixed digest remaps in ForwardProgressWithPrefix, and scope progress tasks per-vertex (vertexState) so completed vertices drop their tasks without prefix-scanning.
Show a summary per file
File Description
pkg/vex/vex.go Streams VEX JSON directly to the output file instead of buffering the full string
pkg/vex/openvex.go Indexed grouping/dedup and precomputed PURL prefix/qualifier suffix; adds createVEXDocument, vexSubcomponentKey, osPackageQualifiers
pkg/vex/openvex_benchmark_test.go New benchmarks for VEX creation and file output
pkg/tui/display.go Per-vertex task map (vertexState) replaces global prefix-keyed task cleanup
pkg/tui/display_benchmark_test.go New benchmark for progress task bookkeeping
pkg/generate/generate.go Caches only real hardlink targets and writes hardlinks in sorted order
pkg/generate/generate_benchmark_test.go New benchmark for sparse-hardlink tar rewrite
pkg/common/progress.go Caches digest remaps; removes redundant slice pre-assignment
pkg/common/progress_test.go New unit tests for remap correctness, non-mutation, nil-skip, cancellation
pkg/common/progress_benchmark_test.go New benchmark for repeated-digest forwarding

Review details

  • Files reviewed: 10/10 changed files
  • Comments generated: 1
  • Review effort level: Medium

Comment thread pkg/vex/vex.go Outdated
Signed-off-by: Sertac Ozercan <sozercan@gmail.com>

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a1633a8c61

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread pkg/tui/display.go Outdated
Signed-off-by: Sertac Ozercan <sozercan@gmail.com>
Copilot AI review requested due to automatic review settings July 2, 2026 20:32
Signed-off-by: Sertac Ozercan <sozercan@gmail.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Review details

  • Files reviewed: 13/13 changed files
  • Comments generated: 1
  • Review effort level: Medium

Comment thread test/e2e/nodejs/nodejs_test.go Outdated
Copilot AI review requested due to automatic review settings July 2, 2026 20:38

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Review details

  • Files reviewed: 13/13 changed files
  • Comments generated: 1
  • Review effort level: Medium

Comment thread test/e2e/nodejs/nodejs_test.go Outdated
Signed-off-by: Sertac Ozercan <sozercan@gmail.com>

# Conflicts:
#	test/e2e/nodejs/nodejs_test.go

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 005328b032

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread pkg/vex/vex.go
Signed-off-by: Sertac Ozercan <sozercan@gmail.com>
Copilot AI review requested due to automatic review settings July 2, 2026 21:06

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Review details

  • Files reviewed: 12/12 changed files
  • Comments generated: 0 new
  • Review effort level: Medium

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 59fd46619f

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread pkg/vex/vex.go
Comment thread pkg/vex/vex.go
Signed-off-by: Sertac Ozercan <sozercan@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: 🆕 New

Development

Successfully merging this pull request may close these issues.

2 participants