Perf #7: Investigate Dict{Int, Any} type stability in KKT construction#157
Open
hmzh-khn wants to merge 4 commits into
Open
Perf #7: Investigate Dict{Int, Any} type stability in KKT construction#157hmzh-khn wants to merge 4 commits into
hmzh-khn wants to merge 4 commits into
Conversation
Tests verify that:
- Hot-path containers (K_evals, M_evals, N_evals, M_buffers, N_buffers)
use concrete value types for type-stable access during Newton iterations
- Cold-path dicts (πs, Ms, Ns, Ks) intentionally use Dict{Int, Any}
for heterogeneous symbolic types (BlockVector vs Vector{Num})
- π_sizes_trimmed is Dict{Int, Int} (not Any)
- Pre-allocated k_eval_buffers are reused (identity check)
- End-to-end solve produces correct results with all typed containers
These tests protect against regressions if someone "improves" the cold-path
dicts or accidentally introduces Any-typed containers on the hot path.
Co-Authored-By: Claude Opus 4.6 <[email protected]>
- Add explicit type annotation on π_sizes_trimmed in preoptimize_nonlinear_solver
for self-documentation (Julia already inferred this correctly)
- Register test_typed_kkt_dicts.jl in slow test tier
- Update test_test_tiers.jl expected file lists
Investigation finding: All Dict{Int, Any} instances in qp_kkt.jl (lines 92-95)
and nonlinear_kkt.jl (line 256) are COLD PATH only — used during one-time
symbolic construction, never accessed in the Newton iteration loop. The hot-path
containers (K_evals, M_evals, M_buffers, etc.) already use concrete types
(Vector{Union{Matrix{Float64}, Nothing}}, Dict{Int, Matrix{Float64}}).
Co-Authored-By: Claude Opus 4.6 <[email protected]>
Benchmarks verify that hot-path dict access (Dict{Int, Matrix{Float64}})
is not a bottleneck. Includes micro-benchmark comparing typed vs untyped
dict access, and full solve / compute_K_evals benchmarks.
Co-Authored-By: Claude Opus 4.6 <[email protected]>
Key finding: All Dict{Int, Any} in KKT construction are cold-path only.
Hot-path containers were already well-typed from previous PRs.
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
Investigation PR for Dict{Int, Any} type instability in KKT construction (
qp_kkt.jllines 92-95,nonlinear_kkt.jlline 256).Key finding: All
Dict{Int, Any}instances are COLD PATH only. They are used during one-time symbolic construction and never accessed in the Newton iteration loop. The hot-path containers were already correctly typed from previous PRs (Perf #4-6):Vector{Union{Matrix{Float64}, Nothing}}for K/M/N evalsDict{Int, Matrix{Float64}}for M/N buffersVector{MNFunctionWrapper}for compiled M/N functionsVector{Int}for π_sizesChanges
src/nonlinear_kkt.jl: Add explicitDict{Int, Int}type annotation onπ_sizes_trimmed(self-documenting, Julia already inferred correctly)test/test_typed_kkt_dicts.jl: 24 new regression tests documenting hot-path vs cold-path type guaranteestest/test_tiers.jl: Register new test in slow tiertest/test_test_tiers.jl: Update expected file listsscripts/benchmark_typed_kkt_dicts.jl: Benchmark script for typed dict accessRETROSPECTIVES.md: PR retrospectiveTesting
julia --project=. -e 'using Pkg; Pkg.test()')Investigation Details
Call chain trace:
solve()→run_nonlinear_solver()→compute_K_evals()(hot path)πsDict{Int, Any}MsDict{Int, Any}NsDict{Int, Any}KsDict{Int, Any}π_sizes_trimmedDict{Int, Int}M_buffersN_buffersK_evalsChangelog
🤖 Generated with Claude Code