Improve deserialization performance with streaming parser#12
Closed
knutwannheden wants to merge 3 commits into
Closed
Improve deserialization performance with streaming parser#12knutwannheden wants to merge 3 commits into
knutwannheden wants to merge 3 commits into
Conversation
Refactor JsonRpcSuccess and JsonRpcMethod to use the MessageFormatter interface instead of their own static ObjectMapper instances. This removes duplicate ObjectMapper configurations and centralizes JSON conversion through the MessageFormatter.convertValue() method. Key changes: - Add convertValue(Object, Type) method to MessageFormatter interface - JsonRpc now takes a MessageFormatter parameter (with deprecated single-arg constructor for backwards compatibility) - JsonRpcSuccess uses injected formatter via factory method - JsonRpcMethod.convertAndHandle() takes formatter parameter Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Optimize JSON-RPC message handling with several performance improvements:
1. Streaming deserialization using JsonParser and TokenBuffer:
- Parse JSON-RPC messages with streaming API instead of reading
into intermediate Map<String, Object>
- Defer params/result parsing using TokenBuffer until actual type
is needed via convertValue()
- Primitives for 'result' are read directly without TokenBuffer
2. LimitedInputStream for zero-copy content reading:
- Stream content directly from underlying input without copying
to intermediate byte array
- Properly handles remaining bytes after message deserialization
3. ObjectWriter caching via ClassValue for serialization:
- Cache ObjectWriter instances per message type for faster writes
4. ThreadLocal ByteArrayOutputStream for send buffer reuse:
- Avoid allocating new buffer for each message sent
c727ddc to
1c06ce6
Compare
Resolved conflicts: - JsonMessageFormatter: kept streaming parser implementation - HeaderDelimitedMessageHandler: kept LimitedInputStream and ThreadLocal buffer optimizations while preserving effectiveFormatter for backwards compatibility - JsonRpcTest: use non-deprecated 2-arg HeaderDelimitedMessageHandler constructor
Member
|
Superseded by #18 |
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.
Optimize JSON-RPC message handling with several performance improvements:
Streaming deserialization using JsonParser and TokenBuffer:
LimitedInputStream for zero-copy content reading:
ObjectWriter caching via ClassValue for serialization:
ThreadLocal ByteArrayOutputStream for send buffer reuse: