Skip to content

[Performance]: Optimize REST and JSON-RPC transport hot paths and reorganize transport code #201

Closed

Description

@MisterVVP

Proposal

Context

With #186 and #85 completed, the performance suite now provides isolated measurements for REST and JSON-RPC transport components, including:

  • JSON-RPC envelope parsing and serialization;
  • protobuf-to-JSON response serialization;
  • REST query parsing;
  • REST response construction;
  • task projection and lifecycle work;
  • end-to-end wire performance across concurrency levels.

Current wire results show substantially weaker scaling for HTTP+JSON and JSON-RPC than for gRPC, including cases where throughput largely plateaus while latency continues increasing with concurrency.

This task should use the new component benchmarks to identify and optimize the dominant transport-side costs.

Goal

Improve REST / HTTP+JSON and JSON-RPC throughput and latency, especially under concurrent workloads, without changing protocol semantics or weakening correctness.

Use the work as an opportunity to improve transport code organization.

Refactoring

Reorganize transport implementation code under dedicated subdirectories.

Suggested layout:

src/client/
  transport/
    grpc_transport.cpp
    http_json_transport.cpp
    json_rpc_transport.cpp
    sse_parser.cpp

src/server/
  transport/
    grpc_server_transport.cpp
    json_rpc_server_transport.cpp
    rest_server_transport.cpp
    rest_transport.cpp
    transport_mux.cpp
    http_adapter.cpp
    http_server_response_builder.cpp
    stream_cancellation_watcher.cpp
    transport_components.*

Keep non-transport concerns such as dispatcher, request context, tasks, stores, push-notification services, and Agent Card implementation outside these directories.

Update CMake and internal include paths accordingly.

Public API compatibility

Do not break existing installed include paths as part of this task.

Public headers such as:

a2a/client/http_json_transport.h
a2a/client/json_rpc_transport.h
a2a/server/rest_server_transport.h
a2a/server/json_rpc_server_transport.h

must remain source-compatible.

If public headers are reorganized internally, retain forwarding headers at the existing paths.

Optimization investigation

Use the component benchmarks added by #85 to identify the actual dominant costs before changing production behavior.

Initial candidates include:

JSON-RPC payload conversion

Investigate avoidable intermediate JSON/protobuf conversions.

In particular, request processing currently contains paths where protobuf Struct values are serialized to JSON and then parsed again into typed protobuf messages.

Determine whether these conversions and associated allocations can be removed or reduced.

REST query parsing

Investigate allocation costs in REST query parsing.

The current generic parsing path materializes decoded strings and an unordered_map even though A2A endpoints generally consume a small known set of query parameters.

Consider direct parsing into request structures or another lower-allocation representation where appropriate.

Response serialization

Use the protobuf-to-JSON benchmarks to determine the cost of response materialization for:

  • tasks;
  • task lists;
  • SendMessage responses;
  • streaming responses;
  • push-config responses.

Pay particular attention to task-list scaling with response size.

HTTP / JSON-RPC concurrency

Investigate why HTTP+JSON and JSON-RPC throughput stops scaling much earlier than gRPC.

Check for:

  • shared locking or serialization;
  • request scheduling bottlenecks;
  • unnecessary allocations/copies;
  • HTTP connection handling;
  • response construction;
  • JSON serialization;
  • transport-specific dispatcher overhead.

Do not assume serialization is the bottleneck until component measurements confirm it.

Performance methodology

Record a baseline from current main before optimization.

Compare both:

Component benchmarks

Relevant benchmarks from #85, including:

BM_JsonRpcEnvelope_ParseOnly
BM_JsonRpcEnvelope_SerializeOnly
BM_RestQueryParser_ParseOnly
BM_RestResponseBuilder_BuildOnly
BM_ProtoJson_ResponseToJson_*

End-to-end wire scenarios

Compare HTTP+JSON, JSON-RPC, and gRPC at concurrency:

1
4
16
64

Use the in-memory backend as the primary transport-isolation signal so PostgreSQL behavior does not obscure transport improvements.

gRPC should remain a useful control.

Success criteria

  • Transport implementation files are coherently organized under client/transport and server/transport.
  • Existing public include paths remain compatible.
  • At least one measured REST or JSON-RPC hotspot is identified from component benchmarks.
  • Production optimization addresses measured work rather than speculative changes.
  • Selected component benchmark improves materially; target approximately 15%+ where practical.
  • Improvement is visible in corresponding end-to-end wire workloads, not only the microbenchmark.
  • HTTP+JSON and JSON-RPC concurrency scaling is explicitly compared before and after.
  • gRPC performance does not materially regress.
  • No protocol or error-semantics regressions.
  • Existing streaming/SSE behavior remains unchanged.
  • TCK continues to pass all executed tests.
  • Unit, functional, integration, interoperability, and performance tests pass.
  • clang-format and clang-tidy pass.
  • ./scripts/verify_changes.sh passes.

Constraints

  • Preserve existing public SDK compatibility.
  • Do not trade correctness for throughput.
  • Avoid introducing global serialization or coarse-grained locks.
  • Avoid optimizations that improve microbenchmarks while degrading concurrent end-to-end workloads.
  • Keep allocations and copies out of hot paths where practical.
  • Retain transport parity and existing A2A protocol behavior.
  • Use benchmark evidence for performance claims.

Deliverables

  • transport implementation refactoring;
  • one or more evidence-backed REST / JSON-RPC optimizations;
  • before/after component benchmark results;
  • before/after wire results at concurrency 1/4/16/64;
  • brief explanation of the bottleneck found and why the optimization improves it;
  • documentation updates where architecture or performance guidance changes.

Out of scope

  • PostgreSQL store optimization;
  • PostgreSQL connection-pool redesign;
  • async PostgreSQL I/O;
  • unrelated task/store refactoring;
  • breaking public header/API changes.

Activity

  1. self-assigned this
    on Aug 10, 2026
  2. added
    enhancement
    performance
    on Aug 10, 2026
  3. moved this from Todo to In Progress in a2a-cpp SDK Roadmapon Aug 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancementperformance

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions