-
-
Notifications
You must be signed in to change notification settings - Fork 670
Questions and answers
A collection of answers to questions that appeared over time.
By annotating a top-level function with the @start
decorator, any top-level statements of the program will not execute until the first time this function is called. Also means that the first thing to do with a module must be calling this function. This is useful in scenarios where memory isn't imported but top-level code already prints strings for example, as there is no way to access memory (and thus the string's characters) until module instantiation is complete otherwise.
How much does the runtime add to a binary?
The full
runtime adds about 2KB to your binary after optimizations. This includes a proper memory manager and a complete reference counting implementation with deferred cycle collection. Where external creation of managed objects is not necessary, i.e. where no interaction with the JS-space takes place, this can be reduced by using the half
runtime instead, which doesn't have any implicit exports so the optimizer can more easily eliminate dead code. In scenarios where free/GC support isn't required, for example in very short-lived programs or programs with hardly any memory footprint, the stub
implementation can be used instead that only provides a very basic arena memory allocator without any means of freeing up memory again. Similarly, the none
runtime is essentially stub
without any exports, essentially evaporating entirely after optimizations.
Semantically, a select
differs from an if/else
in that both alternatives are always executed, then picking one of them depending on the condition. So if one side has side effects, it is going to happen regardless of the condition. Performance-wise, a select
(conditional move, works similar to a switch) is expected to be faster than an if/else
where the condition is random (that is, branch prediction is not going to perform well) and the operands are cheap. An if/else
where branch prediction is doing well, for example where checking a configuration value that is always the same, is expected to be fastest.