Skip to content

refactor: dedupe common middleware hooks between Eip1193 and CAIP engines #32904

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

wenfix
Copy link

@wenfix wenfix commented May 14, 2025

Description

The Eip1193 and CAIP RPC engines share several equal hooks between them which are currently duplicated. This pr creates a method to setup these common hooks in order to avoid duplication.

Open in GitHub Codespaces

Related issues

Fixes:
https://github.com/MetaMask/MetaMask-planning/issues/4102

Manual testing steps

There should be no difference for users or dapps, all functionality should work as it did previously.

Screenshots/Recordings

Before

After

Pre-merge author checklist

Pre-merge reviewer checklist

  • I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed).
  • I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots.

Copy link
Contributor

github-actions bot commented May 14, 2025

CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes.

@wenfix
Copy link
Author

wenfix commented May 14, 2025

I have read the CLA Document and I hereby sign the CLA

@metamaskbot
Copy link
Collaborator

Builds ready [64f1145]
UI Startup Metrics (1205 ± 69 ms)
PlatformBuildTypePageMetricMean (ms)Min (ms)Max (ms)Std Dev (ms)P 75 (ms)P 95 (ms)
ChromeBrowserifyHomeuiStartup1205108814506912361358
load105295712876310811188
domContentLoaded104695212826210761181
domInteractive16144241624
firstPaint690133129242310581188
backgroundConnect84325720
firstReactRender20144152134
getState1453282029
initialActions001000
loadScripts804714103260835931
setupStore85182813
WebpackHomeuiStartup22641821259518624242552
load17761369227117718832074
domContentLoaded17681365226517718732062
domInteractive171275111445
firstPaint1646938664185307
backgroundConnect40102474641192
firstReactRender18055380110295353
getState194335381840
initialActions318247
loadScripts17531364205915818701994
setupStore207207222542
FirefoxBrowserifyHomeuiStartup1361117616169514211569
load1212105114688812721365
domContentLoaded1212105114678812711365
domInteractive1044351248120148
firstPaintNaNNaNNaNNaNNaNNaN
backgroundConnect20145252129
firstReactRender25205472451
getState11522422820
initialActions001001
loadScripts1194103714488712551340
setupStore8423223610
WebpackHomeuiStartup15621387215015116221901
load13391194178913314151629
domContentLoaded13391194178913314151629
domInteractive79532382582110
firstPaintNaNNaNNaNNaNNaNNaN
backgroundConnect2416121122441
firstReactRender36295154046
getState124126141031
initialActions002111
loadScripts13181174176713013961605
setupStore95366827
Benchmark value 1181 exceeds gate value 1180 for chrome browserify home p95 domContentLoaded
Benchmark value 1188 exceeds gate value 1180 for chrome browserify home p95 firstPaint
Benchmark value 20 exceeds gate value 18 for chrome browserify home p95 backgroundConnect
Benchmark value 2265 exceeds gate value 2192 for chrome webpack home mean uiStartup
Benchmark value 1776 exceeds gate value 1711 for chrome webpack home mean load
Benchmark value 1769 exceeds gate value 1704 for chrome webpack home mean domContentLoaded
Benchmark value 1754 exceeds gate value 1699 for chrome webpack home mean loadScripts
Benchmark value 2553 exceeds gate value 2454 for chrome webpack home p95 uiStartup
Benchmark value 2074 exceeds gate value 2030 for chrome webpack home p95 load
Benchmark value 2063 exceeds gate value 2005 for chrome webpack home p95 domContentLoaded
Benchmark value 192 exceeds gate value 90 for chrome webpack home p95 backgroundConnect
Benchmark value 1994 exceeds gate value 1970 for chrome webpack home p95 loadScripts
Sum of mean exceeds: 258ms | Sum of p95 exceeds: 338ms
Sum of all benchmark exceeds: 596ms

Bundle size diffs [🚀 Bundle size reduced!]
  • background: -4.27 KiB (-0.08%)
  • ui: -39 Bytes (0%)
  • common: 3.85 KiB (0.04%)

ffmcgee725
ffmcgee725 previously approved these changes May 14, 2025
@metamaskbot
Copy link
Collaborator

