Skip to content

A census of JIT and light-frame coverage without running code, and perf-step judged by it - #232

Merged
Largo merged 2 commits into
masterfrom
jit-census
Nov 18, 2026
Merged

Largo merged 2 commits into
masterfrom
jit-census

Conversation

@Largo

@Largo Largo commented Nov 18, 2026 •

Copy link
Copy Markdown
Owner

What

IronRuby.jit_census(paths) and Util/perf/census.rb: what the method JIT and the light frames make of every def in a set of files, found without running any of them. Each file is parsed and each method goes through the decisions its first call would take it through:

  • the body's transformation: a light frame, or the reason it keeps its scope, and how many of its blocks run without one;
  • JitStub.Wrap's static decision: the parameter list and the screen;
  • JitCompiler.TryCompile for parameters that are all Integers, all Floats and all objects, with no receiver profile.

A method is then never (no profile can make it compile), compiles (a typed body exists without a profile) or maybe (the profile decides).

$ ./ir.sh Util/perf/census.rb Src/StdLib
census: 27944 methods in 1654 files, 9.8 s

light frames    17952   64.2% of methods run without a scope
light blocks     7246   63.4% of the 11426 blocks in them
JIT compiles     2810   10.1%
JIT maybe        2296    8.2%
JIT never       22838   81.7%  (parameters 4152, screen 18686)

JIT never: what refused the method
  14434  MethodCall (screen)                new 936, is_a? 666, each 577, raise (self) 558, map 375, enter 233
   1902  uses its block (parameters)
   1120  rest parameter (parameters)
   ...

-o FILE saves a census, -d FILE lists the methods whose verdict changed against a saved one, -c LOG checks the census against the stderr of a run traced with IR_JIT_VERBOSE=1 IR_LIGHT_FRAMES=why, -l lists every method.

perf-step (second commit) now judges a change by the census instead of by the clock and the gate: the worktree's census against the saved census of the unchanged build, ten seconds. It keeps the differential matrix for the code touched and a traced run checked with -c, both seconds. /perf-gate and /perf-measure are owed once to the branch, before it is pushed; until then a step's ledger entry says "census only, not gated" and a step does not push.

Changes to the runtime

  • JitCensus.cs (new). The census has no class to resolve a method's calls on, so the screen's question "may the typed body inline this call?" is answered from the methods the files define in the same class body, then from what Object has in the process.
  • JitStub: ParameterShape names what the parameter list refused (the same tests Screen made inline), Screen takes the callee test from the census when given one, and IsLeafShape is IsLeafMethod's test on a syntax tree alone.
  • JitCompiler.Bail and JitScreen.No keep their reason for the census as they do for IR_JIT_VERBOSE.
  • MethodDefinition.TransformBody tells the census what it tells stderr under IR_LIGHT_FRAMES=why; BlockDefinition counts the blocks that run without a scope.

Nothing changes for code that is compiled to run: the hooks are null there.

How it was checked

  • -c against traced runs: all 14 AWFY benchmarks (346 of their 391 methods called), the standard library methods those runs called (73), and an mspec run over core/array, library/stringio and library/matrix (776). Every method agreed on both the light frame and the screen verdict, and no method a run specialized was never.
  • Of the 40 methods the runs declined, the census had 5 as compiles: that verdict is a typed body without a profile, and the profile can still say otherwise (a nil receiver, a String argument).
  • IronRuby.Tests on net10.0: 1,270 tests pass, with the new JitCensus1.
  • Every command in the rewritten skill was run as written.

Not run: net11.0 (this PR's CI), ruby/spec.

Limits

  • It counts methods, not calls: a refusal in a method nothing calls costs nothing. Weighting by a stored call profile is not built.
  • def only: not loops compiled on their own, not define_method bodies.
  • With perf-step judged by the census, a step no longer shows that a change computes the same thing beyond what its matrix probes, or that covering more was faster on the clock. That is what step 5 of the skill defers to the gate.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features
    • Added a JIT census tool that analyzes Ruby files without executing them and reports method-level JIT eligibility and light-frame coverage, including reasons for ineligible methods.
    • Census results can be listed, saved, and compared with another census or a runtime log to identify discrepancies.
  • Documentation
    • Updated performance-work guidance to use census results when evaluating optimizations and to run performance checks before pushing changes.

Largo and others added 2 commits November 19, 2026 00:19
…ithout running it

Whether the method JIT or the light frames cover a method was only visible
by running a program with IR_JIT_VERBOSE=1 or IR_LIGHT_FRAMES=why: it
showed the methods that program happened to call, and took as long as the
program. Most of both decisions is made from the syntax tree, though, the
first time a method is called.

IronRuby.jit_census(paths) parses the files and takes each `def' through
those decisions without running anything (Runtime/Jit/JitCensus.cs):

- the body's transformation, which says whether it is a light frame and
  why not (MethodDefinition.TransformBody now tells the census what it
  tells stderr), and how many of its blocks run without a scope;
- JitStub.Wrap's static decision: the parameter list (ParameterShape names
  what refused it) and the screen. The screen asks which calls the typed
  body may inline; with no class to resolve them on, the census answers
  from the methods the files define in the same class body, then from what
  Object has, and takes an unknown name as IsLeafMethod takes a method not
  defined yet (IsLeafShape is that test on a syntax tree alone);
- JitCompiler.TryCompile for parameters that are all Integers, all Floats
  and all objects, with no receiver profile.

A method is then `never' (no profile can make it compile), `compiles' (a
typed body exists without a profile) or `maybe' (the profile decides).

Util/perf/census.rb prints the counts and the reasons, most frequent first,
saves a census (-o), lists the methods whose verdict changed against a saved
one (-d), and checks itself against the stderr of a traced run (-c).

The whole standard library is 27,944 methods in 9.8 s: 64.2% light frames,
10.1% compiles, 8.2% maybe, 81.7% never. Checked with -c against traced
runs: all 14 AWFY benchmarks (346 of their 391 methods called), the
standard library methods those runs called (73), and an mspec run over
core/array, library/stringio and library/matrix (776). Every method agreed
on both the light frame and the screen, and no method a run specialized
was `never'. IronRuby.Tests passes on net10.0 (1,270 tests, with the new
JitCensus1); net11.0 and ruby/spec were not run.

