motoko
motoko copied to clipboard
perf: optimize `Array.tabulateVar`
using or re-using dedicated prim instread of this code in base Array.mo
public func tabulateVar<X>(size : Nat, generator : Nat -> X) : [var X] {
// FIXME add this as a primitive in the RTS
if (size == 0) { return [var] };
let array = Prim.Array_init<X>(size, generator 0);
var i = 0;
while (i < size) {
array[i] := generator i;
i += 1
};
array
};
Right now tabulateVar is an order of magnitude more expensive than tabulate (or so)
https://dfinity.slack.com/archives/CPL67E7MX/p1678194612815229?thread_ts=1678192911.487829&cid=CPL67E7MX