Skip to content

Commit

Permalink
CP-8525: Improve Android performance (polyfill promise with es6-promi…
Browse files Browse the repository at this point in the history
…se) (#1293)
  • Loading branch information
atn4z7 authored May 8, 2024
1 parent a2cd524 commit 5c86a63
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 1 deletion.
4 changes: 4 additions & 0 deletions packages/core-mobile/app/services/sentry/SentryService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ const isAvailable =
const init = (): void => {
if (isAvailable) {
Sentry.init({
// disabling promise patching since it is affecting app performance
// instead, we are patching promise ourselves with es6-promise
// TODO: renable patchGlobalPromise here https://ava-labs.atlassian.net/browse/CP-8616
patchGlobalPromise: false,
dsn: Config.SENTRY_DSN,
environment: Config.ENVIRONMENT,
debug: false,
Expand Down
1 change: 1 addition & 0 deletions packages/core-mobile/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@
"crypto-browserify": "3.12.0",
"date-fns": "2.28.0",
"deprecated-react-native-prop-types": "2.3.0",
"es6-promise": "4.2.8",
"eth-rpc-errors": "4.0.3",
"ethers": "6.8.1",
"events": "3.3.0",
Expand Down
1 change: 1 addition & 0 deletions packages/core-mobile/polyfills/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import './promise'
import 'react-native-gesture-handler'
import 'react-native-quick-crypto' // to override the global.crypto object
import '@walletconnect/react-native-compat'
Expand Down
27 changes: 27 additions & 0 deletions packages/core-mobile/polyfills/promise.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// there seems to be a performance issue with React Native's promise so we are polyfilling it with es6-promise
// TODO: remove this polyfill and use bridgeless mode https://ava-labs.atlassian.net/browse/CP-8616
const {
polyfillGlobal
} = require('react-native/Libraries/Utilities/PolyfillFunctions')

const Promise = require('es6-promise').Promise

// es6-promise doesn't have allSettled by default
Promise.allSettled =
Promise.allSettled ||
(promises =>
Promise.all(
promises.map(p =>
p
.then(value => ({
status: 'fulfilled',
value
}))
.catch(reason => ({
status: 'rejected',
reason
}))
)
))

polyfillGlobal('Promise', () => Promise)
3 changes: 2 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ __metadata:
date-fns: 2.28.0
deprecated-react-native-prop-types: 2.3.0
detox: 20.13.5
es6-promise: 4.2.8
eslint: 8.50.0
eslint-plugin-avalabs-mobile: "workspace:*"
eth-rpc-errors: 4.0.3
Expand Down Expand Up @@ -12435,7 +12436,7 @@ __metadata:
languageName: node
linkType: hard

"es6-promise@npm:^4.2.8":
"es6-promise@npm:4.2.8, es6-promise@npm:^4.2.8":
version: 4.2.8
resolution: "es6-promise@npm:4.2.8"
checksum: 95614a88873611cb9165a85d36afa7268af5c03a378b35ca7bda9508e1d4f1f6f19a788d4bc755b3fd37c8ebba40782018e02034564ff24c9d6fa37e959ad57d
Expand Down

0 comments on commit 5c86a63

Please sign in to comment.