feat: optional compression for RPC responses#6951
Conversation
WalkthroughAdds a configurable HTTP response compression layer for the RPC server controlled by Changes
Sequence Diagram(s)sequenceDiagram
actor Client
participant HTTP_Server as "RPC HTTP Server"
participant CompressionLayer as "CompressionLayer\n(predicate + SizeAbove)"
participant Handler as "RPC Handler / Service"
Client->>HTTP_Server: Send request (may include Accept-Encoding)
HTTP_Server->>CompressionLayer: Pass request/response pipeline
CompressionLayer->>Handler: Invoke inner service (request)
Handler-->>CompressionLayer: Produce Response (body)
CompressionLayer->>CompressionLayer: Check body size vs COMPRESS_MIN_BODY_SIZE
alt compress?
CompressionLayer->>Client: Return gzip-compressed Response
else no compress
CompressionLayer->>Client: Return uncompressed Response
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Suggested reviewers
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
✨ Simplify code
Comment |
9b7dac0 to
997cadb
Compare
997cadb to
f9443cf
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/rpc/compression_layer.rs`:
- Around line 53-70: The parsing should accept integers outside i32 so
out-of-range inputs are handled (negative disables, too-large clamps) instead of
falling back to DEFAULT; change the parse from raw.parse::<i32>() to a wider
signed type (e.g., raw.parse::<i128>()), use a matching i128 max derived from
u16::MAX, then handle: on parse error log and return Some(DEFAULT) as before, if
parsed < 0 return None, if parsed > max emit the clamp warning and clamp to max,
and finally return Some(parsed.min(max) as u16). Update uses of parsed and max
in the warning messages accordingly (symbols: COMPRESS_MIN_BODY_SIZE_VAR,
DEFAULT, raw, parsed, max).
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 9982f8d0-3821-4cd0-8788-7aca10cd3043
📒 Files selected for processing (5)
.config/forest.dicCHANGELOG.mddocs/docs/users/reference/env_variables.mdsrc/rpc/compression_layer.rssrc/rpc/mod.rs
f9443cf to
8b9c010
Compare
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@docs/docs/users/reference/env_variables.md`:
- Line 23: Update the documentation entry for FOREST_RPC_MAX_CONNECTIONS to
indicate it accepts 0 by changing the type description from "positive integer"
to "non-negative integer (0 allowed)" or similar wording that notes "0 disables
or allows no connections"; keep existing default and example values but clarify
the semantics of 0 so users know it's intentionally valid. Reference the
variable name FOREST_RPC_MAX_CONNECTIONS and ensure the table cell currently
reading "positive integer" is replaced with the new wording.
- Line 24: Update the doc for FOREST_RPC_COMPRESS_MIN_BODY_SIZE to remove the
contradiction by stating that the accepted values are integers in the range [-1,
65535] where -1 (exactly -1) disables compression and any value >65535 is
clamped to 65535; ensure the description for FOREST_RPC_COMPRESS_MIN_BODY_SIZE
explicitly says "set to -1 to disable compression" (not "any negative value")
and retains the existing default and example values (1024 default, 2048 example)
so readers know the exact behavior.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 236db9cd-362c-401a-854c-ccea8e377459
📒 Files selected for processing (5)
.config/forest.dicCHANGELOG.mddocs/docs/users/reference/env_variables.mdsrc/rpc/compression_layer.rssrc/rpc/mod.rs
✅ Files skipped from review due to trivial changes (2)
- .config/forest.dic
- CHANGELOG.md
🚧 Files skipped from review as they are similar to previous changes (1)
- src/rpc/mod.rs
Codecov Report❌ Patch coverage is
Additional details and impacted files
... and 8 files with indirect coverage changes Continue to review full report in Codecov by Sentry.
🚀 New features to boost your workflow:
|
Summary of changes
Made compression optional and with a configurable threshold. For
eth_chainIdthis yields:Lotus: average
0.0435 msForest main: average
0.2039 msForest this PR: average
0.0268 msThat's over 7x improvement for, AFAIK, most widely used RPC method.
This will improve perf of most other methods as well, but I don't have numbers for those.
Changes introduced in this pull request:
FOREST_RPC_COMPRESS_MIN_BODY_SIZE; set a negative value to disable compression entirely. Small JSON-RPC responses such aseth_chainIdare no longer gzip-encoded, yielding a large throughput and latency improvement on high-QPS workloads.Reference issue to close (if applicable)
Closes
Other information and links
Lotus
Forest (this PR)
Forest (main)
bench script
https://gist.github.com/LesnyRumcajs/402f3528cbca69ae68f0b11987517ba6
Change checklist
Outside contributions
Summary by CodeRabbit
New Features
Bug Fixes
Documentation
Chores