Optimize event envelope serialization in EventSubscription.executeAll#126
Open
greenart7c3 wants to merge 1 commit intomasterfrom
Open
Optimize event envelope serialization in EventSubscription.executeAll#126greenart7c3 wants to merge 1 commit intomasterfrom
greenart7c3 wants to merge 1 commit intomasterfrom
Conversation
Pre-serialize the event JSON once per fan-out and stamp it into a
per-subscription envelope by string concatenation, instead of asking
Jackson to re-walk the JsonNode tree for every matching subscription.
The subscription id is escaped once at construction (Subscription.escapedId)
so the hot path performs no JSON serialization per subscription. Also
short-circuits filter testing with `any { test }` (fixing a duplicate-send
when multiple filters in one subscription matched the same event) and
skips subscriptions whose websocket is already closed for send.
Includes a JVM-only micro-benchmark
(ExecuteAllFanOutBenchmark) that compares the strategies; on a 200-sub
fan-out of a typical kind-1 event it shows ~3-4x improvement.
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
Optimize the performance of broadcasting events to multiple subscriptions by pre-serializing the event envelope once instead of serializing it separately for each subscription.
Key Changes
Subscriptiondata class, eliminating repeated escaping during broadcasts["EVENT", <escapedId>, <eventJson>]any()to short-circuit filter evaluation instead of nested forEach loopsImplementation Details
ENVELOPE_MAPPERusingJacksonMapper.mapperfor consistent serializationSubscriptionclass now pre-computesescapedIdduring initializationexecuteAllfunction now constructs envelopes via string concatenation rather than Jackson serialization, reducing object allocation and GC pressureExecuteAllFanOutBenchmark) demonstrating the performance improvement with realistic event and subscription ID data, showing significant speedup especially when broadcasting to many subscribershttps://claude.ai/code/session_01N5q663coA5rYbnsrq5hMF1