Skip to content

Cache process const strings#6952

Merged
LesnyRumcajs merged 2 commits intomainfrom
cache-process-const-strings
Apr 22, 2026
Merged

Cache process const strings#6952
LesnyRumcajs merged 2 commits intomainfrom
cache-process-const-strings

Conversation

@LesnyRumcajs
Copy link
Copy Markdown
Member

@LesnyRumcajs LesnyRumcajs commented Apr 21, 2026

Summary of changes

On top of #6951
This marginally improves the performance (~0.02ms for eth_chainId). Not a huge win from latency perspective, but should save some CPU cycles.

Changes introduced in this pull request:

  • cache process-immutable strings

Reference issue to close (if applicable)

Closes

Other information and links

Change checklist

  • I have performed a self-review of my own code,
  • I have made corresponding changes to the documentation. All new code adheres to the team's documentation standards,
  • I have added tests that prove my fix is effective or that my feature works (if possible),
  • I have made sure the CHANGELOG is up-to-date. All user-facing changes should be reflected in this document.

Outside contributions

  • I have read and agree to the CONTRIBUTING document.
  • I have read and agree to the AI Policy document. I understand that failure to comply with the guidelines will lead to rejection of the pull request.

Summary by CodeRabbit

  • Performance

    • RPC responses (client/version, chain ID, network name, net version) now return cached shared string values to reduce allocations and improve latency.
  • Refactor

    • Added dedicated handling for shared-string JSON values; conversions are now identity-like and test snapshot behavior adjusted (test override left unimplemented).

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 21, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 57521d19-55df-4d47-86ed-a3cf183f7939

📥 Commits

Reviewing files that changed from the base of the PR and between c0793f0 and 599616a.

📒 Files selected for processing (1)
  • src/rpc/methods/eth.rs

Walkthrough

Adds a specialized HasLotusJson impl for Arc<str> (identity conversions and unimplemented snapshots) and changes multiple RPC response types from String to Arc<str>, introducing process-wide OnceLock<Arc<str>> caches returned by handlers instead of per-request string allocations.

Changes

Cohort / File(s) Summary
Lotus JSON Trait Implementation
src/lotus_json/arc.rs
Add impl HasLotusJson for Arc<str> with type LotusJson = Self; into_lotus_json/from_lotus_json are identity conversions; test-only snapshots() is unimplemented!.
RPC: eth methods
src/rpc/methods/eth.rs
Web3ClientVersion and EthChainId: change type Ok from StringArc<str>; use static OnceLock<Arc<str>> to cache computed values and clone per call; added OnceLock import.
RPC: f3 methods
src/rpc/methods/f3.rs
GetRawNetworkName: change type Ok from StringArc<str> and return a cloned Arc<str> from a static OnceLock<Arc<str>> initialized once.
RPC: net methods
src/rpc/methods/net.rs
NetVersion: change type Ok from StringArc<str>; use a static OnceLock<Arc<str>> to cache the decimal representation and return clones thereafter.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant RPC_Handler as "RPC Method"
    participant ChainConfig
    participant Cache as "OnceLock<Arc<str>>"

    Client->>RPC_Handler: invoke method (e.g., NetVersion)
    RPC_Handler->>Cache: check initialized?
    alt cached
        Cache-->>RPC_Handler: clone Arc<str>
    else not cached
        RPC_Handler->>ChainConfig: read value (e.g., eth_chain_id / genesis_name)
        ChainConfig-->>RPC_Handler: value
        RPC_Handler->>Cache: initialize with Arc<str>
        Cache-->>RPC_Handler: clone Arc<str>
    end
    RPC_Handler-->>Client: return Arc<str>
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested labels

RPC

Suggested reviewers

  • sudo-shashank
  • hanabi1224
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 12.50% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Cache process const strings' directly and clearly describes the main objective of the pull request, which implements caching of process-immutable constant strings across multiple RPC methods.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch cache-process-const-strings
✨ Simplify code
  • Create PR with simplified code
  • Commit simplified code in branch cache-process-const-strings

Comment @coderabbitai help to get the list of available commands and usage tips.

@LesnyRumcajs LesnyRumcajs changed the base branch from main to optional-compression-rpc April 21, 2026 16:54
Base automatically changed from optional-compression-rpc to main April 21, 2026 19:55
@LesnyRumcajs LesnyRumcajs marked this pull request as ready for review April 22, 2026 07:34
@LesnyRumcajs LesnyRumcajs requested a review from a team as a code owner April 22, 2026 07:34
@LesnyRumcajs LesnyRumcajs requested review from hanabi1224 and sudo-shashank and removed request for a team April 22, 2026 07:34
@LesnyRumcajs LesnyRumcajs force-pushed the cache-process-const-strings branch from f0e3027 to a15e06d Compare April 22, 2026 07:34
@LesnyRumcajs LesnyRumcajs enabled auto-merge April 22, 2026 07:34
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 22, 2026

Codecov Report

❌ Patch coverage is 24.00000% with 19 lines in your changes missing coverage. Please review.
✅ Project coverage is 64.06%. Comparing base (b4dd6a2) to head (599616a).
⚠️ Report is 2 commits behind head on main.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/rpc/methods/eth.rs 33.33% 6 Missing ⚠️
src/lotus_json/arc.rs 37.50% 5 Missing ⚠️
src/rpc/methods/f3.rs 0.00% 5 Missing ⚠️
src/rpc/methods/net.rs 0.00% 3 Missing ⚠️
Additional details and impacted files
Files with missing lines Coverage Δ
src/rpc/methods/net.rs 0.00% <0.00%> (ø)
src/lotus_json/arc.rs 15.00% <37.50%> (+15.00%) ⬆️
src/rpc/methods/f3.rs 0.00% <0.00%> (ø)
src/rpc/methods/eth.rs 65.24% <33.33%> (-0.03%) ⬇️

... and 7 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b4dd6a2...599616a. Read the comment docs.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@LesnyRumcajs LesnyRumcajs force-pushed the cache-process-const-strings branch from a15e06d to c0793f0 Compare April 22, 2026 07:55
@LesnyRumcajs LesnyRumcajs added this pull request to the merge queue Apr 22, 2026
Merged via the queue into main with commit d13c21d Apr 22, 2026
34 checks passed
@LesnyRumcajs LesnyRumcajs deleted the cache-process-const-strings branch April 22, 2026 09:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants