Repository navigation
Faster calls, blocks and instance variables: 1.86x to 1.05x of CRuby on five AWFY benchmarks - #215
Merged
Merged
Conversation
IronRuby is about 1.9x slower than CRuby 4.0 and 40x slower than TruffleRuby 40 on the object-oriented Are-We-Fast-Yet benchmarks, and closing that is many small experiments, most of which do not pay. Three project skills make one experiment a repeatable step: - perf-measure: AWFY at steady state and per-operation costs against CRuby and TruffleRuby, recorded in Util/perf/LEDGER.md with the gaps ranked. - perf-step: take the worst open gap, try one optimization in a worktree of its own, measure it against the unchanged build, merge it only if it is faster and passes the gate, and write down the outcome either way. Meant for /loop. - perf-gate: the candidate must compute what the baseline computes (IronRuby.Tests, the differential matrices, ruby/spec language, self-verifying benchmarks) and slow nothing down. Util/perf has what they run: setup.sh (TruffleRuby and AWFY into ../ironruby-perf), worktree.sh (a sibling worktree with its own DLR copy and the native libraries), awfy.rb, micro.rb and micro-table.rb. The ledger starts with today's numbers. Co-Authored-By: Claude Fable 5.2 <[email protected]> Claude-Session: https://claude.ai/code/session_01KPwZf7WbR4bihMQfHYjG4L
…teral `s == "lit"' and `s != "lit"' made a method the JIT's pre-screen rejected (a String literal), so the method ran generically: a new String for the literal on every evaluation and a dynamic call of ==. In a specialized body the comparison is now JitRuntime.StringEqualsLiteral: for a receiver whose class is String itself it compares the contents with one frozen copy of the literal, which String#== never keeps, so nothing can tell it from a fresh String; anything else deopts, so only a pure body takes it. String#== (and #!=) must be the plain public library methods when compiling - no singleton == on any String, no refinement where the method was written - and the global method version guard keeps that true. micro.rb str== (def str_eq(s); s == "abc"; end), Release: 123 -> 35 ns/op (CRuby 4.0: 92). Checked against CRuby: a String subclass with its own ==, a singleton ==, a non-String receiver whose == sees a fresh unfrozen literal, String#== redefined before and after the method turned hot, a refinement of String#==. Co-Authored-By: Claude Fable 5.2 <[email protected]> Claude-Session: https://claude.ai/code/session_01KPwZf7WbR4bihMQfHYjG4L
… site A factory method - `def make(x) P.new(x, 0) end' - was rejected by the JIT's pre-screen (a method call), so it ran generically around the call of new. When `C.new(args)' (C a constant, up to three plain arguments, no block) is the last statement of a method body, the specialized body now makes the construction the rule of that call would make (RubyClass.TryGetObjectConstruction: allocate a plain instance, call C's Ruby initialize) through JitRuntime.Construct*, typed by arity so no argument array is made. C's new must resolve to Class#new, public, under the refinements active where the method was written (resolved as a site resolves it, so private_class_method moves the method version), and the global method version guard keeps that true while the body runs. Only as the last statement: initialize runs Ruby code that can change anything the body checked at its entry, and nothing of the body is left to run after it. Its effects are observable, so a body that can deopt is not specialized. The construction re-checks the class's version, and while :c_call is traced or once that moved, the call goes through an ordinary call site of new. micro.rb new2 (def newobj; P2.new(1, 2); end), Release: 134 -> 75-93 ns/op (CRuby 4.0: 87); new of a class with an empty-bodied initialize(a, b) 95 -> 42. Checked against CRuby and the unchanged build: initialize redefined after the method turned hot, a singleton new defined and removed, private_class_method :new, a refinement of new, a subclass, optional and rest parameters, initialize raising (message and backtrace are the unchanged build's), initialize defining methods. Co-Authored-By: Claude Fable 5.2 <[email protected]> Claude-Session: https://claude.ai/code/session_01KPwZf7WbR4bihMQfHYjG4L
A specialized body logs every Array or Hash element store so that a deopt after it can take the store back before the generic body runs the method again; a body that stores at all therefore makes its entry take the thread's undo log ([ThreadStatic]), mark it and release it in a finally on every call. The store helpers deopt only before they store, so the store that is the last statement of a method body has nothing after it that could deopt, and needs no log: it now passes none, and a method whose only store it is has no undo-log entry at all. Not in an outlined loop, whose iteration is re-run, nor in a body that calls itself, which runs nested under the caller's log (TryCompile compiles that one again with the store logged). Release, ns/op: `@arr[1] = 3' 63 -> 41, micro.rb's arr (`@arr[1] = @arr[2]') 67 -> 49 (CRuby 4.0: 38), `@h[1] = 3' 70 -> 47. Checked against CRuby and the unchanged build: a store growing the Array, a new Hash key, a frozen Array (FrozenError) after a logged Hash store in the same body, a new key while the Hash is iterated, a self-recursive body ending in a store. Co-Authored-By: Claude Fable 5.2 <[email protected]> Claude-Session: https://claude.ai/code/session_01KPwZf7WbR4bihMQfHYjG4L
A Ruby method whose body made any call - `def getter; a; end`, `def cmp(o); @x < o; end`, `def nilq(o); o.nil?; end` - allocated and initialized a RubyMethodScope on every call, because every call site takes the caller's scope as its first operand. Measured with variants of the method body, that scope was ~35 ns of the ~60 ns such a method cost over an empty one (`def glob; $g; end`, which needs the scope and makes no call, cost the same as `getter`; `IR_LIGHT_FRAMES=0` made the empty method cost the same too). Light frames already ran call-free bodies without a scope; this extends them to bodies that call. A call in a light frame now goes through a site bound with a light scope (RubyCallFlags.HasLightScope) that is handed the declaring scope. A rule that would read the scope - its value or its expression (CallArguments .MetaScope): a library method taking RubyScope (binding, block_given?, local_variables, eval, =~...), method_missing, a refined call, a protected method or a missing one on an explicit receiver (resolution looks for a public method, which every caller sees) - is not made; the site gets a rule returning RubyOps.LightScopeRequired instead, and the method then makes its scope on demand (as a TracePoint hook already does) and repeats the call, with the operands already evaluated, through the original site. Attribute readers and writers only take the scope for its runtime and use it as before. Like TruffleRuby's virtual frames, the scope exists only once something asks for it, and is then what it would have been at entry. A light body that makes calls also checks the stack at entry, so deep recursion stays a SystemStackError. IsScopeFree also lets through op-assignments, if/unless/?:, and/or/not over such calls, so `@x += @v; @x = 0 if @x > 500` is light. IR_LIGHT_CALLS=0 turns this off. Release net10.0, ns/call (baseline -> new, back to back, two runs): getter 72 -> 43, ivar_rw 91-94 -> 60-62, cmp 88 -> 53-60, nil? 86-89 -> 47-49, == 87-90 -> 49-52, abs 87-90 -> 58-62, empty 24-25 -> 25-27 (unchanged). AWFY us/iteration (base -> new, two runs): DeltaBlue 101713/98982 -> 97587/93094, Richards 630076/583535 -> 506349/553489, Json 137292/144179 -> 127692/125234, Bounce 150902/163183 -> 127487/138462, Towers 205420/207924 -> 170464/177203; geomean 0.872 / 0.891. IronRuby.Tests: all 1252 run; the one failure, Exception_CauseRaisedInClause1, fails the same on the unchanged tree in Release. jit, refinement, refinement-binding, raise, respond-to, prepend, ivar, error-message, full-message, set-backtrace, block-scope-reuse and callable-parameters matrices print what the unchanged build prints; scripts probing binding, local_variables, block_given?, eval, $~, __method__/__callee__ through an alias, protected/private/missing methods, method_missing, refinements, TracePoint :call, send/public_send and threads match CRuby 4.0. Co-Authored-By: Claude Fable 5.2 <[email protected]> Claude-Session: https://claude.ai/code/session_01KPwZf7WbR4bihMQfHYjG4L
A call site whose receivers are of several classes, each resolving the call to a different Ruby method or attr_reader/writer, gets a precompiled dispatcher per class, but the DLR keeps only one delegate as the site's target. Every call of a class other than the last one bound missed it and went through CallSite.Update: a matchmaker site allocated, the L1 rules tried one by one, the target swapped. That cost 20-60 ns a call on top of a monomorphic one. A dispatcher bound while the site's target is another dispatcher of the site's delegate type now keeps that target (MemberDispatcher.Next) and hands it the calls it does not serve, instead of calling the site's update. Each link still tests the receiver's class version exactly as before and the last one falls back to Update, so redefinition, singleton classes, prepend and visibility changes behave as they did; a stale link costs one compare. Chains stop at 8 links so a megamorphic site does not grow one without bound. Next is set before the delegate is published and never changed afterwards, so concurrent callers see a complete chain. Release, ns/op, master vs this (back to back), receivers of k classes: top-level o.foo: k=2 54 -> 39, k=3 76 -> 42, k=4 76 -> 46, k=6 93 -> 52 in a method: k=2 124 -> 112, k=4 143 -> 113, k=6 163 -> 128 micro.rb poly2: 126-139 -> 105; empty and nil? unchanged. The AWFY set (Bounce, Richards, Json, DeltaBlue, Towers) is unchanged within noise: Richards and Json have no class-polymorphic dispatcher sites, and DeltaBlue's are a small share of its time. IronRuby.Tests: all pass but Exception_CauseRaisedInClause1, which fails on master too. Co-Authored-By: Claude Fable 5.2 <[email protected]> Claude-Session: https://claude.ai/code/session_01KPwZf7WbR4bihMQfHYjG4L
…rame yielder
A call with a block literal allocated a Proc on every call, and the method's
yield allocated a BlockParam on every call too. `o.yielder { |x| x }` took
~88 ns against CRuby's 34; making the Proc alone cost ~20 ns of that (an
experiment that cached it per literal took noblk{} from 52 to 33 ns).
A light-frame method (MethodDefinition.IsLightFrameCandidate: no calls, no
&b, no scope) can do nothing with its block but yield to it, so a literal
block given to one is reachable afterwards only from the frame that made it,
unless one of the block's own calls left its scope behind. EnterLightMethod
now marks such a Proc reusable (Proc.ConvertAsLightFrame) when its literal
allows it (BlockDispatcher.ReusesProc: not a lambda, no nested block literal,
whose Proc would hold the scope without RubyScope.MarkCaptured, no compiled
TracePoint hooks, not eval code) and no TracePoint listens. Anything that may
expose the Proc clears the mark: RubyScope.MarkCaptured of a scope the block
ran in (walking up through block scopes), the light method making its scope
(CreateMethodScopeLazy), any other consumer (ConvertAsFrame and friends
rewrite the kind bits), and InitializeBlock before every call, including a
retried one.
The literal keeps its last Proc in a hidden variable of the enclosing frame
and InstantiateReusableBlock takes it again if it is still marked and its
call has returned (Proc.TryReuse); a variable of the frame rather than a
field of the dispatcher, so no other thread or frame can see it and nothing
is kept alive past the frame. The yield site takes the BlockParam of the
last call from the reusable Proc too (ReuseBfcForYield).
Release, ns/op, base vs new back to back (micro.rb):
yield (o.yielder { |x| x }) 89-91 -> 62-63
y1{} variant (m5.rb) 89-92 -> 59-60
Util/bench yield_0 0.45-0.47 -> 0.19-0.33 s
Util/bench yield_3 0.30-0.36 -> 0.13-0.22 s
each4, blockeach (Array#each, a C# iterator): unchanged
AWFY (Bounce Richards Json DeltaBlue Towers) unchanged within noise.
Checked: a differential script of break/next/redo/retry/return, bindings
and eval taken in the block, Fiber/Enumerator suspension inside it,
TracePoint, threads and procs kept with &b matches CRuby 4.0;
Util/block-scope-reuse-matrix.rb and Util/block-loop-matrix.rb match CRuby
with and without -X:NoJIT -X:NoOSR; spec/language (block yield proc break
return send def lambda redo retry next) and spec/core proc, binding,
tracepoint, enumerator and Kernel#block_given? give the same results as the
base build; IronRuby.Tests has only Exception_CauseRaisedInClause1 failing,
which fails without this change as well.
Co-Authored-By: Claude Fable 5.2 <[email protected]>
Claude-Session: https://claude.ai/code/session_01KPwZf7WbR4bihMQfHYjG4L
…ll needs one A call of a method with a body cost ~60 ns more than an empty one, the RubyMethodScope made on every call. Measured alone on a quiet machine against the unchanged build: getter 69 -> 40 ns, cmp 85 -> 52, nil? 85 -> 47, ivar_rw 87 -> 61; the five AWFY benchmarks 9% faster (geomean 0.906). Co-Authored-By: Claude Fable 5.2 <[email protected]> Claude-Session: https://claude.ai/code/session_01KPwZf7WbR4bihMQfHYjG4L
…final element store Measured alone against the unchanged build: str== 139 -> 63 ns, new2 125 -> 78, arr 66 -> 50. The AWFY benchmarks do not move: their hot methods make general calls, which the method JIT still declines. Co-Authored-By: Claude Fable 5.2 <[email protected]> Claude-Session: https://claude.ai/code/session_01KPwZf7WbR4bihMQfHYjG4L
…e cache A site that saw several receiver classes went through the DLR's update path on every change of class. Measured alone against the unchanged build: poly2 121 -> 102 ns (top-level sites with 2-6 classes 25-45% faster by the author's measurements). The AWFY benchmarks do not move. Co-Authored-By: Claude Fable 5.2 <[email protected]> Claude-Session: https://claude.ai/code/session_01KPwZf7WbR4bihMQfHYjG4L
…and BlockParam Measured alone against the unchanged build: yield 87 -> 62 ns. Blocks given to C# iterators (each, times) are unchanged, and so are the AWFY benchmarks. Co-Authored-By: Claude Fable 5.2 <[email protected]> Claude-Session: https://claude.ai/code/session_01KPwZf7WbR4bihMQfHYjG4L
… paths IronRuby/CRuby on the five AWFY benchmarks goes from 1.86 to 1.61 (geomean), and the per-operation ratios for a method with a body from 2.7-3.6 to 1.7-2.0. The ledger now has what landed, what each experiment learned about where the rest of the time goes, and what is untried for each remaining gap, which is what /perf-step reads next. Util/perf/hot-shapes-matrix.rb runs the shapes the merges accelerate hot, with their invalidations (redefinition, a singleton method, String#== replaced, initialize redefined, a frozen Array, a block kept as a proc) in the middle. CRuby 4.0, the merged build and the merged build with -X:NoJIT -X:NoOSR print the same. perf-gate names it. Co-Authored-By: Claude Fable 5.2 <[email protected]> Claude-Session: https://claude.ai/code/session_01KPwZf7WbR4bihMQfHYjG4L
…and while loops Most hot AWFY methods that still made a RubyMethodScope per call were refused by the cheap filter (IsLightFrameCandidate), not by anything their transformed body did with the scope. Counted with IR_LIGHT_FRAMES=verbose over Richards, DeltaBlue, Json, Bounce and Towers, the leading reasons in the benchmarks' own methods were string and symbol literals in calls (`"\n" == @current`, `kind == :x`), `o.x = v` and `a[i] = v`, `while` loops (Richards#append/schedule, Json#read_number...), string interpolation and case/when. The filter now lets these through, and the rewriter, which still checks every use of the scope, accepts the two that loops make: - EnterLoop/LeaveLoop set the scope's InLoop flag (for an eval'd break or next). In a light frame they set it on the scope if one has been made, and in a frame local that a scope made later inside the loop takes (RubyOps.LightScopeInLoop). - An OSR site hands its specialized copy the scope: that operand is now the scope made on demand, as a TracePoint hook's is, once per loop entry that gets that far. Both the filter and the rewriter give up on a body nested too deep for the stack (DeepNesting1's `def f = [[[...]]]` a thousand deep overflowed in the rewriter). AWFY (us/iteration, 12 s each, base then new, two runs back to back on a shared box): DeltaBlue 72956 -> 61464, 125989 -> 76856 Richards 544523 -> 500173, 686076 -> 531258 Json 116082 -> 95983, 125059 -> 130636 Bounce 124204 -> 126377, 100003 -> 104788 Towers 168653 -> 128889, 220691 -> 175397 geomean new/base 0.870, 0.837 Micro: str== (`def str_eq(s); s == "abc"; end`) 70 -> 52 ns, 68 -> 51; others within noise. hot-shapes-matrix gains the new shapes (with to_s, Integer#===, a constant and a called method changed mid-run, binding/local_variables inside a loop, an OSR'd loop) and prints the same on CRuby, this build and -X:NoJIT -X:NoOSR; jit, raise and refinement-binding matrices unchanged from the base build; IronRuby.Tests only the known Exception_CauseRaisedInClause1; ruby/spec language 2935 examples, 0 failures, 1 error. Co-Authored-By: Claude Fable 5.2 <[email protected]> Claude-Session: https://claude.ai/code/session_01KPwZf7WbR4bihMQfHYjG4L
… that only yield fd94bce made a block literal's Proc (and the BlockParam of its yields) again for the next call from the same frame, but only for light-frame Ruby yielders. A literal given to a C# iterator - Array#each, Integer#times, Range#each - still allocated a Proc, a BlockParam, and on the first yield of each call a fresh block scope, since the scope the last call parked lives on the BlockParam. A library method marked [BlockNotKept] does nothing with its BlockParam but yield to it: IListOps each/map/collect/select/filter/each_index, Integer#times, Range#each, Hash#each/each_pair. For those the call site (rule and LibraryCallPlan) makes the BlockParam with RubyOps.CreateBfcForBlockNotKept, which marks the literal reusable as EnterLightMethod does (Proc.ConvertAsLightFrame: same ReusesProc/TracePoint rules, the same un-marking by MarkCaptured, InitializeBlock and other converters) and, for a Proc made again, hands back the last call's BlockParam reset for the next yield, with the block scope it parked. The BlockParam is kept in Proc.YieldBlockParam; a yield-kind and a library one are told apart by IsLibProcConverter. The reuse is per frame (the literal's hidden #proc variable), so it pays off for an iterator called in a loop of one frame. Release, ns per outer iteration, base vs new, IR_LIGHT_CALLS=0 on both to isolate this change, two runs: while ...; a.each { |e| e }; end 99-103 -> 81-85 while ...; 4.times { |e| s += e }; end 257-294 -> 189-200 Allocation for the first: 144 -> 24 bytes per iteration. Checked: IronRuby.Tests (only Exception_CauseRaisedInClause1 fails, as on the base), spec/language 2935 examples 0 failures 1 error as the base; spec/core proc, enumerator, binding, array/each, range/each, integer/times, hash/each, kernel/block_given as the base; hot-shapes, block-loop, block-scope-reuse (+blockpass, race) and osr-array matrices identical to CRuby with and without -X:NoJIT -X:NoOSR. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01KPwZf7WbR4bihMQfHYjG4L
…e until a call needs one A block whose body made a call, read or wrote an enclosing local (`s += e`), an instance variable or yielded made a RubyBlockScope on every call (or took the parked one back), which cost 25-30 ns a yield over a scope-free block. c9a17e2 made such method bodies scope-free (MethodDefinition.LightFrameRewriter: calls through sites with a light scope that answer RubyOps.LightScopeRequired when the bound method would read the scope, which then is made on demand and the call repeated). Blocks now use the same rewriter: BlockDefinition.IsLightCallBody filters with MethodDefinition.IsScopeFree, and the light sites, instance variable and constant helpers are handed the scope the block was defined in (its Proc's LocalScope, which is the parent any block scope has). The enclosing scopes' locals are read from that scope at entry (ScopeBuilder.CreateScopeWithParent) instead of from the block's own. A yield in the block finds the method's block from that scope too (GetMethodBlockParameter[Self]; BlockYield does not use its scope). Any other use of the scope still makes the rewrite fail and the block compiles as before; IR_LIGHT_CALLS=0 turns this off with the method half. Release, back to back with the base (micro lines noisy, load 4-9): each4 (a.each { |e| s += e } in a method) 306-360 -> 213-228 ns my lines: times4 270 -> 208, range4 290 -> 229, blockeach 68 -> 52 allocation `a.each { |b| s += 1 if b.odd? }` 640 -> 432 B/call, som Vector#each shape (Range#each { |i| yield v[i] }) 1688 -> 968 B/call AWFY us/iteration, five runs, min base -> min new: DeltaBlue 77794 -> 72023 (new faster in all five, 0.58-0.93), Richards 425042 -> 419829, Json 112504 -> 107597, Bounce 98693 -> 105989, Towers 153156 -> 145949 (the last four within the run-to-run noise; Bounce's 100-element each is outlined by BlockLoopSite anyway). Checked: IronRuby.Tests only Exception_CauseRaisedInClause1 failing (as base), spec/language 2935 examples 0 failures 1 error, spec/core proc, enumerator, binding, block_given?, array/range/hash each, times as the base; hot-shapes-matrix (new cases: a called method switching to binding, method_missing, protected calls, bindings and procs kept from the blocks, yield/break/return through them, threads) plus block-loop, block-scope-reuse (+blockpass, race), osr-array matrices identical on CRuby, the new build and -X:NoJIT -X:NoOSR. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01KPwZf7WbR4bihMQfHYjG4L
…e shapes Both branches changed MethodDefinition.LightFrameRewriter: perf/lf gave it the frame's #in-loop flag (a `while' in a light frame), perf/blk made it and IsScopeFree internal so that a block's body can use them. A light block therefore accepts what a light method now does (loops, case/when, attribute and element assignment, string and symbol literals), and gets its own #in-loop variable; a block scope made on demand inside the loop takes the flag through RubyOps.LightBlockScopeInLoop, as a method scope does through LightScopeInLoop. Util/perf/hot-shapes-matrix.rb gains blocks of those shapes (break, next, return, a binding and a proc kept mid-run, a method and Integer#< redefined, a frozen Array, threads): CRuby 4.0, this build and this build with -X:NoJIT -X:NoOSR print the same. Co-Authored-By: Claude Fable 5.2 <[email protected]> Claude-Session: https://claude.ai/code/session_01KPwZf7WbR4bihMQfHYjG4L
A profile of DeltaBlue, Richards and Json in steady state put about 10% of self time in RubyOps.GetInstanceVariable/SetInstanceVariable and the JIT's GetIVar/SetIVar: the cached case was a shape compare and a slot load, but behind a call the .NET JIT would not inline (the methods also carried the module, Ractor and slow paths). The cached case is now a small [AggressiveInlining] method - RubyOps.TryReadCached/TryWriteCached: `self is RubyObject`, load the instance data, its slot array, the site's entry, acquire-read element 0, compare, load or store the slot (a store re-reads element 0, as RubyInstanceData's protocol requires) - and everything else goes to the old code, now out of line. GetInstanceVariable, SetInstanceVariable, JitRuntime.GetIVar/SetIVar and the attr_reader/attr_writer dispatchers (for an exact RubyObject) use it. The protocol is unchanged, so it is as safe without a GVL as the code it replaces. Measured (Release, net10.0, base = parent commit): 40 `@x` reads in a method 130 -> 78 ns per call; GetInstanceVariable (5.4% self in DeltaBlue) gone from the profile; AWFY back to back, 4 shared cores, two runs, geomean new/base 0.984 and 0.932 (Json, Bounce, Towers faster in both). ivar-matrix, jit-matrix and hot-shapes-matrix (with a new section changing a hot site's shape mid-run) identical on CRuby, this build and -X:NoJIT -X:NoOSR; ivar-stress OK four times; IronRuby.Tests only Exception_CauseRaisedInClause1; spec/language 0 failures 1 error; core kernel/basicobject/module as the base. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01KPwZf7WbR4bihMQfHYjG4L
…rite, inline Both sides appended cases to Util/perf/hot-shapes-matrix.rb; both are kept. Co-Authored-By: Claude Fable 5.2 <[email protected]> Claude-Session: https://claude.ai/code/session_01KPwZf7WbR4bihMQfHYjG4L
The first round of speed work was guided by per-operation timings, and three of its four changes moved no benchmark. profile.sh records a benchmark's steady state with perf (with the two DOTNET_ settings that make JIT frames resolve) and profile-agg.rb prints self and inclusive time per frame, or the callers of the frames a regexp matches. dotnet-trace is not used for this: its sampler stops threads at GC safepoints and so blames allocation sites. Compiled Ruby method bodies still show as [unknown] (about 40% of samples); the header says why, as far as is known. Co-Authored-By: Claude Fable 5.2 <[email protected]> Claude-Session: https://claude.ai/code/session_01KPwZf7WbR4bihMQfHYjG4L
… variable access Three experiments of the second round, measured alone against 4c78e82 on a quiet machine (AWFY geomean of Bounce, Richards, Json, DeltaBlue and Towers, two runs each): - perf/lf (0b3043d): light frames also take attribute and element assignment, string and symbol literals, interpolation, case/when and while loops - the reasons most hot methods of the benchmarks still made a scope. - perf/blk (baaa807, 96881ad): the Proc and BlockParam of a block literal are reused for library iterators that only yield ([BlockNotKept]), and a block that makes calls or uses outer locals runs without its scope until a call needs it. each4 281 -> 203 ns; AWFY 0.975, DeltaBlue 10% faster. - perf/prof (1ee9cdc): the cached instance variable read and write are inlined into compiled code and the attr dispatchers. AWFY 0.982. perf/lf and perf/blk together: AWFY 0.871 and 0.862. The merged tree gives the baseline's results on IronRuby.Tests (the one Release failure, Exception_CauseRaisedInClause1, is the baseline's), on ruby/spec language and nineteen core directories (17123 examples, the same 2 failures and 18 errors; the expectation count differs only in core/thread, where it varies from run to run on the baseline too), and matches CRuby 4.0 on Util/perf/hot-shapes-matrix.rb with the JIT on and off. Co-Authored-By: Claude Fable 5.2 <[email protected]> Claude-Session: https://claude.ai/code/session_01KPwZf7WbR4bihMQfHYjG4L
IronRuby/CRuby on the five AWFY benchmarks is 1.36 (1.61 after round one, 1.86 at the start). The ledger records what the three merged experiments did, the two that were rejected, the profile before and after, and the gaps re-ranked from the profile: calls of core methods from light frames now go through generic DLR rules (20% of DeltaBlue), which is the next thing to try. profile.sh took /usr/bin/perf, a wrapper that refuses to run without a build for the running kernel; it now prefers the binary under /usr/lib/linux-tools-*. Co-Authored-By: Claude Fable 5.2 <[email protected]> Claude-Session: https://claude.ai/code/session_01KPwZf7WbR4bihMQfHYjG4L
Co-Authored-By: Claude Fable 5.2 <[email protected]> Claude-Session: https://claude.ai/code/session_01KPwZf7WbR4bihMQfHYjG4L
About 40% of a perf profile's samples (Util/perf/profile.sh) were [unknown]: the compiled Ruby method and block bodies. Their DynamicMethod names carried U+2111 U+211C and U+2236 (RubyStackTraceBuilder.EncodeMethodName), and the runtime's perf-map writer (DOTNET_PerfMapEnabled) damages any line whose name is not ASCII: in /tmp/perf-<pid>.map such a line is cut at "[O", starts with garbage instead of its address, or is written as UTF-16, so perf resolves none of them. The encoded name is now "IR|label|line|id|file", with '|', '%', control and non-ASCII characters of the label and the file escaped as %XXXX (a UTF-16 code unit) and unescaped by TryParseRubyMethodName, the only parser. Backtraces, caller and caller_locations are unchanged (checked against the unchanged build with non-ASCII method, class and directory names, an operator method named | and %, and a singleton class body). profile-agg.rb shows a body as "label (file:line)", merging a method's compiled instances and tiers, shortens CLR frames to Type::Method, and takes 'self:REGEX' to list callers of the leaf frames only (which Ruby methods the shared-name CallSite.Target rules run under). Richards: [unknown] 3.6% of the samples, from about 45%. Co-Authored-By: Claude Fable 5.2 <[email protected]> Claude-Session: https://claude.ai/code/session_01KPwZf7WbR4bihMQfHYjG4L
Protocols.RespondTo(RespondToStorage, ...) interned the method name on every call (RubyContext.EncodeIdentifier -> CreateSymbol, a dictionary lookup under the symbol table). Array#== asks respond_to?(:to_ary) of every non-array operand, so `@storage == nil` in SOM's Vector#append made CreateSymbol 1.1% of DeltaBlue's and 0.7% of Json's self time (the named profile's callers of CreateSymbol). The storage, one per library method and runtime, now keeps the last name and its symbol in one field, so threads racing on it see a matching pair. Array#== nil, 3M calls, -X:NoJIT: 64-90 ns -> 55-58 ns per call (noisy shared machine, alternating runs). hot-shapes-matrix gets a case with to_ary and respond_to? defined on the operand's class and NilClass#to_ary added mid-run; identical on CRuby, this build and -X:NoJIT -X:NoOSR. Co-Authored-By: Claude Fable 5.2 <[email protected]> Claude-Session: https://claude.ai/code/session_01KPwZf7WbR4bihMQfHYjG4L
The named profile showed small helpers running as calls from compiled code: RubyOps.IsTrue/IsFalse from method bodies (1.4-1.5% self of DeltaBlue, Richards and Json; DOTNET_JitDisasm of a body shows the call left in), and RubyOps.GetInstanceVariable (3.4% DeltaBlue, 4.1% Richards) and SetAttribute (1.2%, 2.3%) from attr_reader/attr_writer rules. The DLR compiles a rule with tail calls (CallSiteBinder.Stitch) and the JIT never inlines the callee of an explicit tail call, so the rule jumped to the helper whose cached read was written to be inlined. IsTrue, IsFalse and SetAttribute are AggressiveInlining, and the accessor rules store the helper's result in a local, which takes the call out of tail position. After: none of the four appears in the profiles' self time (CallSite.Target absorbs part of it). task-clock of a fixed harness run, three alternating pairs each, base -> new: DeltaBlue 13.56 s -> 12.96 s, Richards 18.62 s -> 18.06 s, Json 9.11 s -> 8.87 s; awfy.rb timings are within the noise of the shared machine. hot-shapes-matrix: attribute calls served by rules (send, public_send, a splat) with the reader redefined as a method, a singleton reader added and removed and the variable removed mid-run; identical on CRuby, this build and -X:NoJIT -X:NoOSR. Co-Authored-By: Claude Fable 5.2 <[email protected]> Claude-Session: https://claude.ai/code/session_01KPwZf7WbR4bihMQfHYjG4L
IR_LIGHT_FRAMES=verbose named only the candidates whose rewritten body needed its scope; a method IsLightFrameCandidate refused went unlisted. IR_LIGHT_FRAMES=why also prints, for every method compiled with a scope, the reason: not allowed, refinements, profiler, trace, eval, closures, optional/splat/keyword parameters, rescue/ensure, or the first statement that is not scope-free with its node type and line. On the AWFY benchmarks it lists 37 methods: 18 stop at a MethodCall with a block literal, 6 at super, 5 at an if, 3 at a while (block literals inside), 3 at assignments, 2 at optional parameters. Co-Authored-By: Claude Fable 5.2 <[email protected]> Claude-Session: https://claude.ai/code/session_01KPwZf7WbR4bihMQfHYjG4L
…ted methods Adds a shape for calls made from light frames (RubyCallFlags.HasLightScope): Integer#< and NilClass#nil? redefined and restored while the site is hot, a receiver that cycles through Integer/Float/nil/String/a user object, private and protected targets on an explicit receiver, a target redefined mid-run to use block_given?, binding, __method__ and caller, and a singleton method added later. CRuby 4.0, IronRuby and IronRuby -X:NoJIT -X:NoOSR print the same. It was written to check an attempt to let the precompiled dispatchers serve such sites, which did not measurably help and was not kept. Co-Authored-By: Claude Fable 5.2 <[email protected]> Claude-Session: https://claude.ai/code/session_01KPwZf7WbR4bihMQfHYjG4L
Round three. Measured against 3237c08 on a quiet machine, three AWFY runs (Bounce, Richards, Json, DeltaBlue, Towers): geomean 0.956, 0.953, 0.967. - 88cc224: compiled Ruby bodies get ASCII names (IR|label|line|id|file). The runtime's perf-map writer damaged every line with a non-ASCII name, which left 45% of a profile's samples unattributed; Richards now has under 3% unknown. Backtraces are unchanged (raise-, full-message- and error-message-matrix print what the baseline prints). profile-agg.rb shows a body as label (file:line) and can list the callers of matching leaf frames. - 3c938e1: RespondToStorage caches the symbol it asks about; Array#== interned :to_ary on every call (1% of DeltaBlue). - 7c7ec90: IsTrue, IsFalse and SetAttribute are inlined, and the attribute rules' helper call is out of tail position, where the JIT never inlines. - f04fe5a: IR_LIGHT_FRAMES=why says why a method is not a light frame. - hot-shapes-matrix cases for light-scope calls of core, Ruby and private/protected methods. Two experiments of the round are not here: parked method scopes (no benchmark moved, and a reused scope is a risk) and identity calls in the method JIT (string-literal == got slower). Util/perf/LEDGER.md has both. The merged tree gives the baseline's results on IronRuby.Tests and on ruby/spec language plus twenty core directories (17025 examples, 78747 expectations, 2 failures, 18 errors on both), and matches CRuby 4.0 on Util/perf/hot-shapes-matrix.rb with the JIT on and off. Co-Authored-By: Claude Fable 5.2 <[email protected]> Claude-Session: https://claude.ai/code/session_01KPwZf7WbR4bihMQfHYjG4L
IronRuby/CRuby on the five AWFY benchmarks is 1.32 (1.36, 1.61, 1.86 before). The ledger has the three changes that landed, the four that were tried and not kept with their numbers, and what they established about the largest remaining gap: a call of a core method from a method costs what its light frame costs, not what its rule costs, so the next things to try are a cheaper light frame and instance-variable operands in the method JIT. Co-Authored-By: Claude Fable 5.2 <[email protected]> Claude-Session: https://claude.ai/code/session_01KPwZf7WbR4bihMQfHYjG4L
The method JIT's pre-screen refused any instance variable used as an operand of an operator (`@last_idx - @first_idx', `@a < o'), so methods such as Vector#size and #empty? stayed generic. Outlined loops already type such reads from their live self (NumericIVar); a method now does the same with the receiver of the call that turned it hot, which the stub holds only while it compiles (ReceiverHints.SelfSample). An Integer or Float there is read through GuardInt/GuardLong/GuardDouble, which unbox the one value read and deopt when it is anything else, so another thread changing the variable between read and use cannot slip past; an unprofiled variable next to a number is speculated as an element read is. A read is not observable, so a body that only reads stays restartable; one that also writes an ivar is still declined as before. IR_JIT_VERBOSE now also names each screen-rejected method and the call or variable that rejected it, which is how the benchmarks' hot methods were found. Measured (best of 5 x 2M calls, alternating, ns/call, base -> new): `@last - @FIRST' 35/38 -> 36/33, `@last == @FIRST' 40/43 -> 29/38, micro.rb cmp (`@x < o') 42/56/42 -> 27/35/27; Vector#size and #empty? now specialize in DeltaBlue and Json with no deopts. DeltaBlue whole is neutral within noise. Util/jit-matrix.rb gains the shapes (Integer, overflow, Bignum, Float, nil, String, zero divisor, an operator redefined and restored, frozen receiver, subclass override): identical on CRuby, JIT and -X:NoJIT. Co-Authored-By: Claude Fable 5.2 <[email protected]> Claude-Session: https://claude.ai/code/session_01KPwZf7WbR4bihMQfHYjG4L
…ment stays on the yield
The floor per block body had two steps: six calls or more entered the copy
for a run of one, fewer needed five. A body between the two lost on a single
element: `a.each { |x| s += x * 3 + x * 5 - x / 2 + (x & 7) }' (eight calls)
over one element took 140, 153 and 161 ns per call in the copy against 96, 99
and 107 through the yield, three alternating processes each; over two elements
the two were level, and from four on the copy won (182 against 300).
An entry costs about 45 ns more than a yield, and a call the copy types
saves 4 or 5 ns, so one iteration pays for the entry from about twelve calls
on. Floor is now 1 for twelve calls or more (NBody's inner block has about
47), 2 for six to eleven, 5 below that.
Measured, three alternating processes per cell, ns per call, base then new:
eight-call integer body over 1 element 164/111/120 vs 104/97/106, over 2
161/151/164 vs 163/165/162, over 3 223/225/230 vs 182/178/172; ten-call
attribute body over 1 137/143/205 vs 140/148/140, over 2 288/292/260 vs
222/208/184. NBody, median of the last half of 16 iterations, four alternating
processes: 1918, 1879, 1900, 1972 ms before the series, 1315, 1325, 1281,
1411 with it.
Co-Authored-By: Claude Fable 5.2 <[email protected]>
Claude-Session: https://claude.ai/code/session_013PQjty6LpWT6taQu2sGkNx
# Conflicts: # Util/perf/micro.rb
…uld be inlined The screen let a method calling another be wrapped whenever the callee passed JitScreen.CanEverCompile, or the receiver was an instance variable. Many such callees can never be Inlinable (Richards' `append' has a while loop, an attribute write and a constant), so their callers were wrapped, profiled and declined, and a method wrapped and declined stays slower than one never wrapped: Richards was about 4% slower with nothing new compiled. JitInlineShape.IsInlinableShape now asks of the callee's syntax what JitCode.Inlinable will ask of its typed body: no loop, no assignment but to a local, no constant, yield or super, no call but an operator or an attribute read, only mandatory parameters. A call on an instance variable is no longer admitted regardless: it bought DeltaBlue's choose_method and cost seven methods wrapped and declined there, and one each in Json and CD; DeltaBlue measured the same either way (five alternating processes, medians 51.5 vs 52.1 ms). New `declined' lines against the baseline, all thirteen benchmarks: Json's HashIndexTable#hash_slot_for only (its callee string_hash is declined on the type of `s.size', which the syntax cannot see), while JsonArray#size moves from declined to specialized. Richards, List, Towers and the others: JIT decisions identical to the baseline. inline-matrix (19 cases) as CRuby and -X:NoJIT -X:NoOSR; hot-shapes and jit matrices as the baseline; IronRuby.Tests passes but the known Release Exception_CauseRaisedInClause1. micro.rb takes several shape names, as on the combined tree. Co-Authored-By: Claude Fable 5.2 <[email protected]> Claude-Session: https://claude.ai/code/session_013PQjty6LpWT6taQu2sGkNx
# Conflicts: # Util/perf/micro.rb
… wall clock will not hold still awfy.rb's steady-state medians moved by 30% between two runs of one build on a shared host (DeltaBlue 40 and 54 ms, Towers 79 and 105 ms, nothing else running), which no comparison survives. This runs a fixed number of iterations of each benchmark in a fresh process and reports the least user + system CPU time of N rounds, the trees in turn; the baseline is meant to be given twice, so that the distance between its two columns says what a difference has to exceed. Its header says what it does not measure. Co-Authored-By: Claude Fable 5.2 <[email protected]> Claude-Session: https://claude.ai/code/session_01KPwZf7WbR4bihMQfHYjG4L
BasicObject#!= was a rule that called a helper, which called == through a second site and rule: three frames for one comparison (about 3.6% of Richards' samples). Where != is the stock method and == a builtin that runs no Ruby code - identity for nil, true, false and a plain object, Integer#== for two Integers, String#== for two Strings - the site now binds one negated compare (05a31f0). Measured against the tree before, on shapes the method JIT does not compile, three alternating rounds: nil != o 44-48 -> 30-38 ns, o != x 37-49 -> 32-41, a chain of three 145-175 -> 129-142; String and Integer operands within noise. Least CPU time of a fixed run of the five AWFY benchmarks (Util/perf/cputime.rb, five rounds): 0.968 of the baseline, whose own second column was 0.996. Wall-clock medians were unusable on the day (the baseline alone moved by 30% between runs). The branch passed the full five-suite sweep (32285 examples, nothing outside the list of known failures), IronRuby.Tests, and the matrices with new cases for == redefined in a class, on one object, on one String, by a prepended module, made private and undefined. What its table of the hottest rules showed is in the ledger: rule bodies are 20-35 instructions each and already close to minimal; they are a quarter of the run because there are so many dynamic calls. Co-Authored-By: Claude Fable 5.2 <[email protected]> Claude-Session: https://claude.ai/code/session_01KPwZf7WbR4bihMQfHYjG4L
A table of one-character strings (15 kinds of source, 13 ways of taking one character, 19 mutators, each checked against a sibling slice, a copy and a fresh slice), a thread section, and stubs in their settled states (a keyword method, initialize, a method redefined on one thread while four call it). The hunt found no fault in the shared string contents or in the stub targets; these are the cases it ran. Co-Authored-By: Claude Fable 5.2 <[email protected]> Claude-Session: https://claude.ai/code/session_01KPwZf7WbR4bihMQfHYjG4L
…loops, small callees inlined, Range literals Numbers on the code of 5589688, all thirteen benchmarks: IronRuby/CRuby 0.785 (0.800 and 0.768 in the two runs before), NBody 0.78 from 1.08-1.21, CD 0.69, Json's allocation 35.9 -> 30.7 MB, NBody's 2892 -> 1364 MB. Against the tree of round eight, both column orders on a quiet machine: geomean 0.970 and 0.941, nothing slower in both. The ledger records the three experiments that landed, the versions of them that did not and why (a floor of one for every block made light short runs 1.5 to 2 times slower; a screen that admitted every call wrapped methods it then declined), what the gate caught before the merge, two gaps closed and two new ones: calling an iterator at all costs twice what it does in CRuby (`any?` six times), and DeltaBlue's `Vector#each`. perf-gate gains what that taught: a change to when a compiled path is entered is measured at the lengths the old rule kept out, a screen change by the whole specialized/rejected/screen-rejected line of every benchmark, and a probe's threads use names of their own. Co-Authored-By: Claude Fable 5.2 <[email protected]> Claude-Session: https://claude.ai/code/session_013PQjty6LpWT6taQu2sGkNx
#215 gained seven commits after it was last merged: `a != b` bound as the negated builtin `==` (05a31f0), the full spec sweep as the gate's spec step, Util/perf/cputime.rb, and matrix cases. The conflicts were all two sides appending in one place: jit-matrix and hot-shapes-matrix keep both sets of cases, the ledger keeps #215's note on the sweep and this branch's "Caught by the gate" sections, and perf-gate takes #215's sweep step with the note on running mspec by hand kept after it. The ledger's gap 10 says that #215's `!=` binding has landed. Co-Authored-By: Claude Fable 5.2 <[email protected]> Claude-Session: https://claude.ai/code/session_013PQjty6LpWT6taQu2sGkNx
After the merge of #215 through 9b2936f: IronRuby.Tests on net10.0 and net11.0, the differential matrices with #215's new cases, and the full five-suite spec sweep (32,285 examples, nothing that the known-failures list does not name) all as before. Co-Authored-By: Claude Fable 5.2 <[email protected]> Claude-Session: https://claude.ai/code/session_013PQjty6LpWT6taQu2sGkNx
Most of DeltaBlue's 20,592 Vector#each calls per iteration run over one or two elements, so a change to how that iterator or its yield is run must be measured at those lengths too, not only on veach4 and veach100. Co-Authored-By: Claude Fable 5.2 <[email protected]> Claude-Session: https://claude.ai/code/session_013PQjty6LpWT6taQu2sGkNx
[1].any? { |x| ... } cost 420-520 ns where CRuby takes 67-154: the prelude
(ruby4.rb) wrapped Enumerable's four predicates in Ruby methods taking *args
and &block, so every call, block form included, paid for a splat Array, a
Proc for the block, a call of __check_pattern_args__ and a second call of the
aliased C# method with &block. The C# block form itself walks an Array
directly.
The pattern form is now a C# overload of each of the four (Enumerable.cs), and
the prelude wrappers are gone, so the block form is one library call again.
The overload warns "given block not used" at the calling line as before, and
calls pattern === item through a library site, as MRI's rb_funcall does: a
private #=== now answers, where the wrapper raised NoMethodError. An Array is
walked directly for the pattern form too, as rb_ary_any_p does: an Array
subclass's #each is no longer called (CRuby does not call it).
Micro (Util/perf/micro.rb, ns per call, base -> new): s_any1 440/432 ->
198/193, s_any2 504/514 -> 219/228, s_any4 515/534 -> 256/259; the other
micro shapes unchanged within noise. Bytes per AWFY iteration unchanged
(no benchmark calls these). ruby/spec core/array and core/enumerable
any/all/none/one and core/hash/any pass as before; hot-shapes, jit,
block-loop, enum, enumerable2, error-message and refinement matrices print
what the baseline prints; a hot differential script (break/next/redo/return,
raise, recursion, &b, binding, lambda and Method blocks, Symbol#to_proc,
destructuring and it/_1 blocks, frozen and growing receivers, two threads,
Array#any? redefined and removed mid-run) prints what CRuby 4.0.9 prints,
with the JIT and OSR on and off. Enumerable_PredicatePattern1 is new;
Enumerable_PatternUnusedBlockWarning1 now counts the three warnings, which
the test host takes into its error sink rather than $stderr.
Co-Authored-By: Claude Fable 5.2 <[email protected]>
Claude-Session: https://claude.ai/code/session_013PQjty6LpWT6taQu2sGkNx
A method that walks a linked list keeps its cursor in a local assigned
twice: from a parameter before the loop and from the cursor's own attr
read inside it (`xt = x; ... xt = xt.nxt`). TrySampleOfLocal only
sampled locals assigned exactly once, so the read had no profiled
receiver, EmitMethodAttrRead declined it ("call: next/0") and the whole
method stayed generic. List#is_shorter_than, List's hot method, and
CD's tree_minimum were declined for exactly this.
A local assigned more than once whose first assignment is from another
local of the method now samples to what that local samples to. It is a
profile like the rest of TrySample: the compiled read still checks the
receiver's class and the method version and deopts on anything else.
List and CD now specialize one more method each; the other eleven AWFY
benchmarks' [jit] lines are unchanged. List 74.4/74.6/76.7 ms -> 44.9/
49.0/44.2 ms (awfy.rb, base and new in the same run, three runs), and
8.16 MB -> 0.59 MB allocated per iteration. A micro of the shape
(is_shorter_than over lists of 4 and 6) 126/135/134 ns -> 84/84/100 ns.
Checks: a jit-matrix case for the shape (another class, a singleton
reader, false and an Integer in the list, the reader redefined, made
private, restored and removed), identical to CRuby with the JIT on and
off; jit-matrix and hot-shapes-matrix identical to CRuby and the
baseline; List, CD and Richards with -X:NoJIT -X:NoOSR verify;
IronRuby.Tests in Release fails only Exception_CauseRaisedInClause1, as
on the baseline.
Co-Authored-By: Claude Fable 5.2 <[email protected]>
Claude-Session: https://claude.ai/code/session_013PQjty6LpWT6taQu2sGkNx
MyArr[1, 2].one? { |x| x } and MyArr[1, 2].one? called an Array subclass's
#each, where CRuby's rb_ary_one_p walks the Array and gives false. The block
and bare forms of Enumerable#one? now walk a RubyArray directly, as all?,
any? and none? already do: the length re-read every iteration, each element
yielded once, a break from the block returned as the result.
Checked against CRuby 4.0.9: a subclass with a raising #each (block, bare and
pattern forms), break, the receiver grown and shrunk by the block, an
exception rescued inside the block. Enumerable_PredicatePattern1 gains these
cases; IronRuby.Tests (Release) fails only Exception_CauseRaisedInClause1,
as the baseline does.
Co-Authored-By: Claude Fable 5.2 <[email protected]>
Claude-Session: https://claude.ai/code/session_013PQjty6LpWT6taQu2sGkNx
…vel deep CD's RedBlackTree#find_node (every voxel lookup and every `seen.get') stayed generic: the screen took `key.compare_to(current.key)' only of a method its own class defines, and only of a leaf, while Vector2D#compare_to calls compare_numbers; `current', walked down the tree from @root, had no sample; and `key' is a CallSign in one tree and a Vector2D in another, so a body inlining one class's compare_to deopted on every call of the other and was retired. - The screen takes a call on another object of a name some top-level class defines as an inlinable method, and such a callee may itself call, on self, a leaf (compare_to -> compare_numbers): one level, and only for a call on another object, since for self-calls it wrapped Json's HashIndexTable#add and #get, which were then declined. - TrySampleOfLocal's first-assignment rule (perf/rich) takes an instance variable too: `current = @root' samples what self's @root holds; each attr read of `current' still checks its receiver's class. - The profile records the first two Ruby classes of each argument. A call on a parameter seen with two inlines both callees under a class test (a third class deopts); if their types differ it inlines the sampled one. A body that inlined one class on a parameter and then deopts too often goes back to profiling (at most twice) instead of being retired, so a second class seen later is compiled in. The guards stay the call site's: the receiver's class where the call is, the global method version at the entry, public only, no refinement active, the callee's own pinned class and parameter types. find_node micro (lookups in a 300-key tree of Vector2D-like keys): 961/987/ 831 -> 563/458/439 ns per lookup (CRuby 1527). CD profile: RedBlackTree#get inclusive 8.8% -> 4.5%, CallSite.Target self 25.3% -> 21.6%; CD time in eight alternating processes level (medians 598 and 598 ms, spread 570-640 on a loaded machine): unproven. DeltaBlue specializes UnaryConstraint#choose_method, medians 63.3 -> 59.1 ms. Bytes per iteration within 1.2% on all thirteen. [jit] lines: only CD (+find_node) and DeltaBlue (+choose_method) change; no method newly declined. Checks: inline-matrix (31 new tree_ cases: callee or its callee redefined, subclass, singleton, private, protected, removed, refined; keys of another class, nil, Symbol, polymorphic, a third class; attr readers redefined, in a subclass, as a singleton; a Struct node, a nil key in a node, a cycle, root nil, root swapped by a thread, compare_to returning nil/Float/Bignum, a raise with its backtrace, caller, frozen tree, a 20000-deep chain, TracePoint), jit-matrix and hot-shapes-matrix identical to CRuby, -X:NoJIT -X:NoOSR and the baseline, except tree_int_key, which differs from CRuby on every tree (.NET interop answers 42.compare_to with Int32#CompareTo). IronRuby.Tests in Release fails only Exception_CauseRaisedInClause1, as on the baseline. Co-Authored-By: Claude Fable 5.2 <[email protected]> Claude-Session: https://claude.ai/code/session_013PQjty6LpWT6taQu2sGkNx
A cursor walking a linked list (List's is_shorter_than) and a lookup in a binary tree of 300 keys whose compare_to calls a leaf on self (CD's find_node): the two shapes round ten's method-JIT changes are about, which had only scratch scripts. Co-Authored-By: Claude Fable 5.2 <[email protected]> Claude-Session: https://claude.ai/code/session_013PQjty6LpWT6taQu2sGkNx
…nlined for two classes, any? out of the prelude Numbers on the code of a6b1c62, all thirteen benchmarks: IronRuby/CRuby 0.730 (0.750 and 0.779 in the two runs before), List 0.37-0.40 from 0.67. Against the tree before, both column orders: List 0.59 and 0.57, the other twelve inside the noise of a machine that was restarted between the rounds; the cells that were slower in both orders (Json, Bounce) are level in separate processes taken alternately. The ledger records the three changes that landed, what was tried and not kept (a yield reading the method's Proc once, a nil constant read in the method JIT, nesting the inlined call for self-calls), gaps 5, 6 and 8 closed with their measurements, where an iterator call's fixed cost goes, the table of what keeps each hot Richards method out of the method JIT, and what was found on the way (Int32.CompareTo reachable as Integer#compare_to). Co-Authored-By: Claude Fable 5.2 <[email protected]> Claude-Session: https://claude.ai/code/session_013PQjty6LpWT6taQu2sGkNx
Rounds seven to ten: all thirteen AWFY benchmarks measured; List 41%, CD 35%, NBody 34% and Permute 10% faster
… refuses a truffleruby directory it would not replace (review of #215) Three review points on #215 whose first fixes were partial: - awfy.rb took exit status 137 or a signal as the deadline's kill whenever it came, so a run killed early (the OOM killer, a kill -9 from elsewhere) still gave a median of what it had printed. The kill counts only when the deadline had passed; and a run that gets no number now says why on stderr - its status, how many iterations it printed and its last lines - where the output of a failed run was thrown away. Checked: a normal run, a command that exits 2, and a run killed after two seconds of an eight-second window (FAIL, "signal 9 before the deadline, 10 iterations"). - setup.sh repointed the `truffleruby` link with ln -sfn, which puts the link inside `truffleruby` when that is a real directory, and leaves what it holds in use. Such a directory is accepted if it is the version asked for and is an error with the way out otherwise. Checked with a directory holding 39.0.0 and 40.0.0 asked for: exit 1, nothing created inside it. - perf-step asked for a clean `git status -- Src` before the baseline build; Directory.Build.props and the build scripts shape the build too, so it asks for the whole checkout. Two findings of the same review that were only in its body are already fixed: a method with an explicit `&b` parameter is a light frame that enters through EnterLightMethodNamingBlock, and `def keep(&b); b; end` hands back a new Proc for each evaluation of a block literal, as CRuby does (checked over five shapes, cold and hot); and jit-matrix's FalseClass#! case already returns false. Co-Authored-By: Claude Fable 5.2 <[email protected]> Claude-Session: https://claude.ai/code/session_013PQjty6LpWT6taQu2sGkNx
Largo
pushed a commit
that referenced
this pull request
Nov 15, 2026
One conflict: Src/Libraries/Initializers.Generated.cs, which this branch removes and master had regenerated for the pattern overloads of all?, any?, none? and one?. It stays removed: the generator writes it. Checked on the merged tree, Release net10.0: the generated source registers the same 3468 entries as master's checked-in file and is the same text line for line (but for a byte-order mark); IronRuby.Tests 1255 tests, the one known failure; nine probe files of the perf rounds print what CRuby prints. Co-Authored-By: Claude Fable 5.2 <[email protected]> Claude-Session: https://claude.ai/code/session_013PQjty6LpWT6taQu2sGkNx
Largo
pushed a commit
that referenced
this pull request
Nov 16, 2026
…ught nothing Gap 5 was closed in round ten as too small for the bar. It had also been built, in the session of #215: with rules and ObjectConstruction reading a per-body cell, LightLambda's frames left the profiles of four benchmarks entirely (up to 3.7% of Towers) and the CPU time of a fixed run did not move (1.004 of the baseline, whose second measurement was 0.996). The branch was never pushed; the ledger keeps what it showed. Co-Authored-By: Claude Fable 5.2 <[email protected]> Claude-Session: https://claude.ai/code/session_01KPwZf7WbR4bihMQfHYjG4L
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.
What this is
Six rounds of speed work, each an experiment in a worktree of its own, measured against the unchanged build on a quiet machine and merged only if it was faster and computed the same thing; and, in between, looking for what that broke. The ideas come from what TruffleRuby does (frames that cost nothing until captured, blocks that are not materialized, inline caches, shape-checked instance variables); the selection came from measurement, and from round two on from a profile and from allocation counts.
Are-We-Fast-Yet at steady state, IronRuby time / CRuby 4.0.9 time (Release, net10.0; lower is better):
TruffleRuby 40.0.0 is at about 0.05 on the same five, so this closes the gap to CRuby, not to TruffleRuby.
Util/perf/LEDGER.mdhas every number, per-operation timings, bytes allocated per iteration, the profiles, and what was tried and not kept.What changed in the runtime
Method frames
RubyMethodScopeuntil a call needs one (c9a17e2). A call in such a "light frame" goes through a site bound withRubyCallFlags.HasLightScope; a rule that would read the scope returnsRubyOps.LightScopeRequiredand the method makes its scope and repeats the call.IR_LIGHT_CALLS=0turns it off.case/whenandwhileloops (0b3043d), a call with a literal block - the scope is made right before the Proc (5031808,IR_LIGHT_BLOCKS=0) - and optional parameters with scope-free defaults (7605894,IR_LIGHT_OPTIONALS=0).whileloop's OSR site (4de5fc9) instead of aMutableTupleper call. The first alone took Towers from 89 MB allocated per iteration to 0.2 MB.Blocks
ProcandBlockParamare reused when the callee can only yield: a light-frame Ruby method without a block parameter (fd94bce, 079cd93), or a library iterator marked[BlockNotKept](each,map,select,times,Range#each,Hash#each; baaa807).Proc#calland ayieldinside a block reuse the BlockParam of the last call, taken with an atomic exchange and handed back only after a normal return of a block whose scope was not captured (aaa2f99, 94dc916).RubyBlockScopeuntil a call needs it (96881ad).Instance variables and dispatch
IsTrue,IsFalse,SetAttributeare inlined, and the attribute rules' helper call is out of tail position, where the JIT never inlines (7c7ec90).Array#==no longer interns:to_aryper call (3c938e1).Method JIT
s == "lit", a finalC.new(...)and a final element store (ad47bb7, 38a149b, 2d29947); instance variables as operands,!x, instance variable writes when every deopt comes before the first write, identity compares and attr reader/writer calls (d14eddf, 9ca993d, 6347585, bf354cf, d88766c).if/casearms are emitted in the order they run, which the deopt-before-effect rule needs. Identity sites take the class of nil, true, false and Symbols without a type lookup (481ee80).Allocation
s[i]) is a new String on one of 128 shared contents, and gets a content of its own before any other read or any mutation (4a5b605, 965aac8). Bytes per iteration since the start: Richards 169 MB -> 20, DeltaBlue 54 -> 25, Json 73 -> 36, Bounce 71 -> 11, Towers 89 -> 0.15.Names of compiled bodies
IR|label|line|id|file(88cc224). The runtime's perf-map writer damaged every non-ASCII name, which left 45% of a profile unattributed. Backtraces are unchanged.What the speed work broke, and how it was found
Ten faults got past the checks listed below. Each was reproduced against CRuby first, is fixed, and has a case in a matrix or a registered test. Every review thread has a reply saying what was found and in which commit it was fixed.
Found by the first review (Greptile):
def f; f { }; endrecursed until the process died instead of raising SystemStackError: a light frame whose only call passes a literal block skipped the stack check.!(true && @x)answered false from a compiled body for an@xwhose class has a#!of its own.o.value = o.value + 1; @x = 1with a frozen self wroteo.valuetwice before raising FrozenError: the body was restarted after an effect.Found by a hunt that followed (three agents, one each on light frames, the method JIT, and block/Proc reuse, comparing CRuby, IronRuby and IronRuby with the JIT off on several hundred small programs each):
def d(i); [i].each { |v| return 5 }; end; d(1) { 9 }threw MethodUnwinder, on the first call (75bc14d).const_missingrecursing through a constant read, and#inspectrecursing through a qualified constant read, ended the process: a constant read is not a call site, so the frame had no stack check (bd852bd, 0e0070c).Found by the second review (CodeRabbit), in 079cd93:
def capture(&b); b; endhanded back the same Proc for every evaluation of a block literal in a frame: the block was marked reusable on the premise that a light frame can only yield to it. This is in block reuse, which the hunt had found sound.h.fetch(k, @n += 1)evaluated the default twice when the key made the compiled body restart.C.new(n + 1.0)in a self-recursive body left the outer invocations with aFloat#+an innerinitializehad redefined.def initialize(n); C.new(n + 1); endended the process: the direct construction had no stack check.Plus the tooling points of both reviews (a failed run is no longer a result in
awfy.rb,alloc.rb,micro-table.rb;profile.showns and cleans up its benchmark; quoting,pipefail, the requested TruffleRuby version; four matrix cases that did not test what they said; corrections to the perf skills).Tooling
Util/perf/:awfy.rb(steady-state timings on several interpreters),micro.rb/micro-table.rb(per-operation costs),alloc.rb(bytes per iteration, immune to machine noise),profile.sh/profile-agg.rb(perf sampling, Ruby methods named),worktree.sh(an isolated tree with its own DLR copy),setup.sh(TruffleRuby and AWFY),hot-shapes-matrix.rb(differential test, below),LEDGER.md..claude/skills/perf-measure,perf-step,perf-gate: the measure / try one thing / gate loop, written to run under/loop. The gate now asks the questions the faults above stand for.IR_LIGHT_FRAMES=whysays why a method is not a light frame;IR_JIT_VERBOSE=1now prints why the method JIT's screen rejected a method.How it was checked
Each round's merged tree against the tree before it, and again after each set of fixes:
Exception_CauseRaisedInClause1, which fails the same way in Release on master before any of this; compared by failing name.languageplus up to 32 directories (core: Kernel, Proc, Module, Binding, BasicObject, Method, UnboundMethod, Class, TracePoint, Array, String, Hash, Enumerable, Enumerator, Fiber, Exception, Range, Integer, Float, Struct, Symbol, NilClass, Comparable, Encoding, Regexp, MatchData, IO, File, Marshal; library: StringIO, StringScanner): identical failing examples and expectation counts (core/thread, whose count varies from run to run on master too, is left out). Last run: 23065 examples, 92368 expectations, 2 failures, 22 errors on both trees.-X:NoJIT -X:NoOSR:Util/perf/hot-shapes-matrix.rb(new: every accelerated shape run hot while what must invalidate it happens mid-run),jit-matrix,ivar-matrix,block-loop-matrix,block-scope-reuse-matrixand its blockpass variant,refinement-binding-matrix,full-message-matrix,error-message-matrix,encoding-matrix,chr-matrix: no differing line.raise-,encode-,astral-string-andcallable-parameters-matrixprint what the tree before prints (they differ from CRuby in a few lines on master too).ivar-stressandblock-scope-reuse-racepass.Not run here: net11.0 (this container has only the .NET 10 SDK; CI covers it), Windows, several runtimes in one process, and the full five-suite spec sweep. A sweep before merging is worth it: ten faults were found after the checks above had passed.
Where to look hardest
LightFrameRewriterrefusing every raw use of the scope it does not understand, on every frame that can recurse checking the stack - including through runtime helpers and direct paths that run Ruby code without a call site - and on the scope made on demand standing in for the one that would have been made at entry (flow control,returntargets). Five of the ten faults were here._pure,_canDeopt,_deoptAfterEffect,_effectNotOnSelf,_construction). Four of the ten were here.RubyScope.MarkCaptured,CreateMethodScopeLazy,InitializeBlock), while every[BlockNotKept]method really does not keep its block, and while a method that can hand its block on is never treated as one that only yields. One of the ten was here.MutableString._contentis now a property that gives a string a content of its own before use; code that reads_rawContentdirectly would see a shared, owner-less content.CreateMethodScopeLazy/CreateBlockScopeLazy, which fill the tuple from the variables.Tried and not kept (recorded in the ledger with their numbers): light-scope sites through the precompiled dispatchers, unboxed bools and no tail calls in rules, parked method scopes, a
MutableString.Equalsfast path, calls of other methods from method-JIT bodies, Integer results of library methods through the box cache (saved memory, not time).The branch has master merged in (through #211).
🤖 Generated with Claude Code
https://claude.ai/code/session_01KPwZf7WbR4bihMQfHYjG4L
Summary by CodeRabbit