Skip to content

perf: Move request inspection outside of the executor#3356

Merged
FrederikBolding merged 7 commits intomainfrom
fb/move-request-inspection-outside-executor
Oct 1, 2025
Merged

perf: Move request inspection outside of the executor#3356
FrederikBolding merged 7 commits intomainfrom
fb/move-request-inspection-outside-executor

Conversation

@FrederikBolding
Copy link
Member

@FrederikBolding FrederikBolding commented Apr 25, 2025

In the current implementation, every RPC request requires a least 3 messages to be sent to manage outbound request/response tracking. This PR proposes to move that tracking to the client side where we can simply monitor the RPC stream for requests and responses. This should alleviate some pressure on the communication layer for Snaps.


Note

Shift outbound request/response tracking to AbstractExecutionService by inspecting the JSON-RPC stream, removing executor-side notifications and updating tests accordingly.

  • Controllers (packages/snaps-controllers):
    • Update AbstractExecutionService to detect outbound activity by inspecting rpc stream:
      • Publish ExecutionService:outboundRequest on inbound RPC chunks with an id.
      • Intercept rpcStream.write to publish ExecutionService:outboundResponse when writing responses; ignore metamask_chainChanged.
  • Execution Environment (packages/snaps-execution-environments):
    • Remove OutboundRequest/OutboundResponse notifications from BaseSnapExecutor provider wrappers (snap.request, ethereum.request) and simplify teardown handling.
    • Adjust BaseSnapExecutor.test.browser.ts to drop expectations for command-stream outbound notifications where applicable, keeping RPC flow assertions intact.
  • Coverage: Minor metric fluctuations in coverage JSON files.

Written by Cursor Bugbot for commit 8b9e40f. This will update automatically on new commits. Configure here.

@FrederikBolding FrederikBolding force-pushed the fb/move-request-inspection-outside-executor branch from 653abb1 to 9005464 Compare April 28, 2025 08:01
@codecov
Copy link

codecov bot commented Apr 28, 2025

Codecov Report

❌ Patch coverage is 91.66667% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 98.27%. Comparing base (36f2212) to head (8b9e40f).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
...ntrollers/src/services/AbstractExecutionService.ts 90.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3356      +/-   ##
==========================================
- Coverage   98.30%   98.27%   -0.03%     
==========================================
  Files         417      417              
  Lines       11927    11903      -24     
  Branches     1844     1845       +1     
==========================================
- Hits        11725    11698      -27     
- Misses        202      205       +3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@FrederikBolding FrederikBolding force-pushed the fb/move-request-inspection-outside-executor branch from 0db0eba to 797d795 Compare April 28, 2025 11:26
github-merge-queue bot pushed a commit that referenced this pull request May 6, 2025
Moved some of the ideas from #3356
to this PR which will be a simple to merge right away. The other
referenced PR needs some more work, but is eventually what we should do.

This PR let's Snaps start their outbound request before waiting for the
notification to land, this should be a small perf improvement to all
requests made from the Snap.
@FrederikBolding FrederikBolding force-pushed the fb/move-request-inspection-outside-executor branch 2 times, most recently from a4a33fb to 17263e8 Compare October 1, 2025 10:50
@FrederikBolding FrederikBolding marked this pull request as ready for review October 1, 2025 11:10
@FrederikBolding FrederikBolding requested a review from a team as a code owner October 1, 2025 11:10
cursor[bot]

This comment was marked as outdated.

rpcStream.write = (chunk, encoding, callback) => {
// Ignore chain switching notifications as it doesn't matter for the SnapProvider.
if (chunk?.data?.method === 'metamask_chainChanged') {
return true;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is uncovered, but we don't have an easy way to test this right now

@FrederikBolding FrederikBolding force-pushed the fb/move-request-inspection-outside-executor branch from 1b1adf9 to 8b9e40f Compare October 1, 2025 13:51
@FrederikBolding FrederikBolding added this pull request to the merge queue Oct 1, 2025
Merged via the queue into main with commit 8571a4d Oct 1, 2025
119 of 121 checks passed
@FrederikBolding FrederikBolding deleted the fb/move-request-inspection-outside-executor branch October 1, 2025 14:06
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.

2 participants