Skip to content

0.18.0

Choose a tag to compare

@benoitc benoitc released this 03 Dec 00:31
· 16 commits to main since this release
9079075

A guest that runs its own JIT, such as an emulator, now keeps the blocks it
makes compiled and calls them compiled, and a module only called from
another instance gets compiled. A large module takes a fraction of the
memory it took and loads faster, and compiled code runs faster. Also fixed:
compiled code no longer adds atoms that depend on the guest's code, a node
no longer aborts when the module cache fills its literal area, and on Linux
a UDP socket talks from the right address after it reconnects. Compiled
code cached by 0.17.0 is compiled again and unit files must be built again;
core and component images stay valid. The module cache now holds at most
half the node's literal area, 512 MiB on a node started without +MIscs,
and code that reads #func.body reads a new form. The upgrading page has
what to change.

Changes

  • New: a module only called from another instance gets compiled. A
    module nothing called directly was never compiled, however often it ran.
    For a module of 256 functions or fewer, calls from another instance now
    count toward compile_after, so it compiles like one called directly,
    and compile_after => 0 compiles it as soon as it is instantiated.
  • Fixed: compiled code added atoms that depended on the guest's code.
    Each function the compiled tier compiled left behind atoms named after the
    shape of its code, and a node never frees an atom. Compiling many different
    modules, or a guest that keeps making code as a guest JIT does (about sixty
    atoms for each block), grew the atom table without bound until the node
    could stop. Compiled code now takes its names from a fixed set.
  • Fixed: a module that was never validated could run another module's
    compiled code.
    Every module built without wasm:compile/1 or
    wasm:load/1, from a decoded or hand-made module record, looked the same
    to the compiled tier, so the second one compiled could run the first one's
    code. Such a module now always runs interpreted.
  • Fixed: loading more modules than the node's literal area holds aborted
    the node.
    Cached modules live in the literal area, 1 GiB unless the node
    is started with +MIscs, and the cache allowed 2 GiB, so a node loading
    large modules wrote a crash dump and stopped. The cache now holds at most
    half of that area and refuses a load that would not fit with
    module_cache_full. Start the node with a larger +MIscs to cache more.
  • Fixed: an image file whose globals or tables are not its module's
    failed only when restored.
    Such a file, which only a hand-made or
    damaged one can be, loaded, and its restore failed with internal. It is
    now refused when it is loaded, with snapshot_wrong_shape, so a worker
    treats it as no image and captures.
  • Fixed: on Linux, a UDP socket kept the local address of its first
    peer.
    A guest socket that talked to the loopback address and then
    connected over IPv6 to a peer on the network went on sending from the
    loopback address, and reported it as its local address, so the peer could
    not answer. A disconnected socket also lost its port and stopped hearing
    what was sent to it. Each connect now takes the local address of the route
    to its peer and keeps the port, and a connect that fails leaves the socket
    with the peer it had.
  • Faster: a call into another instance runs its compiled code. A
    function reached through a table or a function reference from another
    instance, such as a block a guest's own JIT made and placed in the guest's
    table, always ran interpreted, even when its module was compiled, and so
    did a call back into the caller. Such a call now runs the callee's
    compiled code at the caller's depth, unless the call is metered or the
    callee's max_depth differs from the outermost call's.
    wasm_jit:counts() counts it as entered.
  • Faster: a guest that makes many small modules keeps them compiled. At
    most 16 modules could have compiled code at once, and each new one took the
    slot of one nobody was running at that moment, which then ran interpreted
    for good. Small modules, compiled whole and of modest size like a guest
    JIT's blocks, now have 240 slots of their own; a free slot is used before
    any module's code is replaced; and a module whose code was replaced compiles
    again. An emulator guest with its JIT on now runs a sort in 45 s instead of
    101 s, a loop in 39 s instead of 109 s and a hash in 4.5 s instead of
    6.8 s. At most 16 compiles still run
    at once, and each small module's code is bounded in size, so the small
    slots hold about 270 MB at most by estimate.
  • Faster: compiling is quicker and compiled code runs faster. The
    compiled tier generates less code for each block, loop and branch, so a
    small module compiles in a little over half the time (0.56 times as long
    for the blocks a guest JIT makes), and the code it makes runs faster
    (QuickJS 6%, a tight loop about twice as fast). A function that declares
    many locals but uses few of them, which was left to the interpreter, now
    compiles.
  • Faster: a large module takes a fraction of the memory it took. A
    module of more than 256 functions decoded from bytes now keeps its function
    bodies as their bytes, instead of a tree of terms about thirty times their
    size, and reads each body from its bytes on its first call. That is what
    wasm:load/1 puts in the module cache: CPython's module went from 194 MB
    in the cache to 22 MB, and loading it takes 36% of the time it took.
    Putting an instance of such a module in persistent_term is about sixty
    times faster, and a function's first call takes about a fifth less time
    than it did. Code that reads #func.body through wasm.hrl reads a new
    form; docs/upgrading.md says what to call instead.
  • Faster: compiled loops pass fewer values. A loop's compiled code passed
    every value it reads from outside the loop again at every step. Those values
    now travel together, so compiled QuickJS runs about 9% faster, and SQLite
    is unchanged.