Make sbrk(0) deterministic#115
Conversation
sunfishcode
left a comment
There was a problem hiding this comment.
Good spot! That's a really subtle issue.
|
Is there any fundamental reason why Did you observe it being slower in v8? (or in any specific engine?) I agree this change makes sense, I just don't understand why an engine wouldn't do exactly the same thing internally? |
|
IMO the problem here is that the WASM spec doesn't guarantee that |
|
@sbc100 Maybe I wasn't fully correct. Of cause, they could just check that delta == 0 and then return current size. But in v8 source code they don't do this (https://github.com/v8/v8/blob/4b9b23521e6fd42373ebbcb20ebe03bf445494f9/src/wasm/wasm-objects.cc#L1240). So, I just meant that developers could forget to make this check. And this behaviour would be correct according to the standard. @AndrewScheidecker I also think that the spec must specify this behaviour, but changing Wasm spec isn't so fast? Anyway, I think it worth to create an issue in the spec. |
|
Agreed; this a correctness issue. The spec process does take time, though the other question here is whether the CG would be willing to cause existing conforming implementations to become non-conforming. An implementation which doesn't support |
The Wasm spec doesn't specify explicitly the behaviour of
memory.grow 0. And because ofmemory.grow 0could potentially be non-deterministic. From the other side, WASI dlmalloc heavily relies on it. So, it seems that it is better to make sbrk(0) deterministic.Also
memory.sizeis much faster on many execution environments, since memory could shared and some code with locking could be called (like in v8).