Builds ready [64f1145]
UI Startup Metrics (1185 ± 66 ms)
PlatformBuildTypePageMetricMean (ms)Min (ms)Max (ms)Std Dev (ms)P 75 (ms)P 95 (ms)
ChromeBrowserifyHomeuiStartup1185108615606612161289
load103089913075810631119
domContentLoaded102389312975810581113
domInteractive16133741624
firstPaint74685130139510481115
backgroundConnect83325723
firstReactRender2215149142136
getState1544491930
initialActions001000
loadScripts783658102055818869
setupStore84294818
WebpackHomeuiStartup22001787251916023212386
load17131384200212918081903
domContentLoaded17041380196212518011887
domInteractive161278121350
firstPaint1696432959189289
backgroundConnect2910169193653
firstReactRender19054363110301352
getState1243671527
initialActions318145
loadScripts16991379196112517981871
setupStore206196252135
FirefoxBrowserifyHomeuiStartup13281137181812813851585
load11841021162512112361417
domContentLoaded11841021162512112361416
domInteractive994024930112151
firstPaintNaNNaNNaNNaNNaNNaN
backgroundConnect19134652129
firstReactRender23195572335
getState11421828818
initialActions001001
loadScripts11671008161012012201395
setupStore10420022634
WebpackHomeuiStartup15861383221916116811867
load13551185193814114331596
domContentLoaded13551185193714114331595
domInteractive82381461991124
firstPaintNaNNaNNaNNaNNaNNaN
backgroundConnect241585102440
firstReactRender36295043745
getState125319311017
initialActions103111
loadScripts13351169191414014141577
setupStore11520921822
Benchmark value 24 exceeds gate value 18 for chrome browserify home p95 backgroundConnect
Benchmark value 18 exceeds gate value 17 for chrome browserify home p95 setupStore
Benchmark value 2201 exceeds gate value 2192 for chrome webpack home mean uiStartup
Benchmark value 1714 exceeds gate value 1711 for chrome webpack home mean load
Benchmark value 1705 exceeds gate value 1704 for chrome webpack home mean domContentLoaded
Benchmark value 1700 exceeds gate value 1699 for chrome webpack home mean loadScripts
Benchmark value 12 exceeds gate value 11 for firefox browserify home mean getState
Benchmark value 10 exceeds gate value 9 for firefox browserify home mean setupStore
Benchmark value 34 exceeds gate value 27 for firefox browserify home p95 setupStore
Sum of mean exceeds: 16ms | Sum of p95 exceeds: 14ms
Sum of all benchmark exceeds: 30ms

Bundle size diffs [🚀 Bundle size reduced!]
  • background: -4.27 KiB (-0.08%)
  • ui: -39 Bytes (0%)
  • common: 3.85 KiB (0.04%)

@metamaskbot
Copy link
Collaborator

Builds ready [19c3130]
UI Startup Metrics (1178 ± 57 ms)
PlatformBuildTypePageMetricMean (ms)Min (ms)Max (ms)Std Dev (ms)P 75 (ms)P 95 (ms)
ChromeBrowserifyHomeuiStartup1178107013195712131282
load103594711825110621125
domContentLoaded102993911775110571118
domInteractive16133041624
firstPaint73288113540110451120
backgroundConnect74294720
firstReactRender19154242029
getState1354681928
initialActions001001
loadScripts79270293850819879
setupStore75252712
WebpackHomeuiStartup21981782262416823202431
load17051381207112917971873
domContentLoaded16981377205812817921869
domInteractive161159111348
firstPaint1756551981208337
backgroundConnect309296303957
firstReactRender18253362105296349
getState1445291633
initialActions317145
loadScripts16931376205612917901867
setupStore2962784722181
FirefoxBrowserifyHomeuiStartup13191160179112013561548
load11751033167611112231381
domContentLoaded11751033167611112231381
domInteractive1013817226115157
firstPaintNaNNaNNaNNaNNaNNaN
backgroundConnect2113102122145
firstReactRender23187182230
getState84516818
initialActions002001
loadScripts11561016164310912071367
setupStore8418919613
WebpackHomeuiStartup15101367196911815801742
load1293116115839513591501
domContentLoaded1292116115829513581501
domInteractive80531462090132
firstPaintNaNNaNNaNNaNNaNNaN
backgroundConnect21145052228
firstReactRender35286453644
getState11519324928
initialActions102111
loadScripts1274114715579513421484
setupStore95537822
Benchmark value 21 exceeds gate value 18 for chrome browserify home p95 backgroundConnect
Benchmark value 2199 exceeds gate value 2192 for chrome webpack home mean uiStartup
Benchmark value 338 exceeds gate value 334 for chrome webpack home p95 firstPaint
Benchmark value 181 exceeds gate value 65 for chrome webpack home p95 setupStore
Sum of mean exceeds: 7ms | Sum of p95 exceeds: 123ms
Sum of all benchmark exceeds: 130ms

