perf(router): skip upstream gzip auto-decode on smart-router HTTP req…#2272
Merged
nimrod-teich merged 1 commit intomainfrom Apr 16, 2026
Merged
perf(router): skip upstream gzip auto-decode on smart-router HTTP req…#2272nimrod-teich merged 1 commit intomainfrom
nimrod-teich merged 1 commit intomainfrom
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests.
Flags with carried forward coverage won't be shown. Click here to find out more.
... and 4 files with indirect coverage changes 🚀 New features to boost your workflow:
|
be47970 to
8a4228d
Compare
avitenzer
reviewed
Apr 15, 2026
8a4228d to
b22374a
Compare
…uests
Go's default http.Transport auto-adds `Accept-Encoding: gzip` on outbound
requests when no Accept-Encoding is set, and transparently decodes responses
via net/http.(*http2gzipReader).Read → compress/gzip.Reader → compress/flate.
Production pprof on the eth router attributed ~30-39% of total CPU to that
inflate chain — CPU we spend decoding bytes we then either pass through,
re-encode with gzip for the client, cache as a blob, or peek at with
CheckResponseError.
Two coordinated changes remove that work *only on the smart router*:
1. Switch lavasession.HTTPDirectRPCConnection from its own fresh
&http.Client{} (default transport — no pooling, no TLS session cache,
no HTTP/2) to common.OptimizedHttpClient(). Every smart-router HTTP
connection now shares common.SharedHttpTransport() and inherits
connection pooling, TLS session resumption, and ForceAttemptHTTP2.
2. Set `Accept-Encoding: identity` on every outbound request from
HTTPDirectRPCConnection.SendRequest and DoHTTPRequest. Go only
auto-adds `gzip` when the caller left Accept-Encoding empty; once
identity is set, both the auto-add and auto-decode are skipped.
The scoping matters: the shared transport keeps its default compression
behavior, so provider chain proxies (chainlib/rest.go, tendermintRPC.go,
chainproxy/rpcclient/http.go) continue to auto-gzip as before. The opt-out
lives exclusively on the smart-router request path.
Measured impact on the eth router (same 900s pprof window, back-to-back
before/after the deploy):
CPU cores (avg): 2.47 → 1.23 (-50%)
Memory inuse: 277 GB → 186 GB (-33%)
Gzip-decode CPU path: 38.9% → 0% (eliminated from the top 25)
RelayCacheSet.Marshal: 30 GB → 19 GB (-37%)
Tradeoff: upstream bandwidth goes up because nodes now send plain JSON on
the wire for smart-router traffic. For co-located upstreams this is free;
geographically-distant deployments trade CPU for bytes. Per-request
deadlines are unchanged (caller context via NewRequestWithContext); the
client's 5-minute DefaultHTTPTimeout is a safety backstop above any
realistic upstream timeout.
Covered by:
- TestHTTPDirectRPCConnection_UsesSharedOptimizedTransport: regression
lock-in that two HTTPDirectRPCConnection instances share the singleton
common.SharedHttpTransport() for pooling and TLS session reuse.
- TestHTTPDirectRPCConnection_AdvertisesAcceptEncodingIdentity: httptest
end-to-end assertion that both SendRequest and DoHTTPRequest send
Accept-Encoding: identity on outbound requests and that response
bodies are returned untransformed.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
b22374a to
71eeb95
Compare
avitenzer
approved these changes
Apr 16, 2026
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.
…uests
Go's default http.Transport auto-adds
Accept-Encoding: gzipon outbound requests when no Accept-Encoding is set, and transparently decodes responses via net/http.(*http2gzipReader).Read → compress/gzip.Reader → compress/flate. Production pprof on the eth router attributed ~30-39% of total CPU to that inflate chain — CPU we spend decoding bytes we then either pass through, re-encode with gzip for the client, cache as a blob, or peek at with CheckResponseError.Two coordinated changes remove that work only on the smart router:
Switch lavasession.HTTPDirectRPCConnection from its own fresh &http.Client{} (default transport — no pooling, no TLS session cache, no HTTP/2) to common.OptimizedHttpClient(). Every smart-router HTTP connection now shares common.SharedHttpTransport() and inherits connection pooling, TLS session resumption, and ForceAttemptHTTP2.
Set
Accept-Encoding: identityon every outbound request from HTTPDirectRPCConnection.SendRequest and DoHTTPRequest. Go only auto-addsgzipwhen the caller left Accept-Encoding empty; once identity is set, both the auto-add and auto-decode are skipped.The scoping matters: the shared transport keeps its default compression behavior, so provider chain proxies (chainlib/rest.go, tendermintRPC.go, chainproxy/rpcclient/http.go) continue to auto-gzip as before. The opt-out lives exclusively on the smart-router request path.
Measured impact on the eth router (same 900s pprof window, back-to-back before/after the deploy):
CPU cores (avg): 2.47 → 1.23 (-50%)
Memory inuse: 277 GB → 186 GB (-33%)
Gzip-decode CPU path: 38.9% → 0% (eliminated from the top 25)
RelayCacheSet.Marshal: 30 GB → 19 GB (-37%)
Tradeoff: upstream bandwidth goes up because nodes now send plain JSON on the wire for smart-router traffic. For co-located upstreams this is free; geographically-distant deployments trade CPU for bytes. Per-request deadlines are unchanged (caller context via NewRequestWithContext); the client's 5-minute DefaultHTTPTimeout is a safety backstop above any realistic upstream timeout.
Covered by:
Description
Closes: #XXXX
Author Checklist
All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.
I have...
!in the type prefix if API or client breaking changemainbranchReviewers Checklist
All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.
I have...