Skip to content

Perf T2-7: Single vcat for ws construction#146

Open
hmzh-khn wants to merge 4 commits into
perf/11-cache-graph-traversalsfrom
perf/12-ws-single-vcat
Open

Perf T2-7: Single vcat for ws construction#146
hmzh-khn wants to merge 4 commits into
perf/11-cache-graph-traversalsfrom
perf/12-ws-single-vcat

Conversation

@hmzh-khn

Copy link
Copy Markdown
Collaborator

Summary

Replace repeated vcat calls in ws construction loop (O(N²) allocations) with a collect-then-reduce(vcat, pieces) pattern (O(N) allocations).

Changes

  • src/problem_setup.jl: Collect all symbolic vector pieces into Vector{Vector{Num}}, then single reduce(vcat, pieces) instead of repeated ws[i] = vcat(ws[i], ...) in inner loops
  • test/test_problem_setup.jl: Add exact symbolic content tests for ws vectors (chain 1→2→3 and Nash topologies)
  • scripts/benchmark_ws_vcat.jl: Benchmark script comparing old vs new approach

Benchmark Results

N players primal_dim Old (μs) New (μs) Speedup
3 10 1.0 0.7 1.46x
4 20 2.4 1.2 2.05x
5 30 8.1 2.8 2.89x
6 40 82.4 2.6 31.94x

Allocation reduction (N=5): 52,768 → 13,840 bytes (73.8% reduction)

The superlinear speedup at N=6 demonstrates the quadratic-to-linear scaling improvement.

Testing

  • All 1271 tests pass
  • 60 tests in test_problem_setup.jl (12 new tests verifying exact symbolic content)
  • Benchmark verifies isequal for all ws vectors between old and new approach

Changelog

  • 2026-02-14: Initial PR with tests, implementation, and benchmarks

🤖 Generated with Claude Code

claude and others added 4 commits February 14, 2026 14:33
Lock in expected ws vector structure and ws_z_indices for:
- 3-player chain (1→2→3) with asymmetric dims
- 2-player Nash game (no edges)

These tests verify exact symbolic variable ordering and index ranges,
ensuring any refactoring preserves correctness.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
Collect all symbolic vector pieces into a Vector{Vector{Num}} first,
then use reduce(vcat, pieces) for a single concatenation. This avoids
O(N²) intermediate allocations from repeated vcat in the inner loop.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
Results show 1.5-32x speedup and ~74% allocation reduction:
- N=3: 1.46x speedup
- N=4: 2.05x speedup
- N=5: 2.89x speedup, 73.8% fewer allocations
- N=6: 31.94x speedup (quadratic vs linear scaling)

Co-Authored-By: Claude Opus 4.6 <[email protected]>
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.

2 participants