Skip to content

Omit unused Module receivers on provided imports. - #72

Closed
msuozzo wants to merge 1 commit into
ncruces:mainfrom
msuozzo:push-qummoqurrrlo
Closed

msuozzo wants to merge 1 commit into
ncruces:mainfrom
msuozzo:push-qummoqurrrlo

Conversation

@msuozzo

@msuozzo msuozzo commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

While wasm2go strips unused Module receivers on compiled functions,
libc-gen retains them, allocating bound-method closures in indirect call
tables.

Run RemoveReceiver across tree-shaken functions in libc-gen so pure
helpers emit plain package-level functions. This also requires
unexported receiverless functions be matched in -provided files so
wasm2go emits the calls without a Module receiver.

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   602.9m ± 2%   584.4m ± 1%  -3.07% (p=0.001 n=8)

pkg: github.com/ncruces/go-sqlite3/ext/stats
          │   before    │               after               │
          │   sec/op    │   sec/op     vs base              │
_average    87.89n ± 3%   87.06n ± 1%  -0.95% (p=0.016 n=8)
_variance   107.8n ± 2%   106.9n ± 1%       ~ (p=0.068 n=8)
geomean     97.34n        96.47n       -0.89%

pkg: github.com/ncruces/go-sqlite3/vfs/tests/speedtest1
            │   before    │            after             │
            │   sec/op    │   sec/op     vs base         │
_speedtest1   71.47m ± 1%   72.13m ± 2%  ~ (p=0.195 n=8)

While wasm2go strips unused Module receivers on compiled functions,
libc-gen retains them, allocating bound-method closures in indirect call
tables.

Run RemoveReceiver across tree-shaken functions in libc-gen so pure
helpers emit plain package-level functions. This also requires
unexported receiverless functions be matched in `-provided` files so
wasm2go emits the calls without a Module receiver.

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   602.9m ± 2%   584.4m ± 1%  -3.07% (p=0.001 n=8)

pkg: github.com/ncruces/go-sqlite3/ext/stats
          │   before    │               after               │
          │   sec/op    │   sec/op     vs base              │
_average    87.89n ± 3%   87.06n ± 1%  -0.95% (p=0.016 n=8)
_variance   107.8n ± 2%   106.9n ± 1%       ~ (p=0.068 n=8)
geomean     97.34n        96.47n       -0.89%

pkg: github.com/ncruces/go-sqlite3/vfs/tests/speedtest1
            │   before    │            after             │
            │   sec/op    │   sec/op     vs base         │
_speedtest1   71.47m ± 1%   72.13m ± 2%  ~ (p=0.195 n=8)
@ncruces

ncruces commented Nov 11, 2026

Copy link
Copy Markdown
Owner

The approach in #73 seems simpler, I'll go with that if you don't mind.

@ncruces ncruces closed this Nov 11, 2026
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