-
Notifications
You must be signed in to change notification settings - Fork 20
Pre-tinygo optimizations and codebase cleanups #113
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
- Add //go:build !prod tags to main_js.go and inject.go - Create main_js_prod.go with //go:build prod tag - Remove zerolog dependency from production build - Make InjectHTML a no-op in production (handled by service worker) This reduces WASM binary size and runtime overhead by excluding debug logging and HTML parsing from production builds.
- Add -gcflags="-l=4 -trimpath" for aggressive inlining - Add -ldflags="-s -w -buildid=" to strip symbols and build ID - Add -tags=prod to enable production-only code path - Implement dual-pass wasm-opt: -O4 for speed, then -Oz for size - Enable bulk-memory, sign-ext, and reference-types features This prioritizes runtime performance over binary size.
The WebSocket dialer returns a response that was never closed, causing a resource leak. Now closes the response body on error.
Replace dynamic slice growth with pre-allocation using make() with known capacity. This reduces allocations during relay iteration.
Change sync.Pool to store *[]byte instead of []byte to prevent interface boxing allocation on each Get/Put operation. Applied to: - cmd/portal-tunnel/main.go - cmd/relay-server/manager/bps_manager.go - portal/utils/ratelimit/bucket.go
…y' instead of 'proto.Message' - Changed the return type of CloneMessageVT methods in various structs from proto.Message to any. - Updated the parameter type of EqualMessageVT methods to accept 'any' instead of 'proto.Message'. - This change enhances type flexibility and aligns with recent Go language updates.
- Add rdsec_test.go covering all 4 message types (Identity, ClientInitPayload, SignedPayload, ServerInitPayload) - Round-trip MarshalVT/UnmarshalVT tests - CloneVT, EqualVT, SizeVT tests - Getter methods, Reset methods, and enum String/Enum tests - Coverage: 52.5% - Add rdverb_test.go covering all 11 message types (Packet, RelayInfo, Lease, etc.) - All packet type and response code enum tests - Getter methods and Reset methods - Complex nested message tests - Coverage: 36.6% - Add wsstream_test.go with comprehensive WebSocket stream wrapper tests - Mock implementation for isolated testing - Concurrent read/write safety tests - Multi-message streaming tests - Coverage: 93.1% - Refactor wsstream to use webSocketConn interface for testability - Update utils/ws.go to use wsstream.New() constructor
- Updated test cases in various files to use range-based loops for better readability and performance. - Modified the `justfile` to include `tidy` in the `all` target. - Enhanced `pre-commit-config.yaml` to ensure proper linting and formatting for Go files. - Added comprehensive tests for rate limiting and WebSocket functionalities in `utils` and `wsstream`. - Improved error handling and edge case coverage in existing tests.
Fix flakiness and incorrect assumptions in bucket tests:
- Trigger lazy state update explicitly in slack refill test
- Adjust burst/rate ratios to reliably trigger throttling in concurrent tests
- Increase rate for buffer pool test to avoid timeouts
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Codex Review
Here are some automated review suggestions for this pull request.
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
This pull request introduces several improvements and optimizations across the codebase. The most significant changes include major performance optimizations for buffer pooling, a refactored WebAssembly (WASM) production build process, a migration to reflection-free protobufs for TinyGo compatibility, and enhanced developer tooling for code quality and consistency.
Performance and Memory Optimizations:
cmd/portal-tunnel/main.goandcmd/relay-server/manager/bps_manager.goto use pointers to byte slices (*[]byte) instead of slices directly, reducing interface boxing allocations and improving performance under high concurrency. [1] [2] [3] [4]WebAssembly (WASM) Build Improvements:
build-wasmtarget in theMakefileto produce production-ready WASM builds by stripping debug symbols, enabling aggressive inlining, setting reproducible build IDs, and adding aprodbuild tag to disable debugging and HTML injection. Also improved WASM optimization by running a dual-pass withwasm-optfor both speed and size.//go:build !prod) tocmd/webclient/inject.goandcmd/webclient/main_js.goto exclude debugging and injection code from production builds. [1] [2]Protobuf and Protocol Changes:
portal/core/proto/rdsec/rdsec.pb.goto a reflection-free, TinyGo-compatible protobuf implementation by removing dependencies onprotoimplandprotoreflect, simplifying message types, and updating serialization/deserialization code inportal/core/cryptoops/handshaker.goto useMarshalVT/UnmarshalVTmethods. [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12]Developer Tooling and Code Quality:
.pre-commit-config.yamlwith hooks for whitespace cleanup, line ending normalization, Go formatting, and configuration verification, as well as a newjustfilewith common formatting, linting, testing, and vetting commands to streamline development workflows. [1] [2]Dependency Updates:
go.mod, includinggolang.org/x/crypto,golang.org/x/net,google.golang.org/protobuf,gopkg.eu.org/broccoli, and indirect dependencies, to newer versions for improved security and compatibility.