Skip to content

Perf T3-1: Remove unnecessary Num conversions#133

Open
hmzh-khn wants to merge 4 commits into
mainfrom
perf/24-symbolics-num-conversion
Open

Perf T3-1: Remove unnecessary Num conversions#133
hmzh-khn wants to merge 4 commits into
mainfrom
perf/24-symbolics-num-conversion

Conversation

@hmzh-khn

Copy link
Copy Markdown
Collaborator

Summary

Remove redundant Symbolics.Num() broadcast conversions in preoptimize_nonlinear_solver (lines 462, 472 of src/nonlinear_kkt.jl). The vcat of symbolic vectors already produces Vector{Num}, making the Num.() wrapper a no-op allocation.

Adds a _ensure_num_vec helper with two-method dispatch: returns Vector{Num} unchanged (identity), converts other vector types via broadcast.

Changes

  • src/nonlinear_kkt.jl: Add _ensure_num_vec helper; replace Symbolics.Num.(...) calls at MCP construction sites
  • test/test_num_conversion.jl: New test file verifying types are already Num, helper dispatch works, and MCP output is identical
  • test/test_tiers.jl: Add new test to fast tier
  • test/test_test_tiers.jl: Update tier validation expected lists

Impact

Negligible — this optimizes solver setup (one-time cost), not the solve hot path. Eliminates one unnecessary broadcast allocation per call to preoptimize_nonlinear_solver.

Testing

  • 543 fast-tier tests pass (FAST_TESTS_ONLY=true)
  • 11 new tests specifically for the Num conversion optimization

Changelog

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

🤖 Generated with Claude Code

claude and others added 4 commits February 14, 2026 00:55
Tests verify that KKT condition vectors and parameter vectors are already
Symbolics.Num-typed, making explicit Num.() conversion redundant.
Includes test for _ensure_num_vec helper (not yet implemented).

Co-Authored-By: Claude Opus 4.6 <[email protected]>
Add _ensure_num_vec helper that returns Vector{Num} unchanged (no-op) and
only converts non-Num vectors. Applied at lines 462 and 472 in
preoptimize_nonlinear_solver where vcat already produces Vector{Num}.

Impact: eliminates unnecessary broadcast allocation during solver setup.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
Add test_num_conversion.jl to expected file lists in test_test_tiers.jl
so the tier self-test passes. All 543 fast tests now pass.

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