Repository navigation
Widen 32-bit linear memory addresses to uint64 in popAddr under -unsafe. - #70
Merged
Merged
Conversation
Generated 32-bit memory accesses use `uint32(addr)` at offset 0 and `uint64(uint32(addr))+offset` otherwise, so Go's type-keyed SSA cannot share zero-extensions or bounds-check proofs across uses of `addr`. Under `-unsafe`, where load and store helpers inline into large callers, always widen 32-bit addresses to `uint64(uint32(addr))`. Safe mode keeps `uint32(addr)` at offset 0: its helpers are not inlined into large callers, so widening shares nothing across the call and only adds zero-extensions and spills in the caller. The safe-mode carve-out can be removed once the safe helpers inline, see ncruces#69. Benchmarks on `go-sqlite3` (`wasm2go -unsafe`): goos: linux goarch: amd64 pkg: github.com/ncruces/go-sqlite3/driver cpu: AMD EPYC 7B13 │ before │ after │ │ sec/op │ sec/op vs base │ _loop 543.5m ± 2% 537.3m ± 2% -1.14% (p=0.001 n=8) pkg: github.com/ncruces/go-sqlite3/ext/stats │ before │ after │ │ sec/op │ sec/op vs base │ _average 84.39n ± 1% 81.96n ± 1% -2.88% (p=0.003 n=8) _variance 99.65n ± 1% 98.34n ± 8% ~ (p=0.129 n=8) geomean 91.70n 89.78n -2.10% pkg: github.com/ncruces/go-sqlite3/vfs/tests/speedtest1 │ before │ after │ │ sec/op │ sec/op vs base │ _speedtest1 69.11m ± 1% 68.58m ± 2% -0.77% (p=0.050 n=8)
msuozzo
force-pushed
the
push-opquuxvmutrt
branch
from
November 7, 2026 04:16
92f3089 to
af6193d
Compare
Owner
|
At that point, do generics make sense? |
Contributor
Author
yeah so i think they're necessary to keep safe mode fast (until #69). safe will still use both generic variants until then so i think it's reasonable to keep them around. to put a finer point on it: i found pretty rough regressions (~100% added cpu time) using uint64 everywhere. the go compiler change mentioned in #69 would unblock it if/when it's merged. |
ncruces
approved these changes
Nov 9, 2026
ncruces
left a comment
Owner
There was a problem hiding this comment.
I just inverted the condition as that reads better to me.
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.
Generated 32-bit memory accesses use
uint32(addr)at offset 0 anduint64(uint32(addr))+offsetotherwise, so Go's type-keyed SSA cannotshare zero-extensions or bounds-check proofs across uses of
addr.Under
-unsafe, where load and store helpers inline into large callers,always widen 32-bit addresses to
uint64(uint32(addr)). Safe mode keepsuint32(addr)at offset 0: its helpers are not inlined into largecallers, so widening shares nothing across the call and only adds
zero-extensions and spills in the caller. The safe-mode carve-out can be
removed once the safe helpers inline, see #69.
Benchmarks on
go-sqlite3(wasm2go -unsafe):