Repository navigation
Conversation
…p1 WaitWrite, and map/slice growth - Cap wasm growHeap step size to 64 MiB with backoff up to 65535 pages and cast wasm_memory_size to uintptr before multiplying by wasmPageSize so heaps past 2 GiB do not overflow int32 or fail doubling past 4 GiB. - Add (*FD).WaitWrite in internal/poll/fd_wasip1.go for Go 1.26+ net/fd_unix.go compatibility on wasip1, and guard wait/parkUntil with task.OnSystemStack() so -scheduler=none builds do not pull in time.AfterFunc goroutines or netpoll symbols. - Pass -z stack-size to wasm-ld when -scheduler=none and -stack-size are set. - Walk buckets directly in hashmapCopy instead of heap-allocating temporary key/value buffers per rehash, and skip hashmapClear when count is 0. - Use 1.25x slice capacity growth for oldCap >= 256 in sliceGrow instead of rounding large slices to the next power of two.
teamchong
force-pushed
the
wasm-wasip1-large-heap-and-poll
branch
from
October 27, 2026 06:25
fabf3ee to
8471d34
Compare
Member
|
@jakebailey Seems like your wheelhouse. |
Member
|
This is too many fixes in a single commit. Can you please split these up into at least different commits, if not different PRs, so we can discuss them indivudually? Thanks. |
Contributor
|
@teamchong thank you very much for your commit. As @dgryski suggested, would you please split this up into separate PRs, if they are related in a series, perhaps try GitHub's stack's feature. I am going to close this PR as it stands, not because I am not grateful for your contribution, but because I do not see a straight forward path to merge this as presented. Thank you and I hope to see your contributions shortly. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes several WebAssembly /
wasip1compatibility and memory-scaling issues encountered when compilingtypescript-go(tsgo) towasip1:src/runtime/arch_tinygowasm.go(growHeap):wasm_memory_size(wasmMemoryIndex) * wasmPageSizepreviously multiplied as signedint32before converting touintptr, overflowing to negative at 32,768 pages (2 GiB) and wrapping to0at 65,536 pages (4 GiB).memorySizein a singlewasm_memory_growcall always failed once linear memory passed 2 GiB (requesting >4 GiB) or when a host runtime enforced a ceiling below2 * memorySize.0xffff0000bytes) with halving backoff on failure, and convertwasm_memory_sizetouintptrbefore multiplying bywasmPageSize.src/internal/poll/fd_wasip1.go((*FD).WaitWrite,wait,parkUntil):net/fd_unix.goonwasip1(//go:build unix || js || wasip1), where(*netFD).connectcallsfd.pfd.WaitWrite(). Add(*FD).WaitWritedelegating towait/parkUntil(pollModeWrite, fd.wDeadline).waitandparkUntilwithif task.OnSystemStack()so-target=wasip1 -scheduler=nonebuilds dead-code-eliminatetime.AfterFunc(internal/task.start) andruntime_netpoll_*(which is only built underscheduler.tasks || scheduler.asyncify).compileopts/config.go(LDFlags):-stack-sizeas-z stack-size=<bytes>towasm-ldwhen-scheduler=noneis used, since there are no goroutine stacks and execution uses the linear shadow stack directly.src/runtime/hashmap.go(hashmapCopy,hashmapClear):hashmapCopyinstead of allocating temporarykeyandvaluebuffers on the heap and copying every entry twice viahashmapNext.hashmapClearwhenm.count == 0(matchinghashmapDelete).src/runtime/slice.go(sliceGrow):elemSize == 0.oldCap < 256and use standard Go's 1.25x growth formula (growCap += (growCap + 3*256) / 4) foroldCap >= 256to avoid up to 50% capacity waste on large slices.