Skip to content

What is the correct way of resetting the heap when using "stub" or "minimal" runtime? #2736

Closed
@UstymUkhman

Description

@UstymUkhman

Question

First of all, I'd like to thank you for maintaining this awesome project. I've really enjoyed working with AssemblyScript, great job!

After implementing what I thought was a perfect algorithm for WASM, I realized that the result was a lot slower than it's counter part written in TypeScript. I made some research and tested several tricks aimed to improve performance. As mentioned here and here some things did help. The unchecked() function most of them all, but I do use @inline whenever it makes sense and always cache arrays' length and use StaticArrays (even though it does not make much difference in my tests comparing to Float32Arrays or Uint8ClampedArrays, I decided to stick with it in order to avoid missing some optimization technique). I compile with --optimize -O3 and converge and noAssert are both set to true. Unfortunately none of that helped and the AS version is running ~10 times slower than TS counterpart.

Then I've read this fantastic article and it seamed like one last thing to do is to play with runtime options. Indeed using minimal helped a bit. For instance, TS version takes on average 0.08 seconds to render a frame, incremental runtime takes ~0.55 seconds, minimal takes ~0.31 and with stub it's about 0.17 seconds. Now, I know that with minimal & stub runtimes I'm supposed to clean memory manually and according to this, "free all memory at once" would probably work best for me, but I'm not sure how to do that since there is a heap.reset() method in documentation but it seems to be missing in the APIs. Maybe it's deprecated and I'm supposed to use only heap.free(ptr: usize), but I'm not sure how that works? How can I get the ptr to my StaticArray let's say..?

Another possible optimization I was thinking about is to use a less OO approach (maybe starting from Vector3 class) since it seems to me like WASM doesn't play nice with objects so maybe it's worth testing with raw functions even though the original idea was to mimic as much as possible TS version and I don't even know if that might help, maybe you guys have some tips on that?

Sorry if that was too long, I'll leave some more info here if someone has time to take a look and hopefully suggest some further optimization, it would be much appreciated, thanks a lot!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions