Skip to content

Diamond 0.28.0

Choose a tag to compare

@github-actions github-actions released this 07 Nov 03:49
· 260 commits to main since this release
7cf5178

Changed

  • Cheaper getter and setter calls. A call site that keeps reaching the same attr_reader,
    attr_writer or attr_accessor method on the same class now remembers that it is one, and
    later calls read or write the field after a class check and a value check, skipping the method
    lookup's per-call checks. Typed and untyped receivers both benefit, and errors (a wrong-typed
    value, a frozen receiver) are the same as before. The n-body simulation runs about 13% fewer
    instructions (8% fewer cycles), building and walking trees 5% fewer cycles, and struct- and
    object-heavy code 2-5% fewer.
  • Cheaper class-typed getters and call results. A getter declared as one class, with or
    without Nil (attr_reader left: Node | Nil), now checks its value with one class comparison
    instead of walking its declared type each call; a subclass instance or a wrong-typed value
    still gets the full check and the same error. Method, function and == call results are
    copied back in a form the processor can forward straight from the callee's stores. The
    n-body simulation runs about 10% fewer cycles, object- and struct-heavy code 4-5% fewer, and
    building and walking trees about 3% fewer.
  • Cheaper new for simple constructors. An initialize that only checks its parameters'
    types and copies them into fields (def initialize(x: Int, y: Int) @x = x; @y = y end, and
    every struct's) no longer runs as a method call: new checks the arguments and fills the
    fields directly. Any argument it can't settle at once runs initialize as before, so errors
    and backtraces are unchanged. Struct-heavy code runs about 17% fewer cycles, object
    allocation 13% fewer and building binary trees 8% fewer. With DIAMOND_TRACE_JIT, such
    constructors no longer appear among the compiled functions, since they never run.
  • Cheaper short Strings and Arrays. The collector keeps swept Strings of up to about 100
    bytes, sorted by size, and swept Array headers for the next allocations instead of returning
    them to malloc, as it already did for small instances; together the pools stay within one
    nursery's worth of memory. Regexp#match also collects its group positions on the stack and
    builds its result Array at its final size. Text processing runs about 34% fewer cycles, regular
    expressions 28%, Hash-heavy code 23%, String building 20% and exception handling 17%.
  • Faster regular expressions on ASCII text. The matcher steps over an ASCII character and
    tests \w against it without asking the UTF-8 decoder, which it used to call for every
    character. Results are unchanged for all text; mostly-ASCII input matches about 15% faster.