RNパフォーマンス改善のための指標と改善
from ReactNativeのパフォーマンス
リクエスト回数
キャッシュするなど
ページの読み込み時間
https://codesource.io/best-practices-that-will-increase-react-native-performance/
の7
単純に不要なものを出すなというものmrsekut.icon
それはそうだが。
https://www.simform.com/react-native-app-performance/
Slow navigator transitions
Navigator
navigationの遷移など
画像の最適化
https://www.simform.com/react-native-app-performance/
Image caching in React Native for Android
React Native Image Optimization on Android
Animating the size of images for different UI view
Progressive Image Loading in React Native iOS
いくつかかいている
拡張子を変える
サイズを小さくする
placeholderを利用する
https://codesource.io/best-practices-that-will-increase-react-native-performance/
の2
https://stackoverflow.com/questions/61043847/react-native-bad-app-performance-after-loading-images
https://medium.com/@adamjacobb/react-native-performance-images-adf5843e120
https://codesource.io/best-practices-that-will-increase-react-native-performance/
https://expo.canny.io/feature-requests/p/add-react-native-fast-image
https://github.com/x86kernel/react-native-fast-image-expo
https://github.com/wcandillon/react-native-expo-image-cache
react-native-fast-image
expoでは使えないっぽい
FlatListの最適化
RNのJanky Framesの改善
メモリリーク
メモリ使用量とか
起動時にメモリリークを何度か起こしているmrsekut.icon
Chrome DevToolsで見た
アプリのサイズ
特にAndroidでは問題になりやすい?
Proguardを使って圧縮するとよいらしい
https://tech.kitchhike.com/entry/reduce-react-native-app-size
使用しているライブラリのサイズの計測
改善手法
CPUアーキテクチャごとにAPKファイルを作成する
複数のアーキテクチャをサポートするJSCoreバイナリを保持する必要がなくなり、その結果、アプリのサイズが削減される
画像の圧縮をする
PNGの代わりにAPNGを使うなど
JSONデータも圧縮する
生のまま保存しない
#??
アプリのサイズと、実際に触っているときの挙動の重さってそんなに関係あるの?
参考
React Native app performance: Major issues and insights on improving your app’s performance
Application size and performance on Android
一つ一つの文章が簡潔すぎて詳細がわからんmrsekut.icon
同値だが再描画の原因になるものを省く
FC時代に気にかけることの一例
例えばstyle={{width: '100%'}}は、毎回Objectが新しく作られるので子の再描画の原因になる
外側に出して解決する
code:ts
const bigListStyle = {width: '100%'}
const Main = () => (
....
<BigListPureComponent style={bigListStyle} {...manyOtherProps}/>
)
Why Did You Renderを使うと気付くことの補助になる
起動時間
アプリの起動時に全てのJSコードをメモリにロードするので時間がかかる
必要でないものも全て読み込むので。
改善手法
Lazy Loadを使用する
必要になったタイミングで読み込む
Expoでは、babel-preset-expoのlazyImportsを使う
code:ts
module.exports = function(api) {
api.cache(true);
return {
presets: 'babel-preset-expo', { lazyImports: true },
};
};
Hermesを使用する
https://reactnative.dev/docs/hermes
Expoでどうやって使用するの #??
開始時間が短縮され、バンドルサイズが小さくなり、メモリ使用量が少なくなる
スプラッシュスクリーン使うとか
AppLoadingとか?
重いライブラリを使用しない ref
momentを消す
InlineRequires
RN v0.59で入った
遅延ロードする
Expoではデフォルトで有効になっていない
babel-preset-expoのlazyImportsを設定する
https://github.com/expo/expo/tree/master/packages/babel-preset-expo#lazyimports
code:ts
module.exports = function(api) {
api.cache(true);
return {
presets: 'babel-preset-expo', { lazyImports: true },
};
};
https://soshace.com/performance-optimizations-for-react-native-applications/