perf: cache RawConn/fd + fix proc_exit for TinyGo 0.40+#1
Merged
myleshorton merged 7 commits intomainfrom Mar 6, 2026
Merged
Conversation
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>
There was a problem hiding this comment.
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
RawConnand file descriptor intcpConnFile/tcpListenerFileto reduce per-call syscall/alloc overhead. - Change start-function handling to avoid closing modules on
ExitError(0). - Change
wasi_snapshot_preview1.proc_exitto 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.
- 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>
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
RawConnandfdintcpConnFile/tcpListenerFileto avoid repeated syscall overheadproc_exit(0)for TinyGo 0.40+ compatibilityTest plan
🤖 Generated with Claude Code