You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This commit was created on GitHub.com and signed with GitHub’s verified signature.
Changed
Cheaper calls. A call no longer copies its arguments into a fresh register block when they
already sit in order, which a single argument always does. A typed function's parameter checks
run as a few inline tests on entry instead of one dispatched instruction each when the types are
simple (Int, Float, Bool, String, Symbol, an exact class, or one of these or Nil); anything else,
such as a subclass instance, still goes through the full check with the same error. And a body
ending in a ternary returns straight from each branch. Recursive fib runs about 11% fewer
instructions and cycles, building and walking binary trees about 9% fewer instructions, and
object-heavy code 2-3% fewer.
Cheaper objects. Reading or writing an instance variable checks the instance's shape directly
instead of going through a per-site cache, a trivial getter or setter is recognized once per
program instead of on every call, and the collector keeps swept small instances (up to eight
fields, at most one nursery's worth) for the next allocations instead of returning them to malloc. Allocating a million small objects and calling a method on each runs about 16% fewer
cycles; struct-heavy code 15% fewer, building and walking trees 10% and an n-body simulation 18%. DIAMOND_TRACE_FIELDS, which reported the field cache's hits and misses, is gone.
Cheaper call setup. Each function's call context is built once when a program starts instead
of on every call into it, a warm method call site makes the whole call in one cache lookup, and
a method call's arguments are copied without a library call. A method call costs about 150 fewer
instructions. Closures and object-heavy code run about 8% fewer instructions, struct-heavy code
4%, exceptions 6% and an n-body simulation 4%. The call-site caches are now 8-way, so a program
whose hot call sites happen to share a set no longer evicts one on every pass. Reading an
instance variable no longer makes a function call (polymorphic shape code 4% fewer
instructions), and a body ending in a ternary returns a parameter or local from its true branch
without copying it first (recursive fib 3% fewer).
Typed fields. The compiler now tracks Int and Float instance variables. When every write to
a field stores an Int (or every write a Float), the class's own initialize sets the field
before anything else runs, and nothing else can write it (no subclass, no module writing fields
by name, no define_method or compile_method), reading the field is known to give that type.
Arithmetic on such fields uses the Int fast paths, and a method or generated attr_reader
that returns one skips its return check. A call to a method defined further down the class now
knows that method's declared Int, Float, String, Bool or Symbol return, as it already did for a
method defined above. Object-heavy code runs about 5% fewer instructions, polymorphic shape code
6% and an n-body simulation 3%.
Fixed
A program with more than about 245 classes could fail to compile with an error like expected Target, got Int on a method returning an instance variable of class type: the
field's class was stored as an 8-bit type id.