| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
Replaced the JDK's slow fromLineSubscriber line-assembly mechanism with a custom byte-level streaming SSE parser SseByteSubscriber. This resolves an O(n^2) bottleneck when parsing large compact JSON payloads that are returned on a single line, improving throughput by ~45x. Closes modelcontextprotocol#1042
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
Replaced the JDK's slow fromLineSubscriber line-assembly mechanism with a custom byte-level streaming SSE parser (SseByteSubscriber) in ResponseSubscribers.java. This resolves an O(n²) performance bottleneck when receiving and parsing large compact JSON payload events (which are sent on a single line), without breaking streaming event delivery for notifications/progress.
Motivation and Context
When a tool returns a large payload (~4 MB compact JSON on a single line) over the Streamable HTTP client transport, the Java MCP SDK takes ~5 seconds to receive and parse it. This is roughly 10–13× slower than a raw HttpClient.ofString() read (~0.4s).
The bottleneck is the JDK HTTP Client's HttpResponse.BodySubscribers.fromLineSubscriber() used in ResponseSubscribers.sseToBodySubscriber(). It scans the incoming bytes to find newline boundaries, assembling the entire 4 MB JSON payload into a single string. The internal CharSequence/String assembly in fromLineSubscriber is extremely slow when processing one very long line from many small ByteBuffer chunks.
This PR replaces the line subscriber with a streaming byte-level SSE parser (SseByteSubscriber), which processes raw byte chunks (List<ByteBuffer>) using BodySubscribers.fromSubscriber(...). This bypasses the JDK's line-assembly entirely while preserving the streaming delivery of events.
How Has This Been Tested?
Tested locally via new unit tests in SseByteSubscriberTests.java and running the entire mcp-core test suite:
Breaking Changes
None. This change is fully internal to the package-private subscriber in the transport layer and does not modify the public APIs or the ResponseEvent contract.
Types of changes
Checklist
Additional context
Resolves #1042