Bundle size diffs [🚀 Bundle size reduced!]
  • background: -1.41 KiB (-0.03%)
  • ui: 0 Bytes (0%)
  • common: 0 Bytes (0%)

@wenfix wenfix marked this pull request as ready for review May 14, 2025 17:45
* @param {string} origin - The connection's origin string.
* @returns {object} The shared hooks.
*/
setupCommonMiddlewareHooks(origin) {
Copy link
Contributor

Choose a reason for hiding this comment

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

thoughts on regrouping these by type and bringing back the comments describing each group? like // network configuration-related

Copy link
Author

Choose a reason for hiding this comment

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

good call! lmk if I got it right 🙏

@metamaskbot
Copy link
Collaborator

Builds ready [81f2b65]
UI Startup Metrics (1232 ± 62 ms)
PlatformBuildTypePageMetricMean (ms)Min (ms)Max (ms)Std Dev (ms)P 75 (ms)P 95 (ms)
ChromeBrowserifyHomeuiStartup1232111714496212691344
load106794612386111121172
domContentLoaded106093912306111031167
domInteractive16132631624
firstPaint807130123840210921171
backgroundConnect84355822
firstReactRender19154042028
getState1455791930
initialActions001001
loadScripts82171199760865928
setupStore85333813
WebpackHomeuiStartup22241817264618123582515
load17571407229516118462064
domContentLoaded17471403228915618421992
domInteractive16125391442
firstPaint1586653164176271
backgroundConnect3610245414398
firstReactRender14043336101265327
getState164198221832
initialActions318136
loadScripts17421402228715718391990
setupStore247334442341
FirefoxBrowserifyHomeuiStartup13121131189013313531618
load1169999157912412251462
domContentLoaded1169999157812412241462
domInteractive1043938445111172
firstPaintNaNNaNNaNNaNNaNNaN
backgroundConnect18136171928
firstReactRender23195372249
getState74354713
initialActions001001
loadScripts1153985155212212101412
setupStore73527625
WebpackHomeuiStartup15421348202014816131878
load13201156179413313971587
domContentLoaded13191155179413313971587
domInteractive77371712087116
firstPaintNaNNaNNaNNaNNaNNaN
backgroundConnect20146052126
firstReactRender33295443542
getState12525326828
initialActions002111
loadScripts13021139177413213801559
setupStore85364815
Benchmark value 808 exceeds gate value 800 for chrome browserify home mean firstPaint
Benchmark value 22 exceeds gate value 18 for chrome browserify home p95 backgroundConnect
Benchmark value 2225 exceeds gate value 2192 for chrome webpack home mean uiStartup
Benchmark value 1757 exceeds gate value 1711 for chrome webpack home mean load
Benchmark value 1748 exceeds gate value 1704 for chrome webpack home mean domContentLoaded
Benchmark value 1743 exceeds gate value 1699 for chrome webpack home mean loadScripts
Benchmark value 2515 exceeds gate value 2454 for chrome webpack home p95 uiStartup
Benchmark value 2064 exceeds gate value 2030 for chrome webpack home p95 load
Benchmark value 98 exceeds gate value 90 for chrome webpack home p95 backgroundConnect
Benchmark value 1991 exceeds gate value 1970 for chrome webpack home p95 loadScripts
Sum of mean exceeds: 175ms | Sum of p95 exceeds: 128ms
Sum of all benchmark exceeds: 303ms

Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 1.78 KiB (0.03%)
  • ui: 8.96 KiB (0.13%)
  • common: 99 Bytes (0%)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants