Skip to content

NFC: Use createExportWrapper for exporting mangled symbols #14797

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

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

Conversation

rth
Copy link
Contributor

@rth rth commented Aug 3, 2021

Closes #14695

This does reduce the size of the resulting .asm.js slightly (though it wasn't very conclusive in the use-case of Pyodide #14695 (comment)), and maybe the code paths are slightly more consistent with and without assertions.

Opening it just for reference. Happy to close it and the linked issue if you think it's not worth it.

@rth
Copy link
Contributor Author

rth commented Aug 3, 2021

This does reduce the size of the resulting .asm.js slightly

To be more precise, for each exported symbol with delayed evaluation,

  • before:
    var %(mangled)s = Module["%(mangled)s"] = function() {
       return (%(mangled)s = Module["%(mangled)s"] = Module["asm"]["%(name)s"]).apply(null, arguments);  
    };
    → 99 char + 4*len(mangled) + len(name)
  • with this PR:
    createExportWrapper("{name}", "{mangled}");
    → 29 char + len(mangled) + len(name)

(numbers are approximate)

So for instance,

  • in the case len(name) == len(mangled) - 1 == 6, that would be a 65% reduction in output size for these symbols
  • if len(name) == len(mangled) - 1 == 50 , len(name) = 5, this would be a 62% reduction.

Hmm, I need re-check why I didn't see much impact on the total size on the example of Pyodide. Those exports do see take a significant amount of size (5k symbols).

@rth rth force-pushed the use-export-wrapper branch from bd6dffd to a1ffff3 Compare August 3, 2021 07:23
@rth rth force-pushed the use-export-wrapper branch from aff43b7 to 2634bbb Compare August 3, 2021 09:22
@rth rth marked this pull request as draft August 3, 2021 13:23
function createExportWrapper(name, mangled, fixedasm) {
// We create a wrapper that all calls get routed through, for the lifetime of the program.

globalThis[mangled] = Module[mangled] = function() {
Copy link
Member

Choose a reason for hiding this comment

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

Why is globalThis needed here? Aside from that, this PR looks very promising to me!

But it would also be good to see why this doesn't help pyodide - seems like it should.

@stale
Copy link

stale bot commented Sep 21, 2022

This issue has been automatically marked as stale because there has been no activity in the past year. It will be closed automatically if no further activity occurs in the next 30 days. Feel free to re-open at any time if this issue is still relevant.

@stale stale bot added the wontfix label Sep 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Optimizing output .js size: using createExportWrapper with no assertions
2 participants