The census counts methods, not calls, and covers `def' only: not loops
compiled on their own, not define_method bodies.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
Each step of the perf loop measured its change on the clock - the micro
table, the AWFY suite twice in both orders - and ran /perf-gate
(IronRuby.Tests, ruby/spec language, the matrices in every mode) before
merging it. That is most of an hour per change, needs a quiet machine, and
is the same hour whether the change did anything or not.

A step is now judged by Util/perf/census.rb: the worktree's census against
the saved census of the unchanged build (-d), which takes ten seconds for
the standard library and the AWFY benchmarks and names each method whose
verdict moved. A change is kept if methods moved up (a scope to a light
frame, never to maybe or compiles) and none moved down. Two things that
take seconds stay: the differential matrix for the code touched, which is
all a step has to say that the code computes the same, and a traced run of
the benchmarks concerned checked against the census (-c) - a move from
never to maybe counts only if the trace shows such methods specialized,
since loosening the screen alone makes a method slower. A gap the census
cannot see (how fast covered code runs) is judged by instructions per call
(ab.rb -i).

What a step no longer runs is owed once to the branch (step 5): /perf-gate
and /perf-measure for all the steps since the last gated commit, before the
branch is pushed or a pull request is opened. Until then a step's entry in
the ledger says "census only, not gated", and a step does not push.

Every command in the skill was run as written against this build.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
@coderabbitai

coderabbitai Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

Explain Change →

Caution

Review failed

The pull request is closed.

Walkthrough

The PR adds a method-level JIT and light-frame census, exposes it through IronRuby and a command-line tool, and adds tests. It also changes performance guidance to select work based on census coverage and defer test suites, gates, and timing to branch-level runs.

Changes: JIT Census and Performance Workflow

Layer / File(s) Summary
Census-aware compiler screening
Src/Ruby/Compiler/AstGenerator.cs, Src/Ruby/Compiler/Ast/BlockDefinition.cs, Src/Ruby/Compiler/Ast/Definitions/MethodDefinition.cs, Src/Ruby/Runtime/Jit/JitStub.cs, Src/Ruby/Runtime/Jit/JitCompiler.cs
Compiler and JIT screening now record light-frame outcomes, block scope information, and rejection or bailout reasons when a census is active. JIT screening also uses shared parameter-shape and leaf-method checks.
Census API and source collection
Src/Ruby/Runtime/Jit/JitCensus.cs, Src/Libraries/Extensions/IronRubyOps.cs
JitCensus parses files without executing them, collects method definitions, and returns file-level errors. The IronRuby.jit_census method accepts an array of paths and returns census results.
Method transformation and JIT verdicts
Src/Ruby/Runtime/Jit/JitCensus.cs
The census reports method metadata and light-frame transformation results, then evaluates parameter shapes, screening results, and compilation probes for integer, double, and object typings.
Census command-line reporting and tests
Util/perf/census.rb, Src/IronRuby.Tests/Runtime/LoopTests.cs, Src/IronRuby.Tests/RubyTests.cs
The command-line tool reports census totals and compares saved censuses and run logs. The registered test checks method metadata, verdicts, non-executing parsing, and missing-file errors.
Census-based performance workflow
.claude/skills/perf-step/SKILL.md, CLAUDE.md
Performance guidance now uses census coverage to assess candidate changes and defers suites, gates, and timing to branch-level runs. Ledger entries distinguish census results from gated results.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant CensusTool as census.rb
  participant IronRubyAPI as IronRuby.jit_census
  participant JitCensus
  participant RubyParser
  participant JitStub
  participant JitCompiler
  CensusTool->>IronRubyAPI: Submit source paths
  IronRubyAPI->>JitCensus: Run census for paths
  JitCensus->>RubyParser: Parse source files without execution
  RubyParser-->>JitCensus: Return parsed method definitions
  JitCensus->>JitStub: Screen methods and parameter shapes
  JitStub-->>JitCensus: Return screening results
  JitCensus->>JitCompiler: Probe eligible methods
  JitCompiler-->>JitCensus: Return compilation outcome or bailout reason
  JitCensus-->>IronRubyAPI: Return method census records
  IronRubyAPI-->>CensusTool: Return census results
Loading

Possibly related PRs

  • Largo/ironruby#221: Adds the performance skills and study file that the updated perf-step guidance references.
  • Largo/ironruby#230: Adds the instruction-count mode and supporting tool referenced by the updated perf-step guidance.

Suggested reviewers: claude

Merge Risk: Moderate · up to ed6ca

The new JIT census can report some methods as never compiling when the runtime would accept them. The performance workflow also rejects valid parallel experiments after the baseline advances. Production execution paths are unchanged, but the tool that guides optimization decisions needs these corrections before it is relied on.

- [ ] Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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