Skip to content

パフォーマンス改善: 不要な再レンダーと冗長な通信を削減 - #6151

Merged
TinyKitten merged 9 commits into
devfrom
claude/dev-performance-issues-tugoxt
Jun 9, 2026
Merged

TinyKitten merged 9 commits into
devfrom
claude/dev-performance-issues-tugoxt

Conversation

@TinyKitten

@TinyKitten TinyKitten commented Jun 9, 2026 •

Copy link
Copy Markdown
Member

概要

devブランチのパフォーマンス監査で検出した、不要な再レンダー・再マウント・冗長なブリッジ/ネットワーク通信を解消するパフォーマンス改善です。アプリの表示・挙動は変更しません。

変更の種類

  • バグ修正
  • 新機能
  • リファクタリング
  • ドキュメント
  • CI/CD
  • その他

変更内容

  • チェブロン点滅を新設の BlinkingChevron コンポーネントへ分離し、East/Toei/Saikyo/JRKyushu の4テーマで毎秒8セル全体が再レンダーされていた問題を解消(StationNameCell を React.memo 化)
  • LineBoard の useCallback コンポーネント(<Inner />)を useMemo 要素化し、依存変化のたびにボードのサブツリー全体がアンマウント→再マウントされていた問題を修正(山手線iPadテーマでアニメーションが何度も走る既知症状の原因)
  • src/store/selectors/ にフィールド単位の派生atom(arrivedAtom / approachingAtom / stationsAtom / leftStationsAtom / enabledLanguagesAtom / locationAccuracyAtom)を新設し、LineBoard系9コンポーネントと useBadAccuracy のモノリシックatom全体購読を解消(ヘッダー言語ローテーションやGPS座標更新による無関係な再レンダーを防止)
  • useRefreshStation で値が変わらない場合のatom書き込みを抑制し、全購読者への不要な再レンダー通知を防止
  • 路線変更時の駅一覧と種別一覧のGraphQLフェッチを Promise.all で並列化
  • Remote Config の同期読み取り(getMaxPermitAccuracy 等)にモジュール内キャッシュを追加し、GPS更新ごとのSDK問い合わせを削減
  • PadArch の区間クリップスタイル・darken()・駅ごとのドット/ラベルスタイルを useMemo で事前計算
  • Apple Watch への送信を内容変化時に限定(シリアライズ比較で重複送信をスキップ)し、全駅リスト構築を駅一覧/方向の変化時のみに限定

テスト

  • npm run lint が通ること
  • npm test が通ること
  • npm run typecheck が通ること

npm run lint && npm test && npm run typecheck をローカルで実行し全て通過(170スイート / 1807テスト)。新規テストとして BlinkingChevron(点滅順序)、各selector(値導出と無関係フィールド変更時の通知抑制)、Remote Configキャッシュ(キャッシュ/無効化挙動)を追加。

実機でのUI確認(4テーマのチェブロン点滅・山手線iPadテーマの到着アニメーション)は未実施のため、マージ前の確認を推奨します。

関連Issue

スクリーンショット(任意)

https://claude.ai/code/session_01B1nvgXQqduJFBSmP9ZGKRB


Generated by Claude Code

Summary by CodeRabbit

  • 新機能

    • 到着状況を示す「点滅チェブロン」を導入しました。
  • バグ修正

    • 不要な再描画を削減し描画負荷を低減、表示の安定性を向上しました。
    • 位置情報の精度判定と関連動作を改善しました。
    • リモート設定読み取りの効率化により不必要な取得を抑制しました。
  • 改善

    • ライン切替時のデータ読み込みを並列化して高速化しました。
    • ウォッチ連携で同一内容の重複送信を抑える最適化を実施しました。
  • テスト

    • 関連ユニットテストを多数追加・更新しました。

@github-actions github-actions Bot added the react label Jun 9, 2026
@TinyKitten TinyKitten self-assigned this Jun 9, 2026
@coderabbitai

coderabbitai Bot commented Jun 9, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: c21fda2f-08dd-4815-b22a-3a1056a01ac5

📥 Commits

Reviewing files that changed from the base of the PR and between 655ae09 and ae82cb6.

📒 Files selected for processing (1)
  • src/store/selectors/station.test.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/store/selectors/station.test.ts

📝 Walkthrough

Walkthrough

複数の LineBoard コンポーネントとその依存層全体で Jotai セレクタを導入し、stationState/navigationState/locationAtom から個別フィールドのみを購読する粒度に切り替え。新しい BlinkingChevron コンポーネントで点滅ロジックを統一し、各ボードから内部状態管理を削除。併行してパフォーマンス最適化(キャッシング・事前計算)も実施。

Changes

Jotai セレクタ導入と点滅制御の統一化

Layer / File(s) Summary
Jotai セレクタの定義とテスト
src/store/selectors/station.ts, src/store/selectors/station.test.ts, src/store/selectors/navigation.ts, src/store/selectors/navigation.test.ts, src/store/selectors/location.ts, src/store/selectors/location.test.ts
stationState から arrivedAtom/approachingAtom/stationsAtom、navigationState から leftStationsAtom/enabledLanguagesAtom、locationAtom から locationAccuracyAtom の派生セレクタを新規追加。各セレクタの動作と購読通知条件をテストで検証。
BlinkingChevron コンポーネント実装と統合
src/components/LineBoard/shared/components/BlinkingChevron.tsx, src/components/LineBoard/shared/components/BlinkingChevron.test.tsx, src/components/LineBoard/shared/components/index.ts
2色タプルを1秒ごとに交互切替する BlinkingChevron を新規実装。内部で useState/useInterval を用い、ChevronTY へ現在色を渡す。テストはフェイクタイマーで点滅挙動を検証。
LineBoardEast・E231 の統合的更新
src/components/LineBoardEast.tsx, src/components/LineBoardEast.test.tsx, src/components/LineBoardE231.tsx
到着判定を arrivedAtom に切替。各種コンポーネントから chevronColor state と useInterval を削除し、色ペアタプル chevronColors を StationNameCell に渡して BlinkingChevron に委譲。StationNameCell をメモ化。テストを更新。
LineBoardJRKyushu・Saikyo の点滅統一化
src/components/LineBoardJRKyushu.tsx, src/components/LineBoardJRKyushu.test.tsx, src/components/LineBoardSaikyo.tsx, src/components/LineBoardSaikyo.test.tsx
内部点滅ロジックを削除し固定色定数(JR_KYUSHU_CHEVRON_COLORS、SAIKYO_CHEVRON_COLORS)を渡して BlinkingChevron を使用。arrived を arrivedAtom 参照へ統一、セルを memo 化。テストは BlinkngChevron 呼び出しと useInterval 非呼び出しを検証。
LineBoardToei・West のセレクタ・点滅統一
src/components/LineBoardToei.tsx, src/components/LineBoardToei.test.tsx, src/components/LineBoardWest.tsx, src/components/LineBoardWest.test.tsx
navigationState/stationState の全体購読をやめ、leftStationsAtom/arrivedAtom/approachingAtom/stationsAtom/enabledLanguagesAtom を個別購読。点滅ロジックを BlinkngChevron に統一しテストは atom 別分岐の mockAtoms を導入。
LineBoard・JO・YamanotePad のセレクタ適用
src/components/LineBoard.tsx, src/components/LineBoard.test.tsx, src/components/LineBoardJO.tsx, src/components/LineBoardJO.test.tsx, src/components/LineBoardYamanotePad.tsx, src/components/LineBoardYamanotePad.test.tsx
LineBoard は leftStationsAtom のみ購読に変更し、Inner コンポーネント定義を useMemo に置換。JO と YamanotePad は arrivedAtom を参照。テストの useAtomValue モックを mockAtoms 系へ統一。
パフォーマンス最適化(キャッシング・事前計算)
src/lib/remoteConfig.ts, src/lib/remoteConfig.test.ts, src/hooks/useAppleWatch.ts, src/hooks/useRefreshStation.ts, src/hooks/useBadAccuracy.ts, src/components/PadArch.tsx, src/screens/Main.tsx
remoteConfig にモジュール内キャッシュと reset 関数を追加。useAppleWatch は stationList を useMemo 化し直近送信と同一なら送信をスキップ。useRefreshStation は差分が無ければ prev を返すガードを追加。useBadAccuracy は locationAccuracyAtom を購読。PadArch は描画レイアウト/駅情報を useMemo で事前計算。changeOperatingLine を並列取得に変更。

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

  • TrainLCD/MobileApp#6135: useRefreshStation の接近判定ロジック変更と関連が深いため参照を推奨。

Poem

🐰 コードを跳ねて見回れば、

セレクタ揃いで軽やかに、
チェブロンはぴかっと交互に、
再描画減って嬉しいな、
ラビットは今日もレビュー跳ねる ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed PRタイトルは、変更内容の主要な目的である「パフォーマンス改善: 不要な再レンダーと冗長な通信を削減」を簡潔かつ明確に表現しており、実装ファイル群の内容(新規コンポーネント分離、派生atom導入、キャッシュ追加など)と一致している。
Description check ✅ Passed PR説明は、テンプレートの必須セクション(概要、変更の種類、変更内容、テスト、関連Issue)を網羅しており、具体的な改善内容と実施したテストが詳細に記載されている。ただし、実機確認が未実施である旨が明記されている。
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch claude/dev-performance-issues-tugoxt

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
src/store/selectors/station.test.ts (1)

5-37: ⚡ Quick win

stationsAtom のテストカバレッジを追加することを推奨

arrivedAtom と approachingAtom は十分にテストされていますが、stationsAtom のテストケースがありません。実装パターンは同じですが、明示的なテストがあると保守性が向上します。

📝 提案: stationsAtom のテストケース追加
   it('stationStateのフィールド値を導出する', () => {
     const store = createStore();
     store.set(stationState, {
       ...store.get(stationState),
       arrived: true,
       approaching: false,
+      stations: [{ id: 1, name: 'Test Station' }],
     });
     expect(store.get(arrivedAtom)).toBe(true);
     expect(store.get(approachingAtom)).toBe(false);
+    expect(store.get(stationsAtom)).toEqual([{ id: 1, name: 'Test Station' }]);
   });
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/store/selectors/station.test.ts` around lines 5 - 37, Add tests for
stationsAtom similar to the existing arrivedAtom/approachingAtom specs: create a
store via createStore(), set stationState to change the fields that stationsAtom
derives from, assert store.get(stationsAtom) reflects the expected derived
value, and add a subscriber via store.sub(stationsAtom, listener) to assert it
is only notified when the relevant stationState fields for stationsAtom actually
change; use the same pattern as the two existing tests (createStore,
store.set(stationState, ...), expect(store.get(...)) and expect(listener)
assertions) and clean up with unsub().
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@src/store/selectors/station.test.ts`:
- Around line 5-37: Add tests for stationsAtom similar to the existing
arrivedAtom/approachingAtom specs: create a store via createStore(), set
stationState to change the fields that stationsAtom derives from, assert
store.get(stationsAtom) reflects the expected derived value, and add a
subscriber via store.sub(stationsAtom, listener) to assert it is only notified
when the relevant stationState fields for stationsAtom actually change; use the
same pattern as the two existing tests (createStore, store.set(stationState,
...), expect(store.get(...)) and expect(listener) assertions) and clean up with
unsub().

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: f7ffdd1b-b30e-4693-8df5-9d2d0b3162f5

📥 Commits

Reviewing files that changed from the base of the PR and between 8ff907c and 655ae09.

📒 Files selected for processing (33)
  • src/components/LineBoard.test.tsx
  • src/components/LineBoard.tsx
  • src/components/LineBoard/shared/components/BlinkingChevron.test.tsx
  • src/components/LineBoard/shared/components/BlinkingChevron.tsx
  • src/components/LineBoard/shared/components/index.ts
  • src/components/LineBoardE231.tsx
  • src/components/LineBoardEast.test.tsx
  • src/components/LineBoardEast.tsx
  • src/components/LineBoardJO.test.tsx
  • src/components/LineBoardJO.tsx
  • src/components/LineBoardJRKyushu.test.tsx
  • src/components/LineBoardJRKyushu.tsx
  • src/components/LineBoardSaikyo.test.tsx
  • src/components/LineBoardSaikyo.tsx
  • src/components/LineBoardToei.test.tsx
  • src/components/LineBoardToei.tsx
  • src/components/LineBoardWest.test.tsx
  • src/components/LineBoardWest.tsx
  • src/components/LineBoardYamanotePad.test.tsx
  • src/components/LineBoardYamanotePad.tsx
  • src/components/PadArch.tsx
  • src/hooks/useAppleWatch.ts
  • src/hooks/useBadAccuracy.ts
  • src/hooks/useRefreshStation.ts
  • src/lib/remoteConfig.test.ts
  • src/lib/remoteConfig.ts
  • src/screens/Main.tsx
  • src/store/selectors/location.test.ts
  • src/store/selectors/location.ts
  • src/store/selectors/navigation.test.ts
  • src/store/selectors/navigation.ts
  • src/store/selectors/station.test.ts
  • src/store/selectors/station.ts

@TinyKitten
TinyKitten merged commit e35f832 into dev Jun 9, 2026
5 checks passed
@TinyKitten
TinyKitten deleted the claude/dev-performance-issues-tugoxt branch June 9, 2026 23:39
@TinyKitten TinyKitten mentioned this pull request Jun 10, 2026
5 of 9 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants