perf(sdk-go): reduce websocket order dispatch allocations - #65
Open
namtran1812 wants to merge 1 commit into
Open
namtran1812 wants to merge 1 commit into
namtran1812 wants to merge 1 commit into
Conversation
Nostradamus Risk Rating — LowThis PR is a performance-only refactor in the Go SDK WebSocket dispatch path (packages/sdk-go/websocket/client_dispatch.go), replacing a generic map-decode with a typed struct envelope; the change is functionally equivalent and no security-sensitive areas (auth, signing, fund-movement) are touched. The remaining diff is new benchmark tests and a minor regression test extension. |
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
Reduce allocation overhead in the Go SDK WebSocket order-event dispatch path by replacing the generic
map[string]json.RawMessagediscriminator decode with a small typed envelope.The envelope includes both
e(event type) andE(event time) soencoding/jsonresolves the protocol's case-sensitive fields exactly while preserving the existing order-before-trade classification behavior.Motivation
Private order updates may contain a top-level
ttrade ID. The dispatcher therefore needs to identify explicitorder/orderUpdateevents before applying the generic trade heuristic.Previously, that classification decoded every candidate order frame into a
map[string]json.RawMessageand then decoded theefield separately. This adds avoidable allocations on the WebSocket dispatch path.Changes
e/Eenvelope.e, numericE, and top-levelttogether.Benchmark
Apple M1, darwin/arm64:
This is approximately 58% fewer allocated bytes and 55% fewer allocations per order frame in the benchmark. Timing results are environment-specific.
Validation
go test ./... -count=1go vet ./...go test -race ./websocket -count=1git diff --check