Skip to content

Questions and answers

Daniel Wirtz edited this page Feb 22, 2019 · 24 revisions

A collection of answers to questions that appeared over time.

What's the difference between an if/else and a select?

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.

Is it possible to override WebAssembly's start function?

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.

 

Clone this wiki locally