Skip to content

Compile time: comdat table first in the module; --mlir-timing reports each stage - #863

Merged
ASDAlexander77 merged 2 commits into
mainfrom
perf-compile-time-2
Nov 15, 2026
Merged

ASDAlexander77 merged 2 commits into
mainfrom
perf-compile-time-2

Conversation

@ASDAlexander77

Copy link
Copy Markdown
Owner

Follow-up to #862: one more compile-time fix, and a working --mlir-timing to measure the rest with.

The module's comdat table is its first operation

MLIR's verifier and its translation to LLVM IR look the comdat table up by name for every global and function that has a comdat (a vtable, an RTTI record, a generic's instance), each time scanning the module from its start. tslang created the table wherever the first such global happened to be lowered.

It is now created at the start of the module and moved to the front once the conversion to LLVM is done (globals lowered after it are put in front of it during the conversion).

Translation to LLVM IR for a file of 4,000 small classes, object file, no optimisation:

Comdat table Translation to LLVM IR Whole compile (inside the timer)
last in the module 2.86 s 9.05 s
first in the module 0.52 s 6.42 s

The position before this change was in between: the whole compile went from 8.0 s to 7.8 s. Where the table stands changes nothing in the LLVM IR.

--mlir-timing reports where a compilation spends its time

The option was registered but printed nothing, because no timing manager was given to the pass manager. It now reports MLIR generation, each MLIR pass, the translation to LLVM IR, LLVM's optimizations and code emission, for every --emit.

  • Without the option the timing scopes are empty.
  • The JIT ends the process without running destructors, so it prints the report just before the program runs. That report does not include the machine code the JIT emits lazily.

docs/performance.md gets a "Compile time" section with the option and current figures.

Testing

  • Release suite on Windows x64: 7,445 tests, 5 failures, all test-borrow-facts-*. As in Compile time: no module scan for every new global (2,000 classes: 100 s -> 3 s) #862, they fail on my machine only (the build cache's CMAKE_AR names an MSVC toolset that is no longer installed) and pass when rerun with the installed lib.exe.
  • The suite with TSLANG_VERIFY_LLVM_GLOBALS_INDEX set (run for the comdat commit): no difference logged.
  • LLVM IR before Compile time: no module scan for every new global (2,000 classes: 100 s -> 3 s) #862 and after this branch, for the 150 largest tests, the ray tracer benchmark and a generated file, under default options, --opt_level=3 and -mm=rc: identical except 00param_assigned_owned.ts, whose output already differs from run to run.
  • --mlir-timing checked by hand for --emit=obj, llvm, exe and jit (with and without the JIT cache); a JIT run without the option prints only the program's output.

Not covered

  • Not built or tested on Linux, and not run with a Debug-built compiler.
  • No test is added for --mlir-timing or for compile time.
  • MLIR generation still grows faster than the source (2.65 times for twice the classes); this branch does not change it.

🤖 Generated with Claude Code

ASDAlexander77 and others added 2 commits November 15, 2026 15:13
MLIR's verifier and its translation to LLVM IR look the comdat table up by name
for every global and function that has a comdat (a vtable, an RTTI record, a
generic's instance), each time scanning the module from its start. The table
was created wherever the first such global happened to be lowered.

It is now created at the start of the module and moved to the front once the
conversion to LLVM is done (the globals lowered since are put in front of it).
With the table last in a module of 4,000 classes the translation to LLVM IR
takes 2.9 s, with it first 0.5 s. The LLVM IR does not change.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The option was registered but printed nothing: no timing manager was given to
the pass manager. It now reports MLIR generation, each MLIR pass, the
translation to LLVM IR, LLVM's optimizations and code emission, for every
--emit. The JIT ends the process without running destructors, so it prints the
report before the program runs.

docs/performance.md gets a "Compile time" section with the option and current
figures.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@ASDAlexander77
ASDAlexander77 merged commit cf0f78d into main Nov 15, 2026
8 checks passed
@ASDAlexander77
ASDAlexander77 deleted the perf-compile-time-2 branch November 15, 2026 15:49
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.

1 participant