Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a memory.grow handler in the RT #2755

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

CountBleck
Copy link
Member

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.

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

This handler can be used with an import for users not using ESM bindings
to recreate views into memory only when necessary.
If the test is supposed to compile, but compilation fails instead,
there's no point in diffing fixtures (unless you like a wall of red in
your terminal). It also turns out that execution never reaches the
diffing section, since writing the non-existent debug Wasm binary fails.
@MaxGraey
Copy link
Member

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

@CountBleck
Copy link
Member Author

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?

@MaxGraey
Copy link
Member

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

Copy link
Member

@HerrCai0907 HerrCai0907 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think it is more convenient for developer if we have a function memory_grow which will call memory.grow. Then developer can replace this function just like replacing trace.
It can give more freedom to hook memory grow. They can hook before and after memory grow.

@CountBleck
Copy link
Member Author

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 CountBleck marked this pull request as draft October 1, 2023 01:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants