Skip to content

Conversation

@kripken
Copy link
Member

@kripken kripken commented Nov 6, 2025

The meaning of Global in PossibleContents changes from "an actual wasm
Global" to "an immutable global wasm thing, either a Global or a Function."
Imported wasm Functions are effectively immutable values in the global
scope - not concrete, specifically-known functions - so this is more correct.

In particular, two imported Globals (of compatible types) might or might not
be the same, and likewise with imported Functions. And that is not the case
for defined Functions - they are definitely different.

This does not fix the issues related to imported function type handling -
#7993 does that - but this refactoring makes it possible to properly
optimize imported functions afterward.

This does make the PossibleContents object grow from 32 to 40 bytes,
which might be why this adds 3-4% overhead to GUFA, but I don't see a
good way to avoid that, unfortunately. The loss of the ability to optimize
imported functions might be worth that 3-4% (we recently saw a few digits
improvement due to properly optimizing imported externs, for example,
from #8005)

@kripken kripken requested a review from tlively November 6, 2025 17:21
@kripken
Copy link
Member Author

kripken commented Nov 6, 2025

OTOH, maybe it is better to not land this yet, and risk the possible misoptimization, which as discussed here is quite theoretical, at least for now:

#7993 (comment)

We could leave this PR up as the solution (with 3-4% overhead) in case this ever becomes an issue?

@kripken
Copy link
Member Author

kripken commented Nov 6, 2025

(Though if we do that, we do need to add some hacks in GUFA, as mentioned in that discussion: Without this PR, imported functions appear as Literals, which we optimize too aggressively, even if they have inexact type - we always assume a Literal is a concrete value with fixed type.)

Copy link
Member

@tlively tlively left a comment

Choose a reason for hiding this comment

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

Nice!

@tlively
Copy link
Member

tlively commented Nov 6, 2025

I do like that this is more principled than doing a surgical fix in GUFA to avoid being overly aggressive with imported function literals.

@kripken
Copy link
Member Author

kripken commented Nov 6, 2025

Yeah, I really can't think of another principled solution here, so maybe we do need to live with this slight overhead. I'll fuzz a little more and then land.

@kripken kripken merged commit 8a66d2a into WebAssembly:main Nov 6, 2025
16 checks passed
@kripken kripken deleted the global.func.imp branch November 6, 2025 19:53
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