Assemblyscript: Maximum call stack size exceeded when compiling optimised code

Created on 10 Jun 2020  路  13Comments  路  Source: AssemblyScript/assemblyscript

I get a weird error when compiling my code with optimisation flags -O3 --noAssert
Unfortunately I have not succeed reproducing the issue with a simple code fragment...
My codebase is in this repository: https://github.com/alexvictoor/HdrHistogramJS

If I run "npm run asbuild:optimized" adding a --noAssert flag compilation fails.
If I remove the call to clz() and replace it by the commented code fragment below, everything is fine...

bug released

All 13 comments

I guess it relate to inlining passes. Could you try use --noAssert but instead -O3 use -O3z?

Btw this line:

const ulp = (x: f64): f64 => Math.pow(2, Math.floor(Math.log2(x)) - 52);

you could rewrite to:

export function ulp(x: f64): f64 {
  if (x == Infinity) return x;
  return Math.abs(x - reinterpret<f64>(reinterpret<u64>(x) ^ 1));
}

It will be more efficient and probably smaller in term of codesize if you don't used pow / log2 before. However I'm not sure is it method used before and how important is it.

@MaxGraey Is this a Binaryen issue or is there something wrong on our end?

I don't know. It was my guess. Didn't play with it yet

Thanks for your responses!
@MaxGraey compilation works fine with --noAssert and -O3z
Let me know if I can do something else to help

Math.abs(x - reinterpret<f64>(reinterpret<u64>(x) ^ 1))

Thanks for the tip!

I have just tried v0.11
I get the same "Maximum call stack..." compilation error when I only use the -O3 flag without the --noAssert flag.

It will be really help if you somehow isolate a problem to minimal example. Your project is pretty big. I recommend start looking to recursive called methods/functions

Btw it seems it's problem with generate sourcemaps. If I remove --sourcemap issue is gone.
@alexvictoor did you try this?

So it seems this part in std/portable.js:

String["fromCharCodes"] = function fromCharCodes(arr) {
  return String.fromCharCode.apply(String, arr);
};

Cause to problem. Going to fix this.

@alexvictoor btw this could be also optimized as:

const percentileReportingTicks = 
  this.percentileTicksPerHalfDistance *
  f64(1 << (31 - clz(i32(100 / (100 - this.percentileLevelToIterateTo))) + 1);

if this.percentileLevelToIterateTo guaranteed in range [0, 99.9999999]. Btw I guess percentileLevelToIterateTo should have i32 type. In this case cast to f64 unnecessary

:tada: This issue has been resolved in version 0.12.0 :tada:

The release is available on:

Your semantic-release bot :package::rocket:

I have just tested v0.12 and the issue seems to have disappeared.
Sorry again, it was quite difficult to isolate the problem...
Thanks @MaxGraey for the tips

Was this page helpful?
0 / 5 - 0 ratings

Related issues

torch2424 picture torch2424  路  5Comments

DanielMazurkiewicz picture DanielMazurkiewicz  路  4Comments

emil14 picture emil14  路  3Comments

Iainmon picture Iainmon  路  3Comments

DuncanUszkay1 picture DuncanUszkay1  路  3Comments