Skip to content

Conversation

@kripken
Copy link
Member

@kripken kripken commented Jul 28, 2025

When we precompute struct.new, we have a cache of allocations, as we
need the ID of allocations to remain the same. The logic for managing that
cache was actually first creating a new instance, then throwing it away if
we used the cached value... so we ended up visiting the children and
computing them etc., with exponential (wasted) work in the worst case.

To fix that, just check the cache first.

Fixes #7760

@kripken kripken requested a review from tlively July 28, 2025 20:08
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.

Let's add a test that would trigger the previous slowdown. Of course the test would pass without this change, but we would still notice if a future regression made a test start taking a much longer time to finish.

@kripken
Copy link
Member Author

kripken commented Jul 28, 2025

Heh, good idea. Added, with an extra array.new in the middle to make it even slower.

@kripken kripken merged commit 5ca16fe into WebAssembly:main Jul 28, 2025
17 checks passed
@kripken kripken deleted the ctor.fast branch July 28, 2025 21:45
kripken added a commit that referenced this pull request Jul 29, 2025
Fixes a regression from #7763

This is pretty subtle, unfortunately. We cache the results of a struct.new
etc as we go, so that identity is preserved for precomputing RefEq etc.
The old code always computed structs in full before checking the cache.
#7763 removed that code as an optimization. But, it turns out,
that was load-bearing in that it, by pure luck, happened to avoid a bug.

The bug that was avoided, and which this PR fixes, is that when we
partially precompute, we modify a struct.new and see if we can
precompute that version. We were still using the same heap value
cache, so we could cache the value, then later end up using it for
the original (before, we'd still compute the struct.new again and
use those values). To fix that, do such speculative precomputations on a
side (throwaway) cache.

Fixes #7765
kripken added a commit that referenced this pull request Aug 8, 2025
Precompute has two modes, one where we ignore effects. We were
caching the effectless results for where the normal mode (which cares
about effects) would reuse them, leading to bugs.

Fixes a regression from #7763, another after #7766. We were not using the
cache fully, before, and caches are bug-prone, sadly.
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.

Pathological slowdown in wasm-ctor-eval

2 participants