Skip to content

Aligning on implementation-specific limits. #607

Closed

Description

@titzer

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.

Activity

  1. jfbastien commented on Nov 28, 2017

    @jfbastien
    Member

    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

  2. rossberg commented on Nov 29, 2017

    @rossberg
    Member

    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?

  3. jfbastien commented on Nov 29, 2017

    @jfbastien
    Member

    @rossberg undecided.

    The precise action item is: WebAssembly/meetings#100

    Polls to take at the next meeting are:

    • POLL: do we only want to discuss only static limits, or dynamic ones as well?
    • POLL: do we want to standardize this?
    • POLL: Should the limits be Web-embedding specific, or standardized for all of WebAssembly?

    Also, tooling would warn: WebAssembly/design#1509

  4. RyanLamansky commented on Dec 16, 2017

    @RyanLamansky

    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.

  5. lars-t-hansen commented on Jan 10, 2018

    @lars-t-hansen

    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.

  6. littledan commented on Mar 8, 2018

    @littledan
    Collaborator

    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.

  7. erights commented on Mar 9, 2018

    @erights
  8. rossberg commented on Mar 9, 2018

    @rossberg
    Member

    @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.

  9. littledan commented on Mar 12, 2018

    @littledan
    Collaborator

    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).

  10. littledan commented on Apr 18, 2018

    @littledan
    Collaborator

    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.

  11. titzer commented on May 2, 2018

    @titzer
    ContributorAuthor

    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).
  12. titzer commented on May 24, 2018

    @titzer
    ContributorAuthor

    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:

    • 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.

  13. julian-seward1 commented on Jun 6, 2018

    @julian-seward1

    @titzer:

    SpiderMonkey:
    Allows a maximum table size over the limit (should be maximum 10000000)

    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?

  14. 22 remaining items

  15. dead-claudia commented on Aug 27, 2018

    @dead-claudia

    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.

  16. titzer commented on Sep 3, 2018

    @titzer
    ContributorAuthor

    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.

  17. binji commented on Sep 6, 2018

    @binji
    Member

    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.

  18. titzer commented on Sep 13, 2018

    @titzer
    ContributorAuthor

    PR created; PTAL.

  19. titzer commented on Sep 13, 2018

    @titzer
    ContributorAuthor

    AFAICT from reading back in the thread, the only thing missing here is:

    1. 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).

    2. No resolution on the 1e6 module export limitation, retaining current limit of 1e5.

  20. littledan commented on Dec 13, 2018

    @littledan
    Collaborator

    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).

  21. binji commented on Jan 24, 2019

    @binji
    Member

    Yes, I think this issue is resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions