Skip to content

Only write printed type names into the IR when asked to - #3711

Merged
vchuravy merged 2 commits into
mainfrom
vc/skip-debug-type-names
Oct 4, 2026
Merged

vchuravy merged 2 commits into
mainfrom
vc/skip-debug-type-names

Conversation

@vchuravy

Copy link
Copy Markdown
Member

Requested by Valentin

Enzyme writes the printed Julia type next to types it records in the IR:

  • the enzymejl_parmtype_str parameter/return attribute (set_module_types!, lower_convention, specsig_function!),
  • one enzymejl_source_type_<T> metadata kind per type (compile_unhooked_impl, memcpy_alloca_to_loadstore), which also registers a new metadata kind in the context for every distinct type,
  • enzymejl_allocart_name.

Nothing reads these; they only help when reading IR dumps. The C++ side only copies enzymejl_allocart_name along with enzymejl_allocart when it replaces an alloca, and does nothing if it is missing.

Printing a type is slow on Julia 1.12 (show looks through module bindings for an alias of the type: make_typealias, jl_get_binding_partition), and Enzyme records a type for most loads, allocas and calls of every function in the module. In a profile of a TensorKit.jl test_reverse call this was the largest single item inside compile_unhooked_impl.

This PR emits the names only when Enzyme.Compiler.EmitTypeNames[] is set, like the existing Dump* debug flags.

Measurement

The Enzyme tests of TensorKit.jl (QuantumKitHub/TensorKit.jl#464, svd_trunc_no_error/lq_compact/qr_compact, Trivial and Z2 sectors, Float64 and ComplexF64, two tensor shapes; 72 test_reverse calls, each compiling one new thunk), Julia 1.12.7, both configurations run at the same time:

total
main 472 s
this PR 427 s

That's 5-15% per call, and all tests passed in both runs.

Tests

Added a test that turns EmitTypeNames[] on and checks a gradient, so the debug path keeps compiling. optimize, basic, callconv and rooted_args pass locally on 1.12.

🤖 Generated with Claude Code

@github-actions

github-actions Bot commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Benchmark Results

main e42fd02... main / e42fd02...
basics/make_zero/namedtuple 0.0436 ± 0.0038 μs 0.0433 ± 0.0037 μs 1.01 ± 0.12
basics/make_zero/struct 0.198 ± 0.0077 μs 0.198 ± 0.0071 μs 1 ± 0.053
basics/overhead 3.79 ± 0.01 ns 3.79 ± 0.01 ns 1 ± 0.0037
basics/remake_zero!/namedtuple 0.18 ± 0.0065 μs 0.183 ± 0.0066 μs 0.984 ± 0.05
basics/remake_zero!/struct 0.179 ± 0.0085 μs 0.18 ± 0.0077 μs 0.993 ± 0.064
fold_broadcast/multidim_sum_bcast/1D 0.436 ± 0.0081 μs 0.435 ± 0.0065 μs 1 ± 0.024
fold_broadcast/multidim_sum_bcast/2D 0.316 ± 0.0052 μs 0.316 ± 0.005 μs 1 ± 0.023
inline_abi/call 12.7 ± 0.019 ns 12.7 ± 0.01 ns 1 ± 0.0017
inline_abi/call_alloc 0.0368 ± 0.0011 μs 0.0366 ± 0.001 μs 1.01 ± 0.041
inline_abi/loop 3.52 ± 0.0036 μs 3.52 ± 0.0036 μs 1 ± 0.0015
time_to_load 1.28 ± 0.021 s 1.28 ± 0.0088 s 0.996 ± 0.017

Benchmark Plots

A plot of the benchmark results has been uploaded as an artifact at https://github.com/EnzymeAD/Enzyme.jl/actions/runs/37088582797/artifacts/11261497460.

Copy link
Copy Markdown
Member Author

Integration Tests - Flux - Julia 1.11 fails here with an EnzymeInternalError in the GRU, LSTM and Chain(LSTM, LSTM) testsets (inside broadcast_unalias → mightalias). That isn't this PR's doing: the same check fails the same way on #3709, which is also based on today's main and doesn't touch this code, and Flux passes on 1.10, 1.12 and 1.13 here. I don't know of a fix for it yet, so there's nothing to port.


Generated by Claude Code

@codecov

codecov Bot commented Sep 29, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 93.75000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 80.10%. Comparing base (8d7355b) to head (e42fd02).

Files with missing lines Patch % Lines
src/compiler/callconv.jl 50.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3711      +/-   ##
==========================================
+ Coverage   75.88%   80.10%   +4.21%     
==========================================
  Files          71       71              
  Lines       24486    24180     -306     
==========================================
+ Hits        18581    19369     +788     
+ Misses       5905     4811    -1094     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown
Member Author

codecov/project is red for a -0.03% change (80.02% vs 126f916). The same check is red on #3709 against the same base, and the lines this PR gates are covered by the new EmitTypeNames test, so I'm leaving it as is.


Generated by Claude Code

Comment thread src/compiler/utils.jl Resolved
@vchuravy
vchuravy marked this pull request as ready for review September 29, 2026 13:33
vchuravy and others added 2 commits October 3, 2026 04:03
Enzyme writes the printed Julia type next to types it records in the IR:
the `enzymejl_parmtype_str` attribute, one `enzymejl_source_type_<T>`
metadata kind per type, and `enzymejl_allocart_name`. Nothing reads them;
they help when reading IR dumps. Printing a type is slow on Julia 1.12,
because `show` looks through module bindings for an alias of the type,
and `set_module_types!` and `compile_unhooked_impl` record a type for most
instructions of every function in the module.

Emit them only when `Enzyme.Compiler.EmitTypeNames[]` is set. On the
Enzyme tests of TensorKit.jl this saves 5-15% of the time of each
test_reverse call (472 s -> 427 s for 72 calls).

Assisted-by: Claude Code (Opus 5.5)
Co-authored-by: Valentin Churavy <v.churavy@gmail.com>
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NTwXtqA78uTQz6CYsAJDzb
@vchuravy
vchuravy force-pushed the vc/skip-debug-type-names branch from 1739603 to e42fd02 Compare October 3, 2026 02:05
@vchuravy
vchuravy merged commit 34e265d into main Oct 4, 2026
109 of 110 checks passed
@vchuravy
vchuravy deleted the vc/skip-debug-type-names branch October 4, 2026 11:42
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