Perf T2-7: Single vcat for ws construction#146
Open
hmzh-khn wants to merge 4 commits into
Open
Conversation
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]>
Co-Authored-By: Claude Opus 4.6 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Replace repeated
vcatcalls 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 intoVector{Vector{Num}}, then singlereduce(vcat, pieces)instead of repeatedws[i] = vcat(ws[i], ...)in inner loopstest/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 approachBenchmark Results
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
isequalfor all ws vectors between old and new approachChangelog
🤖 Generated with Claude Code