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
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
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
Railsバージョンを4倍にした話
optim
0
890
作れる、でも消せるか?──安全に「枯らして消す」機能削除術 / Drain, Then Delete
chobishiba
3
1.3k
baseline으로 마이그레이션, 리팩토링 안전하게 맡기기
fornewid
1
780
AIがコードを書いてくれる時代、我々は何を確かめるのか
yosuke_furukawa
PRO
13
5.4k
우리의 Nitro Modules는 당신의 Turbo Modules보다 아름답다
l2hyunwoo
0
250
S3 TablesのIcebergデータに、AIエージェントからアクセスしてみた / 20261016developersio2026joetsu-accessing-iceberg-in-s3tables-via-agent
kasacchiful
PRO
0
250
3回つくってわかった、 定期実行ジョブ基盤の本質情報
takai
4
3.5k
AIが生成したコードは読むべきか?抽象化設計とコードの品質保証 / abstraction-design-and-quality
minodriven
14
8k
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
520
SODA - FACT BOOK(JP)
sodainc
1
40k
高橋メソッドでCVE解説シリーズ 〜CVE-2026-112816〜
hakkadaikon
0
150
コードで差別化できない時代の ソフトウェアエンジニアリング / Software Engineering in an Era Where Code Doesn’t Differentiate
kishida
2
220
Featured
See All Featured
The Director’s Chair: Orchestrating AI for Truly Effective Learning
tmiket
1
340
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.9k
A better future with KSS
kneath
240
18k
世界の人気アプリ100個を分析して見えたペイウォール設計の心得
akihiro_kokubo
PRO
74
43k
Navigating Weather and Climate Data
rabernat
0
570
Agile that works and the tools we love
rasmusluckow
331
22k
Future Trends and Review - Lecture 12 - Web Technologies (1019888BNR)
signer
PRO
0
3.8k
Navigating the moral maze — ethical principles for Al-driven product design
skipperchong
2
670
The untapped power of vector embeddings
frankvandijk
2
2k
Game over? The fight for quality and originality in the time of robots
wayneb77
1
320
Stewardship and Sustainability of Urban and Community Forests
pwiseman
0
580
Rails Girls Zürich Keynote
gr2m
96
14k
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