assemblyscript icon indicating copy to clipboard operation
assemblyscript copied to clipboard

Add a `memory.grow` handler in the RT

Open CountBleck opened this issue 2 years ago • 4 comments

Changes proposed in this pull request: ⯈ Add an optional handler for calls to memory.grow() in the RT. ⯈ Unrelatedly, skip fixture comparisons in tests if compiling them failed.

The question remains whether this could somehow be used within ESM bindings.

  • [x] I've read the contributing guidelines
  • [x] I've added my name and email to the NOTICE file

CountBleck avatar Sep 30 '23 20:09 CountBleck

User can directly call memory.grow(N) intrinsic at some place. So I guess better to patch this built-in intrinsic (in compiler) instead add this handler to all memory runtimes

MaxGraey avatar Sep 30 '23 21:09 MaxGraey

Good point, although I thought that would be a niche case in comparison to the RT growing memory.

Do you think a handler can/should be integrated with ESM/raw bindings to reduce the use of try-catch and repeatedly creating views?

CountBleck avatar Sep 30 '23 21:09 CountBleck

Do you think a handler can/should be integrated with ESM/raw bindings to reduce the use of try-catch and repeatedly creating views?

I'm not sure what is a better solution. Previously, we used similar approach (without try-catch + views) and that was may be a little less code but slower. I would do a some simple PoC and bench this first

MaxGraey avatar Sep 30 '23 21:09 MaxGraey

It can give more freedom to hook memory grow.

Honestly the only use case I'm targeting is handling views of the Wasm memory being detached on memory.grow() in JS. Someone (who does not use ESM bindings) in the AS Discord wanted some way to detect when memory has been grown for that same use case.

I want to expand that into something that works with ESM bindings as well. I don't see the point in widening it to anything more general.

Therefore, it's probably better to scrap what I have in this PR right now and figure out something that works for detecting grow events in at least ESM bindings.

CountBleck avatar Oct 01 '23 01:10 CountBleck