This PR replaces two functions that cause a lot of slowness due to running a lot of BigDecimal operations with more efficient versions.
fastExponentiation replaces the bigDecimalExponated with an implementation of exponentiation by squaring in order to get the number of multiplications from O(N) to O(log N) on the power. This is particularly effective for large powers in the hundreds or thousands.
exponentToBigDecimal replaces the 10^N computation with a string-based implementation. This sounds weird at first, but it helps with performance because it replaces N calls to BigDecimal operations with only one at the end.
A possible further optimization to the fastExponentiation is to expose that as a WebAssembly host function at the graph-node level. This should help optimize performance further by removing the need to pass BigDecimal values back and forth between the AssemblyScript handler function and the Rust BigDecimal.times host function.
This PR replaces two functions that cause a lot of slowness due to running a lot of BigDecimal operations with more efficient versions.
fastExponentiation
replaces thebigDecimalExponated
with an implementation of exponentiation by squaring in order to get the number of multiplications from O(N) to O(log N) on the power. This is particularly effective for large powers in the hundreds or thousands.exponentToBigDecimal
replaces the 10^N computation with a string-based implementation. This sounds weird at first, but it helps with performance because it replaces N calls to BigDecimal operations with only one at the end.A possible further optimization to the
fastExponentiation
is to expose that as a WebAssembly host function at the graph-node level. This should help optimize performance further by removing the need to pass BigDecimal values back and forth between the AssemblyScript handler function and the RustBigDecimal.times
host function.