Repository navigation
perf: JIT/OSR for case/when and Hash/Array access, rule-free first calls, precompiled startup library - #84
Merged
Merged
Conversation
IronRuby.Aot startup compiles the Ruby files `ir -e 1` loads (ruby4.rb, rbconfig, rubygems and the rest, Util/aot/startup-files.txt) into a library of saved IL. The loader registers its files when it sits next to IronRuby.dll (or IR_STARTUP_DLL names it), so requiring one runs the compiled top level instead of parsing, transforming and LightCompiling it. Files whose source hash changed are compiled from source as before. The load-time helpers the saved IL calls (PrecompiledCode) and Closure / RuntimeOps move into IronRuby.dll, so a saved assembly needs nothing but IronRuby. Saved assemblies are retargeted to net8.0 (PersistedAssemblyBuilder writes .NET 10 references) and crossgen'd against the R2R host. Precompiled top-level code is not interpreted, so a const_set caller location came from a CLR stack walk: 50 ms over the prelude's const_set loops. Such calls now get no location, as C-defined constants have none in MRI. IR_PHASE_TIMES=1 prints exclusive wall time per startup phase, IR_BIND_TRACE=1 one line per bind, IR_EAGER_DEF_BODIES=1 turns lazy def-body mapping off. ir -e 1, R2R host, best of 11: 0.86 s -> 0.725 s (median 0.94 -> 0.80), peak RSS 116 -> 119 MB. (cherry picked from commit 67bdbe325b4c7b13c4e9b748818f920221dc30be)
The saved IL has no PDB, so a backtrace through precompiled rubygems code had
each frame at its def's first line, and labels came from the innermost lexical
module ('Requirement.parse'). The compiler now records each sequence point's IL
offset and emits the table in RubyStartupIndex.Lines(); the backtrace builder
reads it (lazily) through RubyMethodDebugInfo. Labels resolve qualified class
names (class Gem::Requirement) and class << self, so backtraces match the
interpreted ones ('requirement.rb:107:in Gem::Requirement.parse').
The library records the MVIDs of the host's IronRuby, IronRuby.Libraries and
DLR assemblies and is ignored when they differ: its IL calls into them and
re-creates their binders, so a host rebuilt since must not run it.
RubyStartupIndex.Entries() hands out the top-level delegates without
reflecting over RubyStartup's 2.5k methods.
Util/aot/build-startup.sh builds the library into the R2R host's directory.
R2R host, best/median of 11, base d96bab0 -> this:
ir -e 1 0.857/0.937 s -> 0.744/0.779 s
-e 'require "set"; require "json"' 1.001/1.031 s -> 0.842/0.885 s
Util/bench/bench.rb --list 0.908/0.958 s -> 0.802/0.840 s
peak RSS (-e 1) 116 -> 121 MB
spec/language with the library: 80 files, 2934 examples, 5563 expectations,
0 failures, 0 errors. IronRuby.Tests: 0 failures.
(cherry picked from commit 22882d84c2ea49d1e410dc8cd44d99d0df0658c1)
A precompiled file is now checked against its source the first time it is required, not at registration: the library can carry files a process may never load at no cost to the ones that do. It now also holds rubygems/path_support.rb (the first require of anything outside the startup set loads it) and the commonly required standard library: json, set, stringio, strscan, io/console, date, fileutils, optparse, pp, prettyprint, tempfile, delegate, tmpdir, time. A script using all of them prints the same with and without the library. IronRuby.Libraries is dropped from the identity check: the saved IL does not reference it (library methods are reached through binders), and its MVID changes with every rebuild of IronRuby.Prism. IR_PHASE_TIMES=1 also reports the inclusive time of the outermost binds and when the prelude starts and ends after process start. (cherry picked from commit 86bc72cc9e6d0ce89eb4e9580f722d893340ac25)
All files' methods and lazily initialized constant fields were in one class (RubyStartup, 28k static fields and 2.5k methods with the startup set alone), whose type load at registration cost 7-15 ms and grew with every file added. Each file now gets a class of its own; RubyStartupIndex carries the file list and hands out a file's entry delegate on request, so registering the library loads no file's code and a file that is never required costs nothing. Registration of the library (46 files): 24-37 ms -> 12-23 ms. (cherry picked from commit 7f2ba7f0b64fc53ae7844e0409d764926d9a98c1)
A precompiled file's code is its top level as a file, so `load(file, true)' of a file in the startup library ran it unwrapped and leaked its constants (Delegator from delegate.rb) into Object. A wrapped load now always compiles the source, as it did before the library. (cherry picked from commit 887a500166f0a77b0e4f3dee774ff0d7d2bfad77)
How the library is built and kept correct (MVID identity check, per-file source hash, line table, first-runtime-only), what it leaves alone (call sites still bind as in interpreted code; binding is now the largest part of the prelude), and the A/B numbers: ir -e 1 0.848/0.906 s -> 0.752/0.795 s best/median of 21 on the R2R host. (cherry picked from commit 4c6840cc8f0b8ec668a2dbdf24ff9552186f2b26)
…ptions Phase timers, 5 alternating runs under bench-lock: the prelude falls from 650-690 ms to 530-560 ms. Parse, bridge, transform and LightCompile (about 270 ms) are gone, and JIT drops from 200-220 to 130-140 ms. The rest of the run grows by 60-80 ms: binder and site creation now happens at first execution, plus about 40 ms of native fixup and type-load time under the precompiled frames. Binding is unchanged at 210-235 ms. Recorded as measured dead ends: a version-bubble crossgen of the host and library (0.705/0.823 -> 0.715/0.810 s, +3 MB), the prism parse cache (at most 24-27 ms of native parse, not visible in wall time), and lazy def bodies (already on at d96bab0; turning them off costs 50-85 ms without the library). (cherry picked from commit 5e80ec52afd6963faf1cb82282716a04e459491d)
A shared rule (RuleVersionSet) tested the receiver's class version against the set's LastVersion, a field of an object loaded from the rule's closure, where a rule of its own compares with a constant. The site that asks for the shared rule to be built is the one most likely to run it hot, so the test now compares with that version as a constant first. The startup library makes such sites common: its compiled code registers the typed delegate shapes ((CallSite, RubyScope, object, int) and so on) with the binders before startup's last method definitions bump the class versions, so the first compiled loop of a program got shared rules for its Integer#< and #+ sites where it used to get its own. CallSite.Target self time in attr_set went 84 -> 125 ms. Util/bench, R2R host with the library, best of 6 at scale 3, library off vs on: before call_empty 1.075, attr_set 1.075-1.10, proc_call 1.08; after call_empty 1.00, attr_set 0.94.
The Linux Release build's IronRubyReadyToRunHost target now runs Util/aot/build-startup.sh against the freshly published bin/R2R/<tfm>.new before it swaps it in, so the host and its IronRuby.Startup.dll always go in together. -p:IronRubyStartupLibrary=false leaves it out; without a .NET 10 SDK and runtime the script says so and exits 3, and a failure only warns: either way the host runs without the library. The compiler (IronRuby.Aot, net10.0) now runs the host's own IronRuby and DLR builds (IronRubyAotHostTfm, net8.0 by default) instead of net10.0 builds of its own: the saved IL calls into those exact assemblies. Inside a build it builds only itself (no restore of the referenced projects, which would rewrite their assets with other properties). It takes the crossgen2 of the host's major version from the NuGet cache, the latest installed shared framework of that version (or the host's own, if it is self-contained), and keeps the last library with a key of everything it was made from, so an unchanged rebuild copies it (about 1 s instead of about 18 s: 8 s compile, 10 s crossgen2). Paths: the library records the files relative to the IronRuby tree and where the tree is from the library. Every path under the tree the code holds (__FILE__, a block's or a method's file) is compiled as a call of PrecompiledCode.Rooted, and backtrace frames of the library are rebased, so a copy of the tree elsewhere (an unpacked release) uses the library with its own paths. A path in a symbol or frozen string would make it unrelocatable; it is then only used where it was compiled. The library is not looked for when IronRuby.dll has no file (NativeAOT) or the runtime cannot load code.
The saved code reduced each LightDynamicExpression to a DynamicExpression typed after its arguments, (CallSite, RubyScope, object, int) -> object and so on, where the interpreter runs the same site untyped, every argument and the result an object (DynamicInstructionN. CreateUntypedInstruction). Each typed shape is a delegate type, a CallSite<T> and rule instantiations of its own that the JIT compiles at startup, rules its binder caches apart from the interpreted code's, and shared-rule records that went stale before the program's own compiled code bound the same shapes. The library's sites now take the interpreter's shape; value-type literals are boxed once, into a field. ir -e 1 with the library (IR_PHASE_TIMES, one run each, typed -> untyped): total 574 -> 480 ms, binding inclusive 244 -> 194 ms (no library: 216), rules built 699 -> 651 (634), JIT 420 -> 332 methods (308). bench-lock, N=11, median (best): ir -e 1 base 0.712 s (0.662) -> 0.590 s (0.572); require set+json 0.848 s (0.805) -> 0.666 s (0.632); peak RSS 106 -> 112 MB. Also: the build lock is held with flock -o, since the build servers and MSBuild nodes the compiler's build starts outlive the script (a second build waited 8 minutes for them), and those builds run -nodeReuse:false.
Until now any method or while loop containing a case/when, a constant, or an
element read/write was outside the method JIT and OSR: the screen rejected the
method, the OSR emitter gave up ("h holds Hash", "node: CaseExpression"), and
the loop ran generically with one dynamic === call site per when (an IsKindOf
chain each) and a full call per h[k]. case_when_class was 5.0x CRuby and
hash_lookup 2.3x.
Specialized code now carries objects (JT.Obj locals and OSR loop slots, Ruby
truthiness as a test) and:
- folds constants (C, ::C, A::B) under a constant-version guard on the entry;
- turns case/when into tests: `when Module` folds to a constant on an
Int/Long/Float/Bool subject and is a per-kind bit test on an object (the CLR
type of nil, true, false, Integer, Float, Symbol, String, Array, Hash, Range,
computed once per case; anything else asks the class once per when); Integer,
nil/true/false, Symbol, String and Integer-range whens are direct compares.
Module#===, Integer#===, Range#===, Symbol#===, String#=== and the methods
they call (==, <=>, to_str, respond_to?) are checked to be the library ones
when compiling, and the method-version guard retires the code when any of
them is redefined; refinements still turn the JIT off;
- calls Array#[]/[]= and Hash#[], #[]=, #key?, #fetch, #size, #empty? on an
exact Array/Hash straight into their storage (Hash.Jit.cs, RubyArray.Jit.cs).
Anything that would run Ruby code - a default proc, a key whose #hash/#eql?
the comparer has to ask, a subclass, a singleton or extending module's [],
a frozen receiver of a write, an index out of range - deopts and the generic
code makes the call. compare_by_identity hashes, Hash#default and String
key dup+freeze behave as Hash#[]= does.
- Element writes go into a per-thread undo log, which a deopt rolls back
before the generic code re-runs the method (or the OSR iteration); a method
body that writes elements deopts at its loop safe points instead of running
a trap handler between writes a later deopt would take back.
- Element reads used as numbers (s += a[i], h[k] += 1) are speculated to be
Integers (or next to a Float, Integers or Floats).
Pinned, best of 5, scale 1 (CRuby / base 97fe918 / this):
case_when_class 0.058 / 0.290 / 0.055 s (5.02x -> 0.95x CRuby)
hash_lookup 0.112 / 0.260 / 0.090 s (2.32x -> 0.80x)
case_when 0.106 / 0.282 / 0.042 s (2.66x -> 0.39x)
array_index 0.081 / 0.231 / 0.053 s (2.85x -> 0.65x)
const_lookup 0.039 / 0.166 / 0.031 s (4.25x -> 0.78x)
At scale 3: case_when_class 0.37x CRuby, hash_lookup 0.58x.
ruby-bench (best ms, base/this): sudoku 800/556 (1.44x), matmul 836/534
(1.57x); fannkuchredux, lee, blurhash, ruby-json, 30k_ifelse, nbody,
binarytrees, nqueens, ruby-xor, splay within noise (0.96-1.10x).
Cases for every new specialized path, in methods and in OSR loops: case/when of each core kind, subclasses, extended objects, Integer/Float/Symbol/String/ range whens; Module#===, Integer.===, Integer#===, Symbol#===, Range#===, String#===, and what the literal whens call in turn (Integer#==, Float#==, Integer#<=>, NilClass#===, to_str), redefined mid-run and restored; objects with their own == and to_str as subjects; constants shadowed and reassigned, and a when constant that is never reached; Hash#[]/#[]=/#key?/#fetch/#default and Integer#eql? redefined mid-run and restored; default values and default procs (also on a Hash subclass, set late, writing the hash); compare_by_identity, frozen hashes and arrays, odd keys (nil, Float, Bignum, Int64, Array, String encodings and subclasses); deopts after element writes; a singleton [] and an extending module; a String key with a singleton eql?; refinements of ===, Symbol#=== and Hash#[]. Output is identical under CRuby, the JIT, and -X:NoJIT -X:NoOSR.
…reported A backtrace is the throw-site walk, which ends with the frame that caught the exception, plus the catch-site walk taken inside that frame. For a compiled catch site the second walk was added with skipFrames 1, which skips the first frame *reported*: right when the catch site is reported in the first walk, wrong when it is not. A frame of the Ruby half of the core library is not reported, so the frame above it went missing instead. gem_compat.rb's Kernel#require is a block that catches the LoadError of a missing file. Once that block is compiled - from the start with the startup library, after 200 calls without it - `require "nope"` from the main program lost the main program's frame (an empty backtrace for a direct call), and a method that required lost its own frame. The catch site is now skipped as the first compiled Ruby frame of the catch-site walk, reported or not. With and without the library, the IL build now gives the same backtraces for require, require_relative, load and the rubygems path (/tmp scripts with 9 such cases).
Module#const_set and #autoload record where they were called from (const_source_location, "previous definition was here"). Interpreted code has that in its frame; compiled code only on the CLR stack, at ~0.2 ms a walk, so precompiled top-level code got no location at all: with the startup library Gem.const_source_location(:ConfigFile) was [] instead of rubygems.rb:1398. The compiler now puts PrecompiledCode.NoteCallLocation(scope, file, line) in front of each const_set and autoload call (19 in the startup files; none in the Ruby half of the core library, whose frames report their caller's location), and both methods take the caller's RubyScope (Initializers regenerated by hand: one parameter more, masks shifted), which only the noted call can match. The note is taken once, so a later send from the same scope cannot pick it up. Still different with the library: constants that ruby4.rb itself makes with const_set or autoload (Errno::*, the Set autoload) have no location, as C-defined ones in MRI; without the library they were reported at gem_prelude.rb:9, the line that requires ruby4.
…ecialize -X:JIT (on by default) wraps a method body when it is first compiled and specializes it from the method's AST once it is hot. A precompiled method has only a header - name, parameters, location - so it was never wrapped: Object#itself and the Fiber accessors (__thread__, __root_fiber__, __set_status__ ...) that the base specializes ran as plain compiled code. Util/bench, best of 5 at scale 3, library off -> on: call_kw_omitted 0.638 -> 0.880 s (1.38x), fiber_new 1.27x. JitStub's static decision is now JitStub.IsCandidate. The compiler asks it for each def (109 of the 2,379 in the startup files pass), keeps the def's source text (4.9k chars in all) when it parses back - the way the runtime will parse it, starting at the def's line - to a method the screen takes too, and RubyMethodBody parses it at the method's first call and wraps the compiled body as an interpreted one would be. `ir -e 1` parses 6 of them. Library off -> on after: call_kw_omitted 0.730 -> 0.699 s (0.96x), Object#itself and the five Fiber accessors specialized as without the library.
ReadyToRun code is replaced by optimized code only after enough calls, and
never while it runs. A loop that runs long in a method called once -
Kernel#loop, a fiber thread's `while fiber' block - ran to the end as
ReadyToRun code, which calls every helper the JIT would inline
(ReuseBfcForYield, MethodYield, Yield0, SafePoint): Kernel#loop's own time
was 1.29 s against 0.59 s for the base's loop-compiled code in a profile of
`loop { i += 1; break if ... }`.
The compiler now marks a method or block whose own code has a loop
AggressiveOptimization (70 in the startup files): crossgen2 leaves it out
and the JIT compiles it optimized at the first call. File and class bodies,
which run once, keep their ReadyToRun code. IR_AOT_LOOP_JIT=0 turns it off.
bench-lock, plain library -> this: loop_break (tools micro row) 0.332 ->
0.283 s, library off 0.272 s; enum_next_gen 0.98x, fiber_switch 0.95x,
fiber_new 1.04x; ir -e 1 best/median 0.661/0.711 -> 0.652/0.686 s (N=11);
the library is 32.0 MB instead of 33.0 MB.
The release archive gets IronRuby.Startup.dll, built by build-startup.sh against the archive's own self-contained composite host and its own copy of the standard library (--root the stage), so the paths it holds are rebased to wherever the archive is unpacked. Building it needs the .NET 10 SDK and runtime; without them (exit 3), or when it fails, the archive goes without it. IR_STARTUP_LIBRARY=0 leaves it out. Before archiving, the script checks that the unpacked tree really uses it (IR_STARTUP_DLL_TRACE) and removes it otherwise rather than ship a library the build would ignore. build-startup.sh passes -p:DlrSourceDir only when told (--dlr or DLR_SOURCE_DIR); otherwise the compiler builds with whatever the tree's build takes (Directory.Build.props or .rsp), as the release's publish does. linux-x64 archive unpacked elsewhere, bench-lock, N=11, library off -> on: ir -e 1 best/median 0.668/0.707 -> 0.574/0.594 s, peak RSS 113 -> 121 MB; require set+json 0.854/0.879 -> 0.695/0.715 s, 119 -> 133 MB. The archive is 160 MB unpacked (+32 MB); packaging took 1m47s.
The publish retries once for the IOException race in Src/Prism/bin/.../ linux-x64. When the first attempt hit it, Exec saw its error lines and set ExitCode to -1 although the retry succeeded and the command exited 0. Since 7f27712 the swap is a step of its own gated on that exit code, so such a build kept the old host and skipped the startup library; before, the swap ran inside the same command. Seen on a no-change Release build: R2R left at the old host, net8.0.new left behind. The publish Exec now ignores the error-line format, so only the real exit status counts; both attempts failing still warns (WarnAndContinue). Rebuilt: publish, cached library (1 s), swap.
…late The undo log is the riskiest part of the element intrinsics: a deopt hands the call back to the generic body, which re-runs it, so every write of the specialized run has to be gone first. Section 7d drives each way a write can need taking back: appends that grew the hash (a resize between the append and its undo), writes made by inner self-calls when the innermost one deopts, Array and Hash writes mixed in one run, the frozen copy of a String key, a value replaced while the hash is being iterated, and an OSR loop whose appends grow the hash before it deopts mid-loop. It also includes a module into String and Array after a `case` testing that module has been specialized. Output stays identical under CRuby, IR_CONFIG=Release ./ir.sh and -X:NoJIT -X:NoOSR (454 -> 468 lines); all five new methods and the loop are specialized (IR_JIT_VERBOSE / IR_OSR_VERBOSE).
x.fetch(k) compiled to a Hash-only helper whenever Hash#fetch was the prelude's, because the receiver's class is only known from the profile, and an instance variable has none. An Array receiver then deopted on every call until the stub retired the method: ruby-bench blurhash's ThreeDArray#[] (`@list.fetch(i)`) took 16 deopts and a retirement on its first iteration. The helpers now take the same arrays/hashes flags as Array#[] / Hash#[]: an exact Array whose #fetch is the library method (IListOps.Fetch) answers the element for an Int32 index in range, counted from the end when negative, and the default for fetch(i, d) out of range; fetch(i) out of range (IndexError), any other index (to_int, TypeError) and a subclass deopt, and the generic call raises. An Int32 key or index is no longer boxed (FetchInt, FetchIntDefault). blurhash: ThreeDArray#[] is specialized with 0 deopts (was 16 deopts, 1 retirement, 1 retry). jit-matrix, C# suite (0 failed) and spec/language (R2R and IL: 2934 examples, 0F/0E) unchanged.
Section 7e: Array#fetch through an instance variable that also holds a Hash in another object, in range, from the end, out of range (IndexError and the default), odd indexes (Float, nil, String, Bignum), a subclass, a frozen and an empty array, element sums that deopt on a Float, nil or a short array, an OSR loop with a default; Array#fetch redefined mid-run, hot again, restored, and a singleton fetch on one Array last. Output identical under CRuby, IR_CONFIG=Release ./ir.sh and -X:NoJIT -X:NoOSR (482 lines). An Int64 index is left out: IronRuby raises RangeError for [1].fetch(2**40) with the JIT on and off alike, where CRuby raises IndexError.
…arses Util/make-startup-mibc.sh, rerun on the R2R host with its startup library: startup now runs the library's precompiled code instead of the parser, transformer and LightCompiler, so the profile package-release.sh gives crossgen2 for the composite image changes accordingly (123 -> 131 kB). Release archive, old -> new profile, bench-lock, N=15, best/median: ir -e 1 0.542/0.590 -> 0.523/0.580 s; require set+json 0.620/0.696 -> 0.606/0.694 s; peak RSS unchanged (121 / 133 MB). Neutral within noise, but the profile now names the methods the shipped startup path runs. IR_STARTUP_DLL_TRACE=1 also says when a precompiled method's source is parsed for the method JIT (6 for ir -e 1), next to the files it parses.
Part D described the d96bab0 prototype: built by hand, typed call sites, no JIT specialization, ReadyToRun loops, a missing require frame. It now says how the Linux Release build and package-release.sh build it, how the known costs were handled, and what it measures on 97fe918. R2R host, bench-lock, N=21 interleaved on a loaded box, best/median, base -> library: ir -e 1 0.675/0.784 -> 0.576/0.672 s (106 -> 112 MB peak RSS); require set+json 0.782/0.943 -> 0.693/0.792 s (110 -> 124 MB); bench.rb --list 0.848/0.900 -> 0.717/0.760 s. Quieter box, N=11: ir -e 1 0.676/0.722 -> 0.557/0.599 s. Util/bench, 67 rows, geomean 1.003; one row slower with the library (mandelbrot, about 5 ms of 80, first run of bench.rb's top-level block only). The comments in Ruby.Console.csproj and build-startup.sh now say ~17% and +6 MB instead of the prototype's ~12% and +4 MB.
…f non-numbers
A `when 1..5' reached by a subject that is not a number cost about 16 us in
IronRuby, generic and specialized code alike: Range#=== asks `1 <=> v',
Integer#<=> asks v to #coerce, and Protocols.TryCoerce made that call and
caught the NoMethodError a CLR exception. CRuby's rb_check_funcall finds there
is no #coerce without calling anything. The specialized range test deopted on
such a subject, so the generic code paid the exception after a deopt.
- TryCoerce now answers "not coercible" without the call when the object's
class resolves no #coerce and its method_missing is BasicObject's - the case
in which the call could only raise the NoMethodError the catch already turns
into that answer. A user respond_to? is still asked first, and a #coerce, a
method_missing or a respond_to? of the object's own is called as before.
- CaseIntRange answers false itself for nil, true, false, a Symbol, and an exact
String, Array or Hash whose classes have no #coerce and library respond_to?
and method_missing (also on any singleton class of an instance; the method
version guard keeps that so) instead of deopting.
Generic (-X:NoJIT -X:NoOSR, ns/op, base -> this): 1 <=> nil 17900 -> 470,
(1..5) === nil 16900 -> 970, (1..5) === [1] 16000 -> 760, 1.0 <=> nil
15700 -> 440, ('a'..'z') === 1 16900 -> 1490.
A method `case v when Integer, String, Float, Symbol, 1..5 else' called with
[1, "x", 2.0, :s, nil, [1]], 1M calls, pinned best of 3: CRuby 0.214 s,
base 5.64 s (26.3x), this 0.238 s (1.11x).
Util/jit-matrix: range whens of every kind of subject, Floats and edges; a
Symbol#coerce, a singleton coerce on one String, a method_missing included into
NilClass and Array, and a Hash#respond_to? each defined mid-run, hot again,
and taken away, counting the calls; <=> of an Integer with objects without
#coerce. Identical under CRuby, the JIT and -X:NoJIT -X:NoOSR (496 lines).
`case v when 0 ... when Array ...' deopted on every Array, Hash or Range
subject that reached the Integer when: Integer#=== asks `v == 0', and the
specialized test only knew the answer for nil, true, false, Symbols and
Strings. A method seeing such subjects often deopted until the stub retired
it, and then ran generic.
Array#== and Hash#== of an Integer are false without calling anything else
once the Integer does not respond to to_ary or to_hash, and Range#== of a
non-Range is false; CaseFixnum now takes a mask of the kinds that answer
false (worked out when compiling: each class's == the library one, also on
any singleton class, and Integer without the conversion), in place of the two
flags it had.
`case v when 0; when 1, 2; when Array; when Hash; else end' in a method,
subjects [0, 1, [1], {1=>2}, nil, :s, 2], 1M calls, pinned best of 5:
CRuby 0.481 s, base 0.840 s, this 0.232 s.
Util/jit-matrix: Integer whens on every kind of subject and on subclasses;
Array#== redefined, a Hash with a singleton ==, Range#== redefined, each
mid-run, hot again and restored. Identical under CRuby, the JIT and
-X:NoJIT -X:NoOSR (506 lines).
…ource at every load Coverage.start is mostly called at run time (SimpleCov, test runners), after the startup library was registered. A require of one of its files then ran the compiled top level, which has no coverage counters, and the file was missing from Coverage.result: Coverage.start(lines: true); require "optparse"; require "delegate" ruby, base, IR_STARTUP_DLL=none: optparse.rb 842-843 lines, delegate.rb 136 library: optparse.rb MISSING, delegate.rb MISSING TryGetCompiledFile now passes over a precompiled file while _context.Coverage is set (the entry stays, for when Coverage stops), so the file is compiled from source as without the library: 843 / 136. The source is also checked against the library's hash at every load, not only the first. A `load' of a library file edited during the run ran the old compiled code; it now runs the edit, as the base does. require loads a file once, so this costs a hash per `load' of such a file.
…other module compiles from source
The compiler works out each method's frame label from the lexical nesting, and the runtime works it
out from the module the def runs for. They differed for module functions and for `class << Time':
FileUtils.mkdir_p('/proc/nope/x') base/CRuby 'FileUtils.fu_mkdir', 'block (2 levels) in FileUtils.mkdir_p'
library 'FileUtils#fu_mkdir', 'block (2 levels) in FileUtils#mkdir_p'
Time.parse('garbage!!') base/CRuby 'Time.make_time' library 'make_time'
Time.iso8601('bad') base/CRuby 'Time.xmlschema' library 'xmlschema'
A static label cannot be right for both copies of a module function ("FileUtils.mkdir_p" when called
on the module, "FileUtils#mkdir_p" when FileUtils is included), nor for a def in class_eval or in a
block. So each precompiled method body now carries the label it was compiled with, and when the
runtime would give the method another one, RubyMethodBody compiles that def from its source, as it
does without the library: PrecompiledCode.ParseDefinition reads the def's text from its file, only
while the file still has the hash the library recorded, with the file's frozen_string_literal
comment in front (a lone def would otherwise get mutable literals; checked on FileUtils'
remove_trailing_slash). Labels are now those of the base and CRuby in every case above, and for
the included copy as well.
A wrong guess then costs a parse at the method's first call, so the walker guesses the copy most
calls go to:
- module_function (bare or with names, and FileUtils' private_module_function): the module's
singleton copy, "FileUtils.mkdir_p", except in Kernel ("Kernel#sleep") and in a module the
library's files extend (Gem::Deprecate, whose functions every start calls as instance methods);
- `class << Const' and `def Const.m': Const's singleton methods when Const is a module the files
define or the runtime has (Time, IO, Dir); ENV and other objects get the bare name, as at run time;
- `X = Class.new do ... end' (Module.new, Struct.new, Data.define): X's, since the runtime labels a
method at its first call, when X has its name. The walker did not look into blocks at all before.
IR_STARTUP_DLL_TRACE=1 says which defs are compiled from source. `ir -e 1', require "set"/"json",
and requiring optparse, time, tempfile, pp, fileutils, date, stringio, strscan, delegate, tmpdir
and io/console compile none: a mismatch only costs programs that call the other copy.
…text, as the compiler made them
The compiler makes the literal text between interpolations a frozen MutableString of characters.
The library re-created it from its bytes, a string of binary content, and every interpolation that
appended it to the characters of the parts around it converted one of the two. Fiber#initialize's
"#{loc[0]}:#{loc[1]}" took 3x the time of the base's (profile of 150k Fiber.new: 181 against 57 ms
under RubyOps.CreateMutableStringN), and Fiber.new allocated 144 bytes more per call.
PrecompiledCode.FrozenString(string, encoding) now makes such a part from its text, and the bytes
only when the compiler's was made of bytes. Fiber.new { } then allocates what it does without the
library (1968 bytes after warm-up, down from 2112), the Fiber.new loop of the review (15k per run,
best of 7) is 0.050-0.063 s instead of 0.065-0.069 s (library off 0.047-0.055 s), and the library
is 0.16 MB smaller.
…ter the call PrecompiledCode.NoteCallLocation's thread-static note stayed set when the noted call never reached Module#const_set or #autoload (a receiver with a const_set of its own): it kept the scope alive, and a later const_set from the same scope that noted nothing (through send) took the stale location. The compiled call now clears the note when it returns (ClearCallLocation), and a const_set or autoload that finds a note it does not match clears it as well, which covers a noted call that raised.
…checked both ways startup-checks.rb prints what the review found the library changed - coverage of files required after a run-time Coverage.start, the frame labels of module functions (both copies), of `class << Time' methods and of Dir::Tmpname, the frozen literals of a def compiled from its source, interpolated strings - and check-startup.sh runs it with the library and with IR_STARTUP_DLL=none and compares (13 lines, the same; before the fixes 6 of them differed). It also checks that a copy of the tree elsewhere uses the library, and that `load' of a library file edited since runs the edit (false before, true now). About 4 s.
A Ruby frame captures the backtrace of an exception it sees go by in an exception filter (RubyExceptionData.CaptureExceptionTrace), along with the interpreted frames the interpreter saved on the exception when it left an interpreted frame (Interpreter.HandleException, a catch). A compiled Ruby method's filter runs while the stack is searched for a handler, before anything has been left: an exception a compiled rule or library method throws into a compiled method had no interpreted frames saved yet, and the backtrace lost every interpreted frame above - and the library frames reported with an interpreted frame's line. It ended at the compiled frames: TypeError: no implicit conversion of nil into String @ File.join | Object#a7 | block (2 levels) in <main> That happens once the call's rule and the method are compiled, so when depended on compile timing: the baseline truncates traces from the 33rd call or so on (an interpreted rule's catch saved the frames until then); the dispatchers, which spend their budget on more call shapes than one rule takes, moved that point for some calls (the reviewer's convbt.rb: 3 frames instead of 9 at its 31st and 32nd iterations). The trace now takes the thread's interpreted frames when none were saved: all of them are still on the stack, innermost first, and are those the interpreter would have saved. convbt.rb (10 calls of library methods raising, 40 iterations; frames per backtrace): the baseline drops to 2-7 frames in 23 of its 55 traces, this tree in none (8-10 frames each; CRuby 9-10).
A call passing a block argument (`a.map(&b)`) with b nil chose the overload of a library method that takes no block (Enumerable#map's, which returns an Enumerator), and its rule tested nothing about the block: a later call from the site with a block took that rule too, ignored the block and returned an Enumerator - [3].map(&:succ) after a map(&nil) at the site gave an Enumerator of [3] instead of [4]. Only a callee that takes a block had its block tested (RuleControlFlowBuilder). The reviewer found it because the dispatchers do test whether a block is given: a site was right for its first 32 calls and wrong once its rule took over. The rule now tests that the block is nil when a nil block chose an overload without a block parameter (or none matched). IronRuby.Tests LibraryMethodNilBlock1 (rules only, BudgetOverride 0): sort_by(&nil) then sort_by(&blk), map(&nil) then map(&blk) at the same sites; it fails without the restriction. The reviewer's blkpass60.rb and a Mutex#synchronize/each_slice/sort_by mix of nil and real blocks now print what CRuby prints, with and without -X:NoAdaptiveCompilation.
7395bda ran the generic code whenever any TracePoint was enabled. A typed body only lacks the :line, :call and :return hooks and the :c_call and :c_return of the library methods it inlines; it raises, rescues, defines classes and switches fibers only through the generic code. So a TracePoint on :raise, :rescue, :class or :thread_begin, which a program can keep enabled for its whole run, also turned the JIT off for the whole process. The entry guard and OsrLoopSite.Run now test ActiveEvents against JitStub.TypedBodyEvents (line, call, return, c_call, c_return, and the block events for safety). This is still one static read and an AND. Release, 2M calls of a 4-way case/when method with a :raise TracePoint enabled: 0.304 s (0.297 s without one). Base takes 1.129 s, and so did 7395bda, which ran the generic code. The jit-matrix gets :c_return on an inlined Hash#[], plus :raise alone and :raise/:rescue/:class while hot methods miss and raise. The output is identical under CRuby, Release, R2R, and both with -X:NoJIT -X:NoOSR.
92ee525 made a long-vs-Float comparison exact by range-testing the long inline. Within 2**53 the two were compared as doubles, and past that CompareWideLongDouble was called. That made the common case pay an add, a compare and a branch on top of the double comparison: 20M iterations of `x = i * 3; x < f; f >= x' took 0.242 s, against 0.187-0.210 s on base. The long's nearest double already orders against the Float as the long does, unless the two are equal. The Float is a double, so when it is above the long's double it is at least the next double up, and the long is short of that. Only on a tie is CompareWideLongDouble asked, and it is exact for any long. The common case is now one conversion and one comparison, plus a second test of the same flags. Release, best of 8 under one bench-lock: the loop above takes 0.195 s, base 0.190 s (base is wrong past 2**53); `a[i & 7] < f' takes 0.331 s, base 1.590 s. jit-matrix 7f gets ties and near-ties: x's own double, the doubles either side of it, and x's double plus a half, around 2**53, 3 * 2**52, 2**62 and both Int64 ends. They run as a typed long, as an element and in an outlined loop. Base gets all three wrong. The output is identical under CRuby, Release, R2R, and both with -X:NoJIT -X:NoOSR.
…ements; exact Integer-Float compares The method JIT and OSR now specialize case/when (class, Integer and range whens), constant reads, Hash and Array element reads and writes, and Array#fetch. Integer-vs-Float comparisons are exact past 2**53 in the JIT and in Float#==. A stored-only parameter, local or OSR slot keeps the box it arrived in. The JIT steps aside only for the TracePoint events a typed body would miss, and never for a body with line coverage. Operator and element methods are inlined only while public. On the track's own A/B (Release IL, bench-lock): case_when_class 4.8x (8x at scale 3), hash_lookup 3x, case_when 6.7x, array_index 3.8x, const_lookup 4.5x, const_scoped 4x, hash-bench lookup_miss 2.2x and large_lookup 2x, ruby-bench sudoku 1.35x and matmul 1.58x; the other rows within noise at scale 3. Util/jit-matrix.rb grew the cases for all of the above and is identical under CRuby, the JIT, NoJIT/NoOSR and R2R.
…s first calls A site's first calls of a library method go through a LibraryDispatcher built from the method's entry points instead of a compiled rule: the dispatcher accepts exactly the calls its rule would, with a per-dispatcher budget, and a spent dispatcher makes the call hot so the binder builds and caches the rule for every site that shares it. Ruby methods with optional or rest parameters, splats, send, define_method and Method#call get the same treatment; the common implicit conversions (to object, integer widening, paths given as Strings, a type that converts to itself) need no rule either. Site delegate type arguments are looked up once, and the commonest call site storages are made without Activator.CreateInstance. Exceptions thrown by compiled rules or library methods into compiled methods now keep the thread's interpreted frames, and a nil block that chose a block-less overload gets a rule restricted to nil blocks (map(&nil) matches CRuby). On the track's own A/B under bench-lock: -e 1 startup median 0.734 -> 0.660 s (R2R, same 106 MB peak RSS), spec/language wall 80.9 -> 67.7 s, whole-process Util/bench rows 1.07-1.12x; warm Util/bench rows within 5%.
…up.dll) The prelude (ruby4.rb, rbconfig, rubygems, set) and the common stdlib (optparse, time, tempfile, pp, fileutils, json, monitor, delegate, stringio, date and others) ship precompiled in IronRuby.Startup.dll, built by Util/aot/build-startup.sh with the R2R host as part of the Release build and shipped by package-release.sh. One class per file is loaded when the file first runs, after its source hash and the host identity are checked, so an edited file or a relocated tree still runs the source. Call sites are in the interpreter's shape and shared call-site rules test the version they were built for first. Methods and blocks with a loop, and the methods the method JIT may specialize, keep their source and are left to the JIT. The library does not change what runs: Coverage compiles from source while it measures; frame labels, line tables, frozen literals, interpolated literals and const_source_location match the compiler's; precompiled methods and blocks that run a block or a loop keep a per-thread frame so other threads' backtraces show them. Util/aot/check-startup.sh checks all of that with the library against IR_STARTUP_DLL=none. Conflicts with sp/w4-jitcover, resolved keeping both: JitStub keeps the IsCandidate/Screen split and the Wrap overload that takes the declaring scope (constants fold in it), and RubyMethodBody hands the JIT the def's AST the library kept the source of, with the declaring scope, and never a body that counts its lines for Coverage. On the track's own A/B under bench-lock (R2R, N=21): -e 1 0.758 -> 0.648 s median (-15%), set+json -16%, optparse/time/tempfile/pp/fileutils -30%; +6-14 MB of transient peak RSS; Util/bench geomean 1.006 over 67 rows, fiber_new 1.18x the base at scale 3 (a warm-up effect, documented in Util/aot/README.md part D).
Regenerated with ClassInitGenerator /refcache from a Debug build: the same entries, sorted by name. Entries inserted by hand in earlier rounds had drifted out of order, so every regeneration showed a spurious diff.
The #coerce protocol (Protocols.TryCoerce) asks an operand that defines
its own respond_to? whether it has #coerce before calling it, as
rb_check_funcall does. It asked through the coercion storage's site,
which holds one site, named by its first use: once a call had made it
the #coerce site, a later operand's respond_to? went through it as a
call of coerce(:coerce) - a NoMethodError for an operand without
#coerce, the wrong argument for one with it. With rules the storages
only ever served operands of one class, so this needed two operands of
one class, the first before the respond_to? was defined. The library
dispatchers (sp/w4-bindcost) serve every call of a site from one set of
storages, so `1 <=> :s` with a Symbol#coerce followed by `1 <=> {}` with
a Hash#respond_to? did it too, and the jit-matrix case "Hash#respond_to?
defined" (sp/w4-jitcover) raised NoMethodError on the merged tree under
the JIT, where CRuby and NoJIT answer [:other, :other, 2].
The question now goes through RubyContext.RespondTo, the context's own
respond_to? site, and the storage's site is only ever the #coerce site.
IronRuby.Tests CoerceRespondTo1 runs the sequence with the dispatchers
and with rules only (BudgetOverride 0); the script raised on the merged
tree before this. Util/jit-matrix.rb under the JIT (Release) is
identical to CRuby's output again (533 lines, md5 640e9234); the C#
suite is 0 FAILED after a clean rebuild.
… rethrows through ci.yml builds against IronLanguages/dlr main unpinned, and main has moved past 522bf37 to 6f0a52a. Its interpreter now runs interpreted catch handlers outside of the CLR catch block (#371) and rethrows an exception that a frame has no handler for, once the finally blocks on its way have run, through ExceptionDispatchInfo.Capture(pending).Throw(). That keeps the frames the exception came through and adds those it is rethrown from, the first of them ExceptionDispatchInfo.Throw itself, which RubyStackTraceBuilder only hid in a process without dynamic code. Built against that DLR (Build/dlr-patches apply cleanly), every backtrace of an exception leaving an interpreted frame began with ":0:in 'Throw'": IronRuby.Tests Backtrace2, 3 and 6 failed, and spec/language had 2 failures (heredoc_spec, rescue_spec) and 24 more expectations. The frame is bookkeeping, never a Ruby one, so it is hidden always. The same went for Ruby code calling ExceptionDispatchInfo.throw itself, which printed two such lines above its own frames. IronRuby.Tests Backtrace8 (an ExceptionDispatchInfo.throw from a Ruby method: the method's frame first, no 'Throw' line) fails without this on the private DLR too. Against upstream main 6f0a52a plus the patches, in the Debug configuration ci.yml builds: spec/language 2934 examples, 0 failures, 0 errors; the C# suite 0 FAILED. On the private DLR nothing changes: spec/language 0F/0E on R2R and IL, the C# suite 0 FAILED.
Conflicts resolved keeping both sides: - JIT/OSR element access: master's hoisted-Array OSR path (1b34198) and w4's object intrinsics (4064784) did the same thing with two undo logs and two JitUndoLog classes. The merge keeps w4's general mechanism (Hash and Array, mark-based per-thread log, method JIT and OSR, qualified constants) and drops master's duplicate ArrayLocal/LoopEntry/OsrArray path; master's Float#to_i and its verbose bail reporting are kept. - Refinements (6e0279c) reach the w4 code: TryCompile/TryCompileLoop and JitStub.Wrap take the definition refinements as well as the declaring scope and hints; JitRuntime.Disabled is gone everywhere. - RubyCallAction.BindPrecompiled: a refinement-sensitive call gets only master's refined dispatcher, never one of w4's first-call dispatchers. - RubyMethodInfo: GetClrDispatcher (w4) and GetRefinedDispatcher (master) share one private GetDispatcher. - RubyMethodGroupBase: master's nil-block restriction subsumes w4's 17f72cb. - Loader/RubyUtils/PrismAstBridge: startup-library registration, phase timers and master's prelude-thread and shebang changes together. - LibraryDispatcher: CreateDefaultInstance is gone on master; the value-type construction it excluded is now RubyOps.CreateDefaultValue<T>. - Util/jit-matrix.rb: both new sections. Generated files rerun: AotSubclasses (Monitor is C# on master).
Two of master's Hash changes met w4's Hash intrinsics, which work on the storage directly: - A new key while the hash is iterated is a RuntimeError on master (MRI's RHASH_ITER_LEV). HashStoreInt/HashStoreObj appended it anyway: a hot `h[k] = v' inside h.each added the key with no error. They now deopt, and the generic store raises. - IdentityComparer hashes an Integer as a BigInteger on master, so that a Fixnum-range long finds the same entry. JitFindFixnum still used the Int32 itself for a compare_by_identity hash, which is not BigInteger's hash code for -2**31: a hot h[-2**31] answered nil and key? false. Both now use IdentityComparer.FixnumHashCode. HashIteration_JitStore1 and HashIdentity_JitFixnumKey1 fail without this.
Master made Hash#fetch the core's IDictionaryOps.Fetch (d5b85e5) and dropped the prelude override, which is what w4's fetch intrinsic recognized (IsPreludeHashFetch). After the merge every method calling h.fetch bailed with "fetch on a Hash": the Hash half of the intrinsic was dead. It now accepts the library method, whose answers it already gives (the value, d for fetch(k, d), and a deopt to the generic call, which raises, for a miss). The KeyError the library method raises was not seen by a TracePoint on :raise, which only Kernel#raise reported; the prelude raised it from Ruby, MRI through rb_exc_raise. Fetch reports it now. jit-matrix's "TracePoint [:raise] on specialized methods" differed from CRuby ([] instead of 100 raises) and is identical again. HashFetch_Jit1 and HashFetch_TraceRaise1 fail without this.
Master's OSR array path (1b34198), which the merge replaced with w4's intrinsics, sampled an indexed Array's elements and unboxed them. w4 speculates an element to be a number only next to a typed operand, so `b[i] = b[i] + a[i]' (Util/osr-array-matrix.rb:103, two_stores) went unspecialized after the merge. In an outlined loop, two element reads of locals whose Arrays sample as all Integers are now speculated as Integers (a deopt corrects a wrong guess). osr-array-matrix is identical to CRuby and that loop is specialized again.
The C# test host loads no prelude: Hash#inspect is the old {1=>1} form and
KeyError is undefined there. HashIteration_JitStore1 prints g.to_a and
HashFetch_Jit1 checks hits and defaults only. HashFetch_TraceRaise1 is dropped
because it needs KeyError; Util/jit-matrix.rb's "TracePoint [:raise] on
specialized methods" covers that against CRuby.
|
Important Review skippedToo many files! This PR contains 105 files, which is 5 over the limit of 100. To get a review, reduce the PR to 100 files or fewer by splitting it into smaller PRs or changing its base branch. Upgrade to a paid plan to raise the limit. This review couldn't start because sufficient usage credits or metered capacity aren't available. Add credits or update usage-based reviews in the billing tab, then retry.
|
Merging master dropped its load-once OSR Array path (1b34198) for the element intrinsics, which check the receiver's CLR type and the process-wide "no singleton #[] anywhere" flag on every access. Renderer loops ran 15-25% slower than master, and the method JIT, which now takes methods like the pixel blit that master left to OSR, ran their loops through the same intrinsics. An outlined loop again loads each local it indexes and does not write, once on entry (JitRuntime.OsrArray: exact RubyArray, Array itself its immediate class), and reads it with ArrayGet, elements unboxed to the sampled type through a guard; stores go through ArrayStore into the shared JitUndoLog. A method body does the same for a parameter the profile only saw hold an Array and the body never assigns: loaded at the top, deopting there if it is not a plain Array. A loop that also writes such a local, or a method body that cannot deopt, is compiled again without, through the intrinsics as before. The check is per Array, so a singleton #[] on one Array no longer keeps every other one generic: Util/osr-array-matrix.rb lines 242 and 286 are specialized again. Doom-shaped loops (/root/workspace/pr2/bench r-*.rb, Release, pinned): blit 1.99 -> 1.49-1.59 s (master 1.59-2.04) shade 1.85 -> 1.23-1.33 s (master 1.44-1.71) add2 0.82 -> 0.52-0.60 s (master 0.61-0.65)
The method-mode load was only used by element stores: reads (a[i] on a call) were still gated to outlined loops. With them, the pixel blit that the method JIT takes (master leaves it to OSR) reads its two source Arrays directly: r-blit 1.49-1.59 s -> 1.29 s (master 1.59-2.04). Util/osr-array-matrix.rb gains a method-JIT section: an Array parameter that turns frozen, a subclass, one with a singleton #[], a Hash, an element of another type, a short Array, and a parameter the body reassigns. CRuby, Release and -X:NoJIT -X:NoOSR print the same.
The merge from master took out the Ruby 1.9 library tree and the old parser, and the R2R host has been built without IronRuby.Startup.dll since: IronRuby.Aot no longer compiled (IronRuby.Compiler.Parser, its fallback parser), and startup-files.txt still listed complex18.rb and rational18.rb. The build only warned. Prism is the only parser now, and neither file is loaded at startup any more. IR_CONFIG=R2R ./ir.sh -e 1 (7 runs, median): 0.64 s without the library, 0.51 s with it.
# Conflicts: # Src/IronRuby.Tests/RubyTests.cs
This was referenced Nov 4, 2026
LibraryFunctionCall.Call was a switch over every shape, 5 KB of IL and 29 KB of Tier0 code with hundreds of GC-tracked temporaries. A library call a dispatcher makes stays on the stack while the method runs, so a script whose main loop runs in a block it calls once (Proc#call through a LibraryDispatcher, as Util/bench does) keeps that Tier0 frame under the loop for good, and every garbage collection decodes and reports its untracked slots twice (mark and relocate). Each shape's call is now a method of its own, called through a table of function pointers from Invoke, so the frame under the callee is a few bytes. gen0 pause, median of every gen0 GC in the timed section (Release IL, scale 3, bench-lock, 4 interleaved runs, vs 0c6f725): yield_0 232-248 -> 218-228 us block_pass 241-265 -> 236-254 us
This was referenced Nov 9, 2026
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.
Brings the w4 speedup round into master: wider JIT/OSR coverage, rule-free first calls, and a precompiled startup library. Current master is merged in.
What it brings
case/when, constants (C,::C,A::B), and Hash/Array element access, with a per-thread undo log. Integer-vs-Float comparisons are exact.IronRuby.Startup.dllis built together with the R2R host. It precompiles the prelude, rubygems and the common stdlib, and is on by default.Numbers
Measured in the w4 integration (sp/w4-int against speedup 97fe918), not re-measured after the master merge:
ir -e 1startup (median)require "set"/"json"case_whencase_when_classarray_indexMerge notes
Fixes found while merging
compare_by_identityhashes are found again.Hash#fetch(now C# on master) is specialized again, and its KeyError fires TracePoint:raise.b[i] = b[i] + a[i]over Integer Arrays.Verification (reduced gate set on e6f23da)
Not run on this head:
The pre-merge w4 tip passed all of these.
Trade-offs and known gaps
Array#[]. One anywhere stops Array specialization for the whole process; master checks this per loop entry. Output stays correct.Follow-up fixes (d03c1b1, f838711, d786ea5)
Array loops are back to master speed or better. Master's load-once Array path is restored on top of the shared undo log, for outlined loops and for method bodies with an Array parameter they never assign. The check is per Array, so a singleton
#[]on one Array no longer keeps the others generic; osr-array-matrix lines 242 and 286 specialize again.Doom-shaped loops, Release:
The startup library builds again. Since the master merge, the R2R host had shipped without IronRuby.Startup.dll: IronRuby.Aot used the removed old parser, and startup-files.txt still listed the deleted 1.9.1 files. With the library back,
ir -e 1takes 0.51 s instead of 0.64 s (a sanity check, not run under bench-lock).Gates on d786ea5:
Still open:
#[]still turns off the general element intrinsics (written locals, non-parameter receivers); only the load-once path checks per Array.GC pause on block_pass / yield_0 (64189b0)
LibraryFunctionCall.Callwas a single switch over 160 shapes: 29 KB of Tier0 code with hundreds of untracked GC slots.🤖 Generated with Claude Code