Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
ReactNative製アプリがAndroidだと遅いという問題に立ち向かった話/the pr...
Search
stand.fm
May 21, 2021
Programming
3.5k
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
ReactNative製アプリがAndroidだと遅いという問題に立ち向かった話/the problem that React Native apps are slow on Android
stand.fm
May 21, 2021
More Decks by stand.fm
See All by stand.fm
stand.fm会社紹介資料
standfm
0
1.4k
stand.fmのTypeScriptへの移行と活用/migrating-to-typescript-standfm
standfm
0
2.6k
stand.fmの最近の取り組み: アプリ起動速度の改善/improvement-of-speed-startup-app
standfm
4
3k
LIVEの負荷対策と監視について / About LIVE load countermeasures and monitoring
standfm
0
9k
声でつながる、 優しい世界を創るUI/UX
standfm
4
660
stand.fm(Android)におけるreact-native-track-playerの改善/Improvement of react-native-track-player on standfm Android app
standfm
0
440
stand.fmにおける開発体験とパフォーマンスの向上 / Development Experience and Performance improvement
standfm
1
7.8k
React NativeアプリでコラボLIVE配信 / Collaboration Live Streaming with React Native App
standfm
1
4.5k
エンジニア向け会社紹介資料 / company deck for engineers
standfm
7
68k
Other Decks in Programming
See All in Programming
조합이폭발하는디자인시스템이걸눈으로도테스트하라고요
giljongyu
0
690
Railsバージョンを4倍にした話
optim
0
900
オーケストレーション記述言語 Katari
yukikurage
0
220
React Native에 현대적인 빌드 도구 더하기: Rollipop 구현기
leegeunhyeok
0
180
Getting Started with Vibe Coding
miccheng
0
140
LLM 101
dalinaum
0
440
Coding with AI: How to trust the storyteller (AWS Community Day Adria, Ljubljana 2026)
slobodan
0
130
AIで開発が速くなった先で、開発チームは何を目指すか
shihochan
1
1.9k
Web Framework Benchmark Battle 2026, Any%
a_matsuda
3
3.1k
sbt 2.0: takeoff
eed3si9n
0
180
3回つくってわかった、 定期実行ジョブ基盤の本質情報
takai
4
3.5k
動画プレイヤーはなぜカクつくのか 〜Flutterのレンダリングとネイティブの境界を解剖する〜
naruogram
0
320
Featured
See All Featured
Are puppies a ranking factor?
jonoalderson
2
4.1k
Claude Code のすすめ
schroneko
67
230k
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
4.6k
Digital Ethics as a Driver of Design Innovation
axbom
PRO
1
480
For a Future-Friendly Web
brad_frost
184
11k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
PRO
203
77k
AI Search: Where Are We & What Can We Do About It?
aleyda
0
8.2k
Keith and Marios Guide to Fast Websites
keithpitt
413
23k
Mind Mapping
helmedeiros
1
420
[SF Ruby Conf 2025] Rails X
palkan
3
1.5k
Stop Working from a Prison Cell
hatefulcrawdad
274
21k
Discover your Explorer Soul
emna__ayadi
2
1.3k
Transcript
ReactNative製アプリがAndroidだと遅いと いう問題に立ち向かった話 株式会社stand.fm エンジニア 三堀 裕 2021/05/21 React Native Meetup #12 LT大会!
自己紹介 - 三堀 裕(みつほり ゆう) - ホリー - stand.fm所属(2021/01~) -
Android, Flutterなどモバイル開発がメイン - ReactNativeはstand.fmで初めて触りました - 趣味:ダーツ、コーヒー、旅行、(麻雀) @1013Youmeee youmitsu @youmeee 2
- stand.fm Androidが重いという話 - パフォーマンスチューニングの話 a. react-navigationの画面遷移速度の改善 b. MaskedViewのレンダリング負荷への対応 c.
Hermesの導入 d. setIntervalのclear漏れ - まとめ アジェンダ
- stand.fm Androidが重いという話 - パフォーマンスチューニングの話 a. react-navigationの画面遷移速度の改善 b. MaskedViewのレンダリング負荷への対応 c.
Hermesの導入 d. setIntervalのclear漏れ - まとめ アジェンダ
stand.fmは誰でもかんたんに アプリで収録・LIVE配信ができる音声 プラットフォーム
stand.fm Androidが重いという話 - ユーザーの方々の声 - Androidアプリが重いのでどうにかしてほしい - 画面遷移が遅い(遷移するまで 10秒かかる) -
画面が固まる(fpsが落ちる) - etc... 6 パフォーマンス最適化のための改善をいくつか実施 今回はその中で4つ紹介します
- stand.fm Androidが重いという話 - パフォーマンスチューニングの話 a. react-navigationの画面遷移速度の改善 b. MaskedViewのレンダリング負荷への対応 c.
Hermesの導入 d. setIntervalのclear漏れ - まとめ アジェンダ
8 react-navigationの画面遷移速度改善 react-navigationの画面遷移時のアニメーションをブロックしてしまうのが原因 - componentDidMountでの非同期処理(async-await) - 最初にマウントされるコンポーネントの量が多い
1. componentDidMountのタイミングでawaitを使わない 2. ReactNativeのInteractionManagerを使う 3. 初期化時にmountされるコンポーネントを減らす https://reactnavigation.org/
9 ReactNativeのInteractionManagerを使う - InteractionManagerのrunAfterInteractionと呼ばれるコールバックを使用し、画面遷移アニメーション が終わってから初期化処理やレンダリングなどを実行させるようにする state = { afterInteractions:
false, } componentDidMount = () => { this.interactionPromise = InteractionManager.runAfterInteractions(() => { this.setState({ afterInteractions: true }) }) } render () { return ( <SafeAreaView> { this.state.afterInteractions && <ScreenContent /> } </SafeAreaView> ) }
10 hooksでrunAfterInteractionを使う // カスタムフックを定義 export const useAfterInteractions = (func:
() => any) => useEffect(() => { const interactionPromise = InteractionManager.runAfterInteractions(() => { func() }) return () => interactionPromise.cancel() }, []) const [afterInteractions, setAfterInteractions] = useState(false) useAfterInteractions(() => { setAfterInteractions(true) }) return ( <SafeAreaView> { afterInteractions && <ScreenContent /> } </SafeAreaView> )
11 対応後の画面遷移速度の比較 - ボタンをタップしてからチャンネル画面への画面遷移が完了するまでの所要時間を計測(施行 回数:30回) - 平均で約300ミリ秒速度が改善 平均: 1550ms
平均: 1245ms 約 300ms 改善
- stand.fm Androidが重いという話 - パフォーマンスチューニングの話 a. react-navigationの画面遷移速度の改善 b. MaskedViewのレンダリング負荷への対応 c.
Hermesの導入 d. setIntervalのclear漏れ - まとめ アジェンダ
13 MaskedViewのレンダリング負荷への対応 - masked-viewというReactNativeでマスク処理をするライブラリ - https://www.npmjs.com/package/@react-native-community/ masked-view
- Live画面のコメントリストの境界をぼかすために使っていた - FlatListをラップする形 - MaskedViewが頻繁にレンダリングされると端末のリソースが 著しく増加してしまう問題があった MaskedViewを表示させないように修正
- 以下の3つの指標の改善に効果があった - CPU使用率、メモリ使用量、バッテリー使用率 - フレームレートの改善にも効果があった 14
MaskedViewのレンダリングによるメモリ使用量の比較 Mask表示 Mask非表示 ←メモリ→ ←CPU→ ←バッテリー→ ←ネットワーク→ 「1GBくらいまで消費→GC」を頻繁に繰り返している メモリ使用量が平坦になっている
- stand.fm Androidが重いという話 - パフォーマンスチューニングの話 a. react-navigationの画面遷移速度の改善 b. MaskedViewのレンダリング負荷への対応 c.
Hermesの導入 d. setIntervalのclear漏れ - まとめ アジェンダ
16 Hermesの導入 - stand.fm Androidでは、JavaScriptエンジンにJavaScriptCore(jsc)を使っていたが、Hermesに移 行した - Hermesのメリット - アプリサイズの削減(jscoreより約2MB削減)
- 起動速度の高速化 - メモリ使用量の削減 - クラッシュフリーレートの改善にも効果があった - 97.5%→99.5% - https://github.com/facebook/hermes
- stand.fm Androidが重いという話 - パフォーマンスチューニングの話 a. react-navigationの画面遷移速度の改善 b. MaskedViewのレンダリング負荷への対応 c.
Hermesの導入 d. setIntervalのclear漏れ - まとめ アジェンダ
18 setIntervalのclear漏れ(バグ) - これが一番の原因だった - 放送音声の再生位置の取得のため、200ミリ秒ごとにネイティブモジュールの再生位置を取得 するメソッドを呼び出していた(setInterval) - clearIntervalが正常に行われていなかったことによって、放送画面がUnmountされたあともずっ
と再生位置の取得処理が行われる - 別の音声を再生するとまたinterval処理が新たに実行されるため、放送を再生した数の分アプ リが重くなる現象が起きていた - 最悪の場合「Excessive number of pending callbacks: 501.」が出てアプリが落ちる clearIntervalをcomponentWillUnmount時に実行するように修正
- stand.fm Androidが重いという話 - パフォーマンスチューニングの話 a. react-navigationの画面遷移速度の改善 b. MaskedViewのレンダリング負荷への対応 c.
Hermesの導入 d. setIntervalのclear漏れ - まとめ アジェンダ
まとめ - iOSに比べると、Android端末はスペック差によるパフォーマンスの影響を受けやすい - react-navigation使用時は画面遷移時のアニメーションをブロックしないようにする - InteractionManagerを使う。componentDidMount時にawaitを極力使わない - 特にAndroidではアニメーションやマスク処理周りは端末リソースに負荷がかかる場合がある ので注意が必要
- Hermesは良いぞ、clearInterval忘れに注意 - 他にもいくつかパフォーマンス改善 issueを計画中。ユーザーに気持ちよくアプリを使ってもらう ための改善を諦めずにやっていきたい 20
We are hiring! エンジニア積極的に募集中です https://corp.stand.fm/recruit 詳細はこちら • CTO候補 • VPoE候補
• クライアントエンジニア • バックエンドエンジニア • 機械学習エンジニア • 配信基盤エンジニア • QAエンジニア • エンジニアリングマネージャー • UI/UXデザイナー 積極募集しているプロダクト開発メンバー
None