Skip to content

Perf T2-8: Single-pass all_variables#147

Open
hmzh-khn wants to merge 3 commits into
perf/12-ws-single-vcatfrom
perf/23-all-variables-single-pass
Open

Perf T2-8: Single-pass all_variables#147
hmzh-khn wants to merge 3 commits into
perf/12-ws-single-vcatfrom
perf/23-all-variables-single-pass

Conversation

@hmzh-khn

@hmzh-khn hmzh-khn commented Feb 14, 2026

Copy link
Copy Markdown
Collaborator

Summary

Replace nested vcat(vcat([zs[i] for i in 1:N]...), vcat([λs[i] for i in 1:N]...), ...) with a pre-allocated vector and copyto! calls for single-pass assembly.

Changes

  • src/problem_setup.jl: Replace nested vcat splatting with pre-allocated Vector(undef, total_len) and copyto! fill
  • test/: Add tests verifying symbolic equality of all_variables for chain and Nash topologies

Benchmark Results

  • Old (nested vcat): 1,680 bytes/call
  • New (single-pass): 656 bytes/call
  • 61% allocation reduction

Known Issue (pre-existing)

The μs section iterates values(μs) on a Dict, which has non-deterministic ordering in Julia. This is a pre-existing issue from the original code — this PR preserves the same iteration pattern. If all_variables ordering needs to be canonical, a follow-up should sort the μs keys. The test validates against the same values() call so it always passes within a single run.

Testing

  • All tests pass
  • Symbolic equality verified with isequal for 3-player chain (with μs) and 2-player Nash (without μs)

Changelog

  • 2026-02-14: Initial PR
  • 2026-02-15: Documented pre-existing Dict ordering issue with μs

🤖 Generated with Claude Code

claude and others added 3 commits February 14, 2026 15:07
Tests verify that all_variables is the correct flat concatenation of
zs, λs, and μs in player order, for both hierarchical (with μs) and
Nash (without μs) game structures.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
Replace nested vcat operations with pre-allocated vector and copyto!
calls. Computes total length upfront, allocates once, then copies
zs, λs, and μs segments sequentially. Eliminates intermediate array
allocations from vcat splatting.

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