Skip to content

perf: cache RawConn/fd + fix proc_exit for TinyGo 0.40+#1

Merged
myleshorton merged 7 commits intomainfrom
cache-rawconn
Mar 6, 2026
Merged

perf: cache RawConn/fd + fix proc_exit for TinyGo 0.40+#1
myleshorton merged 7 commits intomainfrom
cache-rawconn

Conversation

@myleshorton
Copy link
Copy Markdown
Contributor

@myleshorton myleshorton commented Mar 6, 2026

Summary

  • Cache RawConn and fd in tcpConnFile/tcpListenerFile to avoid repeated syscall overhead
  • Fix WASM module not closing on proc_exit(0) for TinyGo 0.40+ compatibility

Test plan

  • Verify socket performance with cached RawConn/fd
  • Test TinyGo 0.40+ WASM modules exit cleanly with proc_exit(0)
  • Run existing test suite to check for regressions

🤖 Generated with Claude Code

myleshorton and others added 2 commits March 2, 2026 17:02
Cache syscall.RawConn and the file descriptor at construction time
in both tcpConnFile and tcpListenerFile, eliminating per-call
SyscallConn() allocations in Read(), Write(), Recvfrom(),
SetNonblock(), and Fd().

This reduces allocations from 93 to 30 per 1KB roundtrip through
WATER+shadowsocks (~68% reduction). The remaining allocations are
from Control() closures which are inherent to the RawConn API.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
TinyGo 0.40+ calls proc_exit(0) after main() completes. Previously this
closed the module, preventing exported functions from being called after
_start returns. Now exit code 0 leaves the module usable.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR improves socket syscall performance by caching syscall.RawConn/fd in TCP socket wrappers and adjusts WASI proc_exit(0) handling so modules remain usable after _start returns (to support TinyGo 0.40+ behavior).

Changes:

  • Cache RawConn and file descriptor in tcpConnFile / tcpListenerFile to reduce per-call syscall/alloc overhead.
  • Change start-function handling to avoid closing modules on ExitError(0).
  • Change wasi_snapshot_preview1.proc_exit to only close the module on non-zero exit codes.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
runtime.go Keeps module open on ExitError(0) from start functions.
internal/sysfs/sock.go Adds cached RawConn/fd fields and uses cached RawConn.Control paths for socket ops.
internal/sysfs/sock_supported.go Uses cached rawConn in listener SetNonblock when available.
internal/sysfs/w_sock_fd.go Returns cached fd directly instead of re-running control per call.
imports/wasi_snapshot_preview1/proc.go Stops closing the module on proc_exit(0); still panics ExitError.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Comment thread internal/sysfs/sock.go Outdated
Comment thread internal/sysfs/sock.go
Comment thread internal/sysfs/sock.go Outdated
Comment thread runtime.go Outdated
Comment thread runtime.go
Comment thread imports/wasi_snapshot_preview1/proc.go
Comment thread internal/sysfs/sock.go Outdated
myleshorton and others added 4 commits March 6, 2026 12:36
- Use interface assertion for SyscallConn to fix TinyGo build
- Handle Control() errors when caching rawConn/fd
- Update proc_exit docs to reflect exit code 0 semantics
- Broaden runtime comment to cover all start functions
- Add regression test for module usability after proc_exit(0)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
TinyGo 0.40 changed SliceHeader.Len/Cap from uintptr to int,
matching standard Go. Cast uintptr to int in tinygo build files.
Also fix bug where Len was set twice instead of Len and Cap.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add tests that verify rawConn and cachedFd are properly populated
at construction time and usable for I/O operations via the fast path.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Remove upstream-only workflows (spectest, integration, release, examples,
internal-images, clear_cache). Slim commit.yaml to essentials:
- Test on Ubuntu + macOS 15 (arm64), Go 1.22 only
- TinyGo build check
- Drop benchmarks, fuzzing, scratch/Docker, Windows, older Go/macOS

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@myleshorton myleshorton merged commit cdc4e11 into main Mar 6, 2026
3 checks passed
@myleshorton myleshorton deleted the cache-rawconn branch March 6, 2026 23:24
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