-
Notifications
You must be signed in to change notification settings - Fork 694
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
Compact import section format #1514
Comments
FWIW, I've also wanted to define a new |
Off the top of my head, this would be the import section, the export section, custom section names, and possibly the contents of custom sections such as the name section. Are there other locations I'm missing? |
I think this could make sense if it showed some good size decreases. With respect to the linked js-string-builtins issue, that discussion isn't finished yet and we may settle on something that doesn't require a huge amount of imports. So the hyper-specialization around array indices might not be necessary. One related issue to the binary size of imports is also just the slowness of performing 'read the imports'. For the string constant use-case for imports, a lot of time is spent performing the specified two fully generic property lookups (one for We've discussed ways internally to optimize this by avoiding the repeated |
Yep! If we get back to adding module-linking to core wasm, then Reading this comment, I wondered if perhaps we could allow string constants to initialize an |
Generally speaking I like this idea, and it seems very straightforward. |
Would it be safe to say that compact import sections would allow string constants in the js-builtins proposal to use the same
being a bit too cute? |
Yes, that's the main reason I think this would be interesting. I plan on presenting a proposal for this on 7-02 CG meeting. In the meantime, before this exists (if it ever does exist) we'd still need an alternative for the js-string use-case, but that's being discussed there. |
It addresses the concern for me. (While I do think a Regardless, I am in favor of developing a new, compact import section encoding either way. |
The binary format of the import section is a vector of elements, each containing a module name, an item name, and the kind and type of the imported item. This means that a module that imports one thousand items from some module named
"env"
would repeat the string"env"
one thousand times in its import section. As the number of imports goes up, this repetition becomes extremely wasteful, even if the module name is extremely short or even empty. With JS string builtins, the number of imports a module might reasonably have is about to increase dramatically, so it would be nice to be able to avoid this duplication as much as possible.It would be possible to design an alternative import section binary format that avoided this duplication, either by grouping multiple imports from a single module together, or by using indices to refer to strings in a table, or by some other mechanism.
Potentially we could go even farther. For example, we could provide a succinct encoding for a sequence of n imports from a module, all of the same type, and with increasing decimal indices as names (i.e.
"0"
,"1"
,"2"
, etc.). This would allow modules to declare an arbitrary number of imports in just a handful of bytes, at the cost of the design being hyper-specialized to that one particular pattern of imports.Would there be appetite for specifying a more compact alternate encoding of the import section? Obviously we would continue supporting the existing encoding, but we could allocate a new section ID or another unused bit to differentiate the compact and existing formats.
The text was updated successfully, but these errors were encountered: