Skip to content

Nihil v4.15.0

Choose a tag to compare

@github-actions github-actions released this 28 Nov 15:23
· 41 commits to main since this release
3446410

Tables are read and written several fields at once, maps and sorting take fewer calls, a division by a constant becomes
a multiplication, and on a Mac a program of more than 1 MiB of code is assembled. bench/workload (1,000,000 sales, an
M4, the release packages one after the other) went from 175 to 139 ms: 0.9 times C (151 ms) and 0.5 times Go (263 ms);
from v4.12, 286 ms, it is twice as fast. The same program's peak memory went from 149 to 157 MB. In a real program
(a planogram generator of about 1 GB), the gain is 1 to 3%: its time goes elsewhere. The ARM64 backend is now checked
on every push and pull request (macos/ci-native.sh). The translator of the x86-64 code (NIHIL_TRANSLATE=1) stays
until v4.16.

  • macOS: every push and pull request builds the compiler straight into ARM64 from the latest release's, checks its
    fixed point and runs the tests as usual, without optimizations and with the collector under pressure
    (macos/ci-native.sh, the macos-native job of tests.yml)

    • Why: Until now only the release workflow ran the ARM64 checks: a change could break the Mac's backend and be
      seen only at the next release
  • Tables: writing a record takes its usual fields (INT from 0 to 10^8 − 1, BOOL, STRING that fits) in a function that
    calls nothing, so its values stay in registers, and the rest (FLOAT, a field that does not fit) goes on from the
    first such field as before; reading one, the table calls the native parse straight away, one call a record
    instead of three; the same bytes and the same errors

    • Why: The error messages made the whole of rec_put call other functions, so every field's type, width and value
      went through memory. bench/workload's table, 1,000,000 sales, on an M4 with -native: written 43 → 39 ms,
      read 37 → 35.5 ms; 5% fewer instructions for the whole run
  • -native (macOS): a program of more than about 1 MiB of code is assembled (its conditional jumps that do not reach their target, 1 MiB at most, become the opposite jump over a plain b); a comparison with a small constant takes its immediate form (cmp x24, #0, cmn x0, #1)

    • Why: The error stubs and the runtime's routines sit at the program's end: in a larger program, clang stopped with
      "fixup value out of range" (a top level of 6,500 lines had 151 such jumps). Smaller programs come out the same
  • Writing a record (@>> path, rows, $r): an INT field of up to 8 digits, not negative, is made with no loop per
    digit (4 + 4, 2 + 2, 1 + 1 by multiplications, the zeros before the first digit turned into spaces at once) and each
    byte of the field written once, instead of spaces first, then a loop to count the digits and another to write
    them; the same bytes and the same errors

    • Why: How many digits a number has changes from record to record, so those loops' exits were mispredicted
      several times a record. bench/workload's table written from 1,000,000 sales: 56 → 45 ms on an M4 with -native
      (−6% cycles for the whole program, though 3% more instructions)
  • -native (macOS): reading a table, an INT field of up to 8 bytes, right-aligned, is read in one go (its 8 bytes at
    once: blanks and digits by masks, the value by three multiplications) instead of a byte at a time, and the record is
    taken from the allocation run without zeroing it first (every word is written right after)

    • Why: The byte loops miss their branch prediction once a field (the blanks and digits change from row to row).
      bench/workload's whole run, 1,000,000 sales: 634 → 598 M cycles on an M4
  • sort(key) copies the keys once, each beside its element's index, merges those pairs (one loop per kind of key)
    and starts from runs of 8 sorted by insertion: 1,000,000 records sorted 30% faster by an INT key (97 → 68 ms on an
    M4) and 26% by a STRING key (273 → 203 ms); the same stable order.

  • maps: m[k] = (m[k] || d) + e; with a STRING key finds its slot inside the one call (the hash and the look-up
    written out, the same slots as before) instead of calling the look-up, which called the hash

    • Why: Three calls a sale became one. bench/workload's units by product name over 1,000,000 sales: 16 → 13 ms on
      an M4 with -native; the map phase 38 → 35 ms
  • On a Mac (-native), a division or rest by a constant that is not a power of 2 becomes a multiplication
    (smulh, Granlund and Montgomery: the smallest multiplier that fits, loaded once before the loop), and writing a
    number in decimal takes one division per digit, not two: a chain of x / 10 and x % 10 35% faster (0.20 → 0.13
    s on an M4), bench/workload's JSON phase 11 → 10 ms.

  • -native (macOS): v[] = x, v[i] and v[i] = x on a LIST are done in place when the list has room or the index is
    within it, calling the prelude only to grow the list or to report the index; an allocation takes the next block of
    a run of free ones instead of looking for one each time

    • Why: A push went from about 66 to 12 instructions. bench/workload's price dispatch
      (rules[s.product % 4].total(...)) over 1,000,000 rows: 6 → 4 ms on an M4. The make-up phase keeps its time: it
      is bound by fresh memory and the collector, not by instructions

Install

curl -fsSL https://nihil-lang.dev/install.sh | sh

Linux x86_64, and macOS on Apple silicon (with the Xcode Command Line Tools).

Each package has a build provenance attestation: gh attestation verify nihil-linux-x86_64.tar.gz --repo nihillang/nihil.