-
Notifications
You must be signed in to change notification settings - Fork 639
perf: Stop encoding messages in mobile #3347
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
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
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. 🚀 New features to boost your workflow:
|
|
|
||
| const json = bytesToString(new Uint8Array(event.data as number[])); | ||
| const message = JSON.parse(json); | ||
| const message = JSON.parse(event.data); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 😄
weizman
left a comment
There was a problem hiding this 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
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.