You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
From the November in-person meeting, we had an action item to reach consensus on implementation-defined limits such as the maximum size of a function or the maximum number of functions in a module.
Implementations need to converge on this and decide on the right limits. I believe that other than the function size (accidently not enforced in V8, e.g., but later enforced to 7654321 bytes), 4 browser implementations have adopted the same limits. This limits are not implemented in the reference interpreter.
We need to decide if these limits are part of the official Web embedding, and if so, add tests for them.
Just to check that we are on the same page: these would be web API tests and don't affect the reference interpreter, because embedder-specific restrictions don't belong there, right?
POLL: Should the limits be Web-embedding specific, or standardized for all of WebAssembly?
Given that non-web embeddings may have considerably greater hardware resources and exotic use cases, it seems audacious to extend web browser limitations to them.
There is an open question about how to interpret the limit on the number of locals. It appears that WebKit and v8 account separately for the number of parameters and locals (so, up to 10000 parameters; up to 50000 non-parameter locals). Firefox instead limits parameters (10000) and then the total number of locals+parameters to 50000 [sic]. This is probably a Firefox bug but it would be nice to settle this explicitly.
Should making a cross-browser decision on main thread synchronous compilation limits be part of this effort? In webpack/webpack#6433, we can see that WebAssembly packaging authors are hitting it; there's also a stack overflow thread where it looks like someone was reading a tutorial written for Firefox, and found it wouldn't work in Chrome. Is there a particular reason why the limit is applied in some browsers and not in others? I imagine users would benefit in terms of compatibility if we could come to agreement here.
On Tue, Nov 28, 2017 at 9:45 AM, Ben L. Titzer ***@***.***> wrote:
We need to decide if these limits are part of the official Web embedding,
and if so, add tests for them.
What does "web embedding" mean? Does this imply that it would apply to v8
in Chrome but not in Node? What about Atom? What makes a host a browser?
@erights, I suppose it's up to clients to decide what standards they implement, and whether they want to consider themselves a full "web browser" in the common sense of the term. Strictly speaking, we can only put out recommendations.
For context, Node implements some web standards, such as URL, and is considering more. On a practical level, these limits are implemented in JS engines, and, unless special support were added to bypass them, I think Node would get the same limits as the browser where the engine is embedded (whether we are talking about Chrome or Edge).
We discussed this issue in the April 12 Wasm WG meeting. The group agreed that we want to move forward on these limits, and that the next step is to write patches against the JS API and Web API for these limits, working out the details on GitHub.
I have now written some tests for these limits and run them against existing engines. I uploaded them to a branch and I'll have a PR ready soon.
Outcome so far: all engines agree on the limits which are written in the tests, except for two:
The maximum number of pages a module may specify for either initial or maximum memory size
(V8 enforces a smaller number than 64Ki, but probably shouldn't)
The enforcement of the maximum number of local variables
(JSC enforces the maximum number of local variables independent of the number of parameters, whereas the other 3 engines consider the parameters to be included).
I have updated the limits test in that branch with what I believe to be a now-final set of tests. The results are that all engines fail one or more minor checks, which I will summarize below.
For reference I have a CL ready for V8 that fixes our previous problem with enforcing a too-small memory pages size (both initial and maximum), while cleaning up the names in the code and making it clear what is specified. For the failures outlined below, I don't expect any engine's changes to be more involved.
To run it: % cat ../harness/wasm-constants.js ../harness/wasm-module-builder.js limits.js > /tmp/test.js && wasm-engine /tmp/test.js
@littledan The test above has a small bit of harness inlined, and I didn't try to get it to run in the browser. It might need to be adjusted to make it nice to run on a spec compliance page. Is that something you can handle?
V8:
With the above CL, V8 fully complies with the limits.
SpiderMonkey:
Enforces a smaller "initial memory pages" implementation-specific limit (should be 65536)
Allows a maximum table size over the limit (should be maximum 10000000)
Chakra:
Enforces a smaller "initial memory pages" implementation-specific limit (should be 65536)
Does not enforce the maximum locals = 50000 limit (or enforces a higher one, interestingly, only in the compile path, not the validation path)
JSC:
Enforces the limit of locals and parameters independently (i.e. parameters do not contribute to the limit of 50000 locals)
Allows a maximum table size over the limit (should be maximum 10000000)
As for enforcing a smaller "initial memory pages" value, IMO I think the engine should not make this a validation error, but should simply be an OOM condition when trying to instantiate the module.
As for the "maximum table size over the limit" issue, I think this is due to the existing js-api.js test attempting to instantiate a table with MaxUint32 entries. IMO the new WebAssembly.Table() constructor and the "binary way" of creating such a table with just a module should enforce the same limit. @lukewagner@jfbastien@MikeHolman thoughts?
I didn't test Chrome's synchronous 4KiB module compilation limitation. I guess this should come with a test somehow, but it was complicated, since Chrome doesn't enforce this limit, e.g. in some worker contexts. IMO that 4KiB limit isn't particularly useful but that's a different discussion.
I also did not test the overall 1GiB maximum module size limitation since it might hard to make a reliable test for this that doesn't already OOM just due to having a 1GiB typed array.
It seems reasonable to me that it now fails. What I don't understand is: that test
exists unchanged in the implementation_limits branch. So I would have thought it
would now fail on all engines. Either that, or I misunderstood something. Can you
clarify?
Just to clarify, is this a must or should support that many exports - on sufficiently resource-constrained devices (anywhere from embedded to mid-range mobile), the device might not have that much memory available, or in some cases, that much memory at all. And near the upper end of the infeasibility, you do have full JS environments with all the recent stuff, so it's not like you can assume most browsers have that much available.
IMHO, the branch adding the limits should specify web implementations "should, if sufficient memory exists", implement those limits, so this isn't an issue.
I'd be OK bumping the export limit to 1e6, simply because it matches the per-module function limit of 1e6. In some sense, it'd be odd to allow a module to have K functions but only be allowed to export K/10 of them.
There is a per-export cost when embedding in JS, since the engine must materialize JS functions for every export, though this can be done lazily. Currently V8 does this eagerly. The cost of an exported function is basically a JSFunction instance + a machine code thunk, but the machine code thunks are per-signature. We currently pay more for imports because (reasons: thunks specialized to import index because a lookup is still needed).
I hate bloat, too, and I don't look forward to needing to parallelize wrapper generation in V8, but I can justify 1e6 by the consistency with module size.
AFAICT from reading back in the thread, the only thing missing here is:
A test for the maximum number of table elements in a table initializer. (I did not add this, because doing so requires creating a module that has >1e7 elements, which is enormous and slow, at least with the JS module builder. It might be necessary to drop down to raw bytes to make these non-prohibitively slow/large).
No resolution on the 1e6 module export limitation, retaining current limit of 1e5.
Now that WebAssembly/meetings#873 is merged, is there anything else to handle in this issue? It seems like an automated test for 1. is impractical, and 2. is a well-understood state for now (at least it's aligned, which is what this issue is about).
Activity
jfbastien commentedon Nov 28, 2017
FWIW we don't implement all the limits from V8's header because they're not all sensible for us. It would be good to list all the ones we want to standardize here. Our list is: https://github.com/WebKit/webkit/blob/master/Source/JavaScriptCore/wasm/WasmLimits.h
rossberg commentedon Nov 29, 2017
Just to check that we are on the same page: these would be web API tests and don't affect the reference interpreter, because embedder-specific restrictions don't belong there, right?
jfbastien commentedon Nov 29, 2017
@rossberg undecided.
The precise action item is: WebAssembly/meetings#100
Polls to take at the next meeting are:
Also, tooling would warn: WebAssembly/design#1509
RyanLamansky commentedon Dec 16, 2017
Given that non-web embeddings may have considerably greater hardware resources and exotic use cases, it seems audacious to extend web browser limitations to them.
lars-t-hansen commentedon Jan 10, 2018
There is an open question about how to interpret the limit on the number of locals. It appears that WebKit and v8 account separately for the number of parameters and locals (so, up to 10000 parameters; up to 50000 non-parameter locals). Firefox instead limits parameters (10000) and then the total number of locals+parameters to 50000 [sic]. This is probably a Firefox bug but it would be nice to settle this explicitly.
https://bugzil.la/1423952 is our tracker for this.
littledan commentedon Mar 8, 2018
Should making a cross-browser decision on main thread synchronous compilation limits be part of this effort? In webpack/webpack#6433, we can see that WebAssembly packaging authors are hitting it; there's also a stack overflow thread where it looks like someone was reading a tutorial written for Firefox, and found it wouldn't work in Chrome. Is there a particular reason why the limit is applied in some browsers and not in others? I imagine users would benefit in terms of compatibility if we could come to agreement here.
erights commentedon Mar 9, 2018
rossberg commentedon Mar 9, 2018
@erights, I suppose it's up to clients to decide what standards they implement, and whether they want to consider themselves a full "web browser" in the common sense of the term. Strictly speaking, we can only put out recommendations.
littledan commentedon Mar 12, 2018
For context, Node implements some web standards, such as URL, and is considering more. On a practical level, these limits are implemented in JS engines, and, unless special support were added to bypass them, I think Node would get the same limits as the browser where the engine is embedded (whether we are talking about Chrome or Edge).
littledan commentedon Apr 18, 2018
We discussed this issue in the April 12 Wasm WG meeting. The group agreed that we want to move forward on these limits, and that the next step is to write patches against the JS API and Web API for these limits, working out the details on GitHub.
titzer commentedon May 2, 2018
I have now written some tests for these limits and run them against existing engines. I uploaded them to a branch and I'll have a PR ready soon.
Outcome so far: all engines agree on the limits which are written in the tests, except for two:
(V8 enforces a smaller number than 64Ki, but probably shouldn't)
(JSC enforces the maximum number of local variables independent of the number of parameters, whereas the other 3 engines consider the parameters to be included).
titzer commentedon May 2, 2018
The branch can be seen here: https://github.com/WebAssembly/spec/tree/embedding_limits
titzer commentedon May 24, 2018
Hello,
I have updated the limits test in that branch with what I believe to be a now-final set of tests. The results are that all engines fail one or more minor checks, which I will summarize below.
For reference I have a CL ready for V8 that fixes our previous problem with enforcing a too-small memory pages size (both initial and maximum), while cleaning up the names in the code and making it clear what is specified. For the failures outlined below, I don't expect any engine's changes to be more involved.
(V8 CL: https://chromium-review.googlesource.com/c/v8/v8/+/1063755)
The test is here: https://github.com/WebAssembly/spec/blob/embedding_limits/test/js-api/limits.js
To run it:
% cat ../harness/wasm-constants.js ../harness/wasm-module-builder.js limits.js > /tmp/test.js && wasm-engine /tmp/test.js@littledan The test above has a small bit of harness inlined, and I didn't try to get it to run in the browser. It might need to be adjusted to make it nice to run on a spec compliance page. Is that something you can handle?
V8:
With the above CL, V8 fully complies with the limits.
SpiderMonkey:
Chakra:
JSC:
As for enforcing a smaller "initial memory pages" value, IMO I think the engine should not make this a validation error, but should simply be an OOM condition when trying to instantiate the module.
As for the "maximum table size over the limit" issue, I think this is due to the existing js-api.js test attempting to instantiate a table with MaxUint32 entries. IMO the
new WebAssembly.Table()constructor and the "binary way" of creating such a table with just a module should enforce the same limit.@lukewagner @jfbastien @MikeHolman thoughts?
I didn't test Chrome's synchronous 4KiB module compilation limitation. I guess this should come with a test somehow, but it was complicated, since Chrome doesn't enforce this limit, e.g. in some worker contexts. IMO that 4KiB limit isn't particularly useful but that's a different discussion.
I also did not test the overall 1GiB maximum module size limitation since it might hard to make a reliable test for this that doesn't already OOM just due to having a 1GiB typed array.
julian-seward1 commentedon Jun 6, 2018
@titzer:
I fixed this in SpiderMonkey. One result of doing so is that the following test
in jsapi.js (at or around line 560) now fails.
assert_equals(new Table({initial:1, maximum:Math.pow(2,32)-1, element:"anyfunc"}) instanceof Table, true);
It seems reasonable to me that it now fails. What I don't understand is: that test
exists unchanged in the implementation_limits branch. So I would have thought it
would now fail on all engines. Either that, or I misunderstood something. Can you
clarify?
Bug 1467071 - Wasm: import embedding_limits "limits.js" test and fix …
22 remaining items
dead-claudia commentedon Aug 27, 2018
Just to clarify, is this a must or should support that many exports - on sufficiently resource-constrained devices (anywhere from embedded to mid-range mobile), the device might not have that much memory available, or in some cases, that much memory at all. And near the upper end of the infeasibility, you do have full JS environments with all the recent stuff, so it's not like you can assume most browsers have that much available.
IMHO, the branch adding the limits should specify web implementations "should, if sufficient memory exists", implement those limits, so this isn't an issue.
titzer commentedon Sep 3, 2018
I'd be OK bumping the export limit to 1e6, simply because it matches the per-module function limit of 1e6. In some sense, it'd be odd to allow a module to have K functions but only be allowed to export K/10 of them.
There is a per-export cost when embedding in JS, since the engine must materialize JS functions for every export, though this can be done lazily. Currently V8 does this eagerly. The cost of an exported function is basically a JSFunction instance + a machine code thunk, but the machine code thunks are per-signature. We currently pay more for imports because (reasons: thunks specialized to import index because a lookup is still needed).
I hate bloat, too, and I don't look forward to needing to parallelize wrapper generation in V8, but I can justify 1e6 by the consistency with module size.
binji commentedon Sep 6, 2018
Is the embedding limits branch ready to be a PR? If we're planning to include this in the v1 spec, I'd like to add it as soon as possible.
titzer commentedon Sep 13, 2018
PR created; PTAL.
titzer commentedon Sep 13, 2018
AFAICT from reading back in the thread, the only thing missing here is:
A test for the maximum number of table elements in a table initializer. (I did not add this, because doing so requires creating a module that has >1e7 elements, which is enormous and slow, at least with the JS module builder. It might be necessary to drop down to raw bytes to make these non-prohibitively slow/large).
No resolution on the 1e6 module export limitation, retaining current limit of 1e5.
littledan commentedon Dec 13, 2018
Now that WebAssembly/meetings#873 is merged, is there anything else to handle in this issue? It seems like an automated test for 1. is impractical, and 2. is a well-understood state for now (at least it's aligned, which is what this issue is about).
binji commentedon Jan 24, 2019
Yes, I think this issue is resolved.
Bug 1467071 - Wasm: import embedding_limits "limits.js" test and fix …
Bug 1467071 - Wasm: import embedding_limits "limits.js" test and fix …
Bug 1467071 - Wasm: import embedding_limits "limits.js" test and fix …
Bump up some default limits to align with mainstream wasm implementat…
Bug 1467071 - Wasm: import embedding_limits "limits.js" test and fix …
Bug 1467071 - Wasm: import embedding_limits "limits.js" test and fix …
Bug 1467071 - Wasm: import embedding_limits "limits.js" test and fix …