Repository navigation
Diamond 0.25.0
Changed
-
sortis native for Int and String arrays. A blocklesssortof an array whose elements are
all Ints or all Strings now runs in C: building and sorting 50,000 Ints ten times went from 1.26 s
to 81 ms. Anything else (a block, mixed kinds, Floats, big integers, nested arrays) sorts as before. -
The JIT compiles
%and Float arithmetic. A function using%or a Float literal used to
stay in the interpreter; both now compile, and Float-with-Float+ - * /and comparisons run
as native SSE2 code. A tight Int loop with%runs about 6x faster underDIAMOND_JIT=1, and a
Mandelbrot loop about 4x. -
Faster startup and recursive calls. Loading a cached program no longer formats its whole
bytecode while checking it, which halves the work a short script does at startup. A function
calling itself reuses its call context instead of rebuilding it, and underDIAMOND_JIT=1a
compiled function's call to itself skips checks that can't change; recursivefibruns about
19% faster with the JIT and 4% faster without. -
Method calls and untyped arithmetic are cheaper. A method whose body only returns an
instance variable (def x() -> Int = @x) is now answered by reading the field, without setting
up a call; return-type checks, arity, privacy and overrides behave as before. Int-,*and/
on values the compiler can't prove are Ints no longer take the big-integer path. An
object-heavy benchmark went from 457 ms to 339 ms and a block-heavy one from 378 ms to 349 ms. -
Array#mapandArray#selectrun natively. Their loop now runs in C and calls the block
directly, instead of through a d6 loop that paid for its own length, index and push calls on
every element.break,next,returnand exceptions inside the block behave as before, and
so do the error messages for a wrong argument.==and!=on two Ints that the compiler
couldn't prove were Ints no longer take the general comparison path. The block-heavy benchmark
went from 349 ms to 199 ms. -
Cheaper block calls,
push,length,sumandRange#to_a.mapandselectset up
their block's call once rather than once per element, and a block reads or assigns a variable
it captured without first re-checking that the variable is shared. Calls topushand
lengthskip about ten other method-name tests that used to come first. A blocklesssumof
plain Ints adds them in C, andto_aon a bounded Int range fills the array in C. Anything
else (a block, Floats, big integers, an endless range, overflow) works as before. The
block-heavy benchmark went from 208 ms to 123 ms. -
Blocks load only the outer variables they use. A block used to fetch every local variable
of the method around it on every call, whether it used them or not. It now fetches only the
ones its body names, unless it creates another block ordefor callsdebugger(). Debug
sessions still see every variable. The block-heavy benchmark went from 127 ms to 109 ms. -
Cheaper method calls. A warm call site that keeps seeing one class now goes straight to
the method it cached, without first testing the name againsttap,to_s,dupand the other
methods every object answers. A class that defines its owntaporto_sstill gets its own.
A typed parameter is checked without a function call when its value is exactly the declared
type or class. A plain method call (no type arguments, at most seven arguments) also goes
through fewer nested calls before reaching the method body. A loop of a million one-argument
method calls runs about 11% fewer instructions, and the object-heavy benchmark about 9%. -
Faster interpreter loop. Each bytecode handler now jumps straight to the next one through
a table instead of returning to one centralswitch. Arithmetic and comparisons with an Int
literal operand, such asi < 3000000,n - 1ori += 1, compile to a single instruction
instead of a constant load plus the operation, and each Int operator has its own handler
rather than sharing one that tested the opcode again. A typed parameter declaredIntor
Floatis checked without a call. The counting loop benchmark went from 1330 ms to about
720 ms, recursivefibfrom about 500 ms to 340 ms, and the object-heavy one from 376 ms to
about 300 ms. JIT-compiled code is unchanged.
Fixed
- Return annotations naming a later class. When a method's return annotation named a class
declared further down the file, a later caller checking that method's result against the class
failed to compile with "expected R, got Nil". It now compiles, and a real mismatch is still
reported with the right class names.