Skip to content

Optimise code size of addFunction. NFC #24594

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

Merged
merged 9 commits into from
Jun 19, 2025

Conversation

RReverser
Copy link
Collaborator

I think there is more that could be done here - in particular, setWasmTableEntry is only used from libaddfunction and likely could be merged into it to unify data structures and updates - but for now just tackled some low-hanging fruits.

@RReverser RReverser requested a review from sbc100 June 17, 2025 18:56
@RReverser RReverser requested a review from sbc100 June 17, 2025 21:10
@RReverser
Copy link
Collaborator Author

Huh. Looks like in core2 Closure mangles

$wasmTypeCodes: {
  'i': 0x7f, // i32
#if MEMORY64
  'p': 0x7e, // i64
#else
  'p': 0x7f, // i32
#endif
  'j': 0x7e, // i64
  'f': 0x7d, // f32
  'd': 0x7c, // f64
  'e': 0x6f, // externref
},

into

wb = {qg: 127, p: 127, rg: 126, f: 125, d: 124, e: 111},

I thought quoting was supposed to prevent that...

@RReverser
Copy link
Collaborator Author

Ahh it's because of how jsify generates the variables. It generates them as unquoted when using object literal...

@RReverser RReverser force-pushed the add-function-opt-size branch from 2636680 to cc9c938 Compare June 18, 2025 14:53
@RReverser RReverser enabled auto-merge (squash) June 18, 2025 14:53
@sbc100
Copy link
Collaborator

sbc100 commented Jun 18, 2025

Ahh it's because of how jsify generates the variables. It generates them as unquoted when using object literal...

Yes, sadly I think the round-tripping that happens when the JS library is processed will remove the quotes.

You can either:
(1) move the object declaration back inside the functions body;
(2) Put the whole thing in a multi-line string.

@RReverser RReverser merged commit 273a3fd into emscripten-core:main Jun 19, 2025
30 checks passed
@RReverser RReverser deleted the add-function-opt-size branch June 19, 2025 01:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants