Perf T3-5: Optimize BFS collect with typed Vector{Int}#145
Open
hmzh-khn wants to merge 4 commits into
Open
Conversation
Characterization test verifying that manual BFS iteration (skipping self) produces identical follower lists to collect(BFSIterator(...))[2:end]. Tests both chain and branching graph topologies. Co-Authored-By: Claude Opus 4.6 <[email protected]>
Avoids intermediate allocation from collect() followed by array
slicing. The manual loop skips self directly and produces a
properly typed Vector{Int} instead of Vector{Any}.
Impact is negligible (per-player, first-iteration only, cached
thereafter) but eliminates unnecessary allocations.
Co-Authored-By: Claude Opus 4.6 <[email protected]>
Results show modest improvements:
- 1.0-1.5x speedup depending on graph size
- ~14% fewer allocations (avoids intermediate array + slice)
- Type stability: Vector{Any} -> Vector{Int64}
- Impact is negligible (per-player, first-iteration only, cached)
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
collect(BFSIterator(graph, ii))[2:end]with manual iteration that producesVector{Int}instead ofVector{Any}. This improves type stability of the cached follower list.Note: The 11-15% allocation reduction applies only to the BFS collect micro-operation itself (e.g., 656B vs 576B), not to overall solver allocations. This code runs once per player and is then cached, so the impact on total allocations is negligible. The primary value is the type stability improvement (
Vector{Any}→Vector{Int}).Changes
src/nonlinear_kkt.jl: Replacecollect(BFSIterator(...))[2:end]with manual iteration producingVector{Int}test/: Add characterization tests verifying equivalence on chain and branching topologiesTesting
Changelog
🤖 Generated with Claude Code