Skip to content

Conversation

@FrederikBolding
Copy link
Member

@FrederikBolding FrederikBolding commented Apr 23, 2025

The current approach for message passing in mobile encodes the JSON payloads into a byte array before injecting into the WebView. This was done by suggestion from @naugtur, but was known to be slow on mobile, especially with larger messages.

More recently this caused performance degradations with Snaps that MetaMask is actively trying to ship to production causing us to revisit this. After discussion with @weizman we landed on the fact that simply JSON stringifying should be safe enough and much more performant.

@codecov
Copy link

codecov bot commented Apr 24, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.03%. Comparing base (b8792af) to head (6bf3a7b).
Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3347      +/-   ##
==========================================
- Coverage   98.03%   98.03%   -0.01%     
==========================================
  Files         402      402              
  Lines       11112    11110       -2     
  Branches     1754     1754              
==========================================
- Hits        10894    10892       -2     
  Misses        218      218              

☔ 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 marked this pull request as ready for review April 24, 2025 08:54
@FrederikBolding FrederikBolding requested a review from a team as a code owner April 24, 2025 08:54

const json = bytesToString(new Uint8Array(event.data as number[]));
const message = JSON.parse(json);
const message = JSON.parse(event.data);
Copy link
Contributor

Choose a reason for hiding this comment

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

this can throw, should we catch gracefully?

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't think it matters too much, we don't do it in any of the other post message stream implementations used in MM either 😄

Copy link
Contributor

@weizman weizman left a comment

Choose a reason for hiding this comment

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

one small comment, lgtm

@FrederikBolding FrederikBolding added this pull request to the merge queue Apr 24, 2025
Merged via the queue into main with commit 2933de0 Apr 24, 2025
170 checks passed
@FrederikBolding FrederikBolding deleted the fb/stop-encoding-messages branch April 24, 2025 10:57
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.

4 participants