Skip to content

パフォーマンス改善: 不要な再計算とレンダーを削減 - #5547

Merged
TinyKitten merged 2 commits into
devfrom
claude/ios-version-requirements-Uw9Qc
Mar 9, 2026
Merged

TinyKitten merged 2 commits into
devfrom
claude/ios-version-requirements-Uw9Qc

Conversation

@TinyKitten

@TinyKitten TinyKitten commented Mar 9, 2026 •

Copy link
Copy Markdown
Member

Summary

第1コミット: 不要な再計算とレンダーを削減

  • Transfers.tsx: 冗長な .map((l) => l) チェーンを削除し、1回の .map() に統合
  • CommonCard.tsx: titleOrLineName.split() の結果を useMemo でメモ化。Subtitle を React.memo でラップ
  • FooterTabBar.tsx: 定数 iconColor を useMemo からコンポーネント外の定数 ICON_COLOR に移動

第2コミット: 各コンポーネントのレンダー内計算をメモ化

  • PresetCard.tsx: renderTextWithSmallerParens の結果を useMemo でメモ化(1レンダーあたり2回の呼び出しを削減)
  • SelectBoundModal.tsx: loopLineDirectionText 内の .map() を事前メモ化した文字列に置換
  • PadLineMarks.tsx: JSX内のテキスト生成ロジックを useMemo で事前計算
  • RouteInfoModal.tsx: renderItem 内の Set 生成を stationSubtitles Map に事前計算

Regression risk

  • 表示ロジックの変更はなく、メモ化とコード整理のみのためリグレッションリスクは低い

Commands executed

npm run lint
npm run typecheck
npm test (136 suites, 1262 tests passed)

Test plan

  • 乗換路線一覧(Transfers)が正しく表示されること
  • CommonCard のタイトル(括弧付き)とサブタイトルが正しく表示されること
  • FooterTabBar のアイコン色が正しく切り替わること
  • PresetCard の駅コード表示が正しいこと
  • SelectBoundModal の方面テキストが正しいこと
  • PadLineMarks の乗換路線名が正しく表示されること
  • RouteInfoModal の路線名サブタイトルが正しく表示されること

https://claude.ai/code/session_01P3RbNTu7mxQvLyfzzerBFB

Summary by CodeRabbit

リリースノート

  • Refactor
    • 各コンポーネントで表示レンダリングを事前計算・メモ化し、UI の応答性とスクロール時の表示性能を改善
    • 表示テキスト(駅名・行名・副題・路線ラベル)を安定化し、表示結果は現状維持しつつ再描画を削減
    • フッタのアイコン色管理を定数化して表示色を安定化

@github-actions github-actions Bot added the react label Mar 9, 2026
@coderabbitai

coderabbitai Bot commented Mar 9, 2026 •

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

複数コンポーネントでレンダリング最適化とロジック平坦化を導入。主にuseMemo/React.memoの追加、冗長な計算の事前算出、モジュール定数化、マッピング処理の単純化を行う変更群。

Changes

Cohort / File(s) Summary
CommonCard コンポーネント
src/components/CommonCard.tsx
Subtitle を React.memo 化。タイトル分割を useMemo (titleParts) に移動し、スケルトンの冗長パスを削除、inbound/outbound 表示ロジックへ変更。レンダリング参照を titleParts に統一。
FooterTabBar コンポーネント
src/components/FooterTabBar.tsx
useMemo を削除し、アイコン色をモジュールレベルの ICON_COLOR 定数へ移行。Ionicons の color プロップ参照を定数化。
Transfers コンポーネント
src/components/Transfers.tsx
stationNumbers の生成を二重 map から単一 map に平坦化。空の lineSymbol/stationNumber のフォールバック算出を一箇所に集約。
PadLineMarks コンポーネント
src/components/PadLineMarks.tsx
各 transfer line の表示名と必要なサフィックスを事前計算する lineLabels を useMemo 化。レンダリング時の per-item 計算を削減し、依存に isDifferentStationName, isEn, station を追加。
PresetCard コンポーネント
src/components/PresetCard.tsx
renderTextWithSmallerParens の出力を memoize して leftCodeRendered / rightCodeRendered として再利用。レンダリング呼び出しを置換(振る舞いは同等)。
RouteInfoModal コンポーネント
src/components/RouteInfoModal.tsx
駅ごとのサブタイトルを事前計算した stationSubtitles: Map に移し、renderItem はそのマップから取得して使用。renderItem の依存に stationSubtitles を追加。
SelectBoundModal コンポーネント
src/components/SelectBoundModal.tsx
inbound/outbound 名の集合を useMemo で事前集約(日本語・ローマ字それぞれ)。ループ内テキスト生成はこれらの集約を参照するよう変更し、コールバック依存を更新。

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Poem

🐇✨ メモを抱え跳ねる私
余分は減らし道は平らに
色は定まり、文字は整い
ループは軽く、ビューは速く
小さなリファクタ、喜び跳ねる

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed PRタイトル「パフォーマンス改善: 不要な再計算とレンダーを削減」は、複数ファイルにおけるuseMemoとReact.memoの導入によるパフォーマンス最適化という主要な変更内容を正確に要約しており、ファイル一覧や曖昧な表現を含まず、チームメンバーが変更内容を理解できる明確性があります。
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch claude/ios-version-requirements-Uw9Qc

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 (2)
src/components/Transfers.tsx (1)

103-122: .find() の重複呼び出しを1回にまとめることを検討してください。

同じ条件 !sn.lineSymbol?.length で .find() を3回呼び出しています。結果を一度変数に格納することで、不要な配列走査を削減できます。

♻️ 提案する修正
        if (!lineSymbol.length || !stationNumber.length) {
+         const emptySymbolData = l.station?.stationNumbers?.find(
+           (sn) => !sn.lineSymbol?.length
+         );
          const stationNumberWhenEmptySymbol =
-           l.station?.stationNumbers?.find((sn) => !sn.lineSymbol?.length)
-             ?.stationNumber ?? '';
+           emptySymbolData?.stationNumber ?? '';
          const lineSymbolWhenEmptySymbol = l.lineSymbols?.[0]?.symbol ?? '';
          const lineSymbolColorWhenEmptySymbol =
-           l.station?.stationNumbers?.find((sn) => !sn.lineSymbol?.length)
-             ?.lineSymbolColor ?? '#000000';
+           emptySymbolData?.lineSymbolColor ?? '#000000';
          const lineSymbolShapeWhenEmptySymbol =
-           l.station?.stationNumbers?.find((sn) => !sn.lineSymbol?.length)
-             ?.lineSymbolShape ?? 'NOOP';
+           emptySymbolData?.lineSymbolShape ?? 'NOOP';
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/components/Transfers.tsx` around lines 103 - 122, The repeated calls to
l.station?.stationNumbers?.find((sn) => !sn.lineSymbol?.length) should be
collapsed into a single lookup: assign the result to a const (e.g.,
emptySymbolSn) and then derive stationNumberWhenEmptySymbol,
lineSymbolWhenEmptySymbol, lineSymbolColorWhenEmptySymbol, and
lineSymbolShapeWhenEmptySymbol from that single variable with the same fallback
defaults; update the return block in the same if branch so it uses emptySymbolSn
instead of calling .find() three times.
src/components/CommonCard.tsx (1)

125-162: SubtitleのReact.memo化は適切な最適化です。

親コンポーネントの再レンダー時に、propsが変更されていない場合の不要な再レンダーを防止できます。

デバッグ時のReact DevToolsでの識別を容易にするため、displayNameの追加を検討してください。

🔧 displayName追加(オプション)
 const Subtitle = memo(
   ({ inboundText, outboundText, numberOfLines, loading }: SubtitleProps) => {
     // ... component body
   }
 );
+Subtitle.displayName = 'Subtitle';
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/components/CommonCard.tsx` around lines 125 - 162, Add a displayName to
the memoized component to make it easier to identify in React DevTools: after
the memoized declaration of Subtitle (const Subtitle = memo(...)), set
Subtitle.displayName = 'Subtitle' so the component shows a readable name in
debugging tools; ensure you add this immediately after the Subtitle constant
definition.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@src/components/CommonCard.tsx`:
- Around line 125-162: Add a displayName to the memoized component to make it
easier to identify in React DevTools: after the memoized declaration of Subtitle
(const Subtitle = memo(...)), set Subtitle.displayName = 'Subtitle' so the
component shows a readable name in debugging tools; ensure you add this
immediately after the Subtitle constant definition.

In `@src/components/Transfers.tsx`:
- Around line 103-122: The repeated calls to
l.station?.stationNumbers?.find((sn) => !sn.lineSymbol?.length) should be
collapsed into a single lookup: assign the result to a const (e.g.,
emptySymbolSn) and then derive stationNumberWhenEmptySymbol,
lineSymbolWhenEmptySymbol, lineSymbolColorWhenEmptySymbol, and
lineSymbolShapeWhenEmptySymbol from that single variable with the same fallback
defaults; update the return block in the same if branch so it uses emptySymbolSn
instead of calling .find() three times.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 13229468-cdd9-411d-ba64-c20b5a920388

📥 Commits

Reviewing files that changed from the base of the PR and between 9548702 and d9673ca.

📒 Files selected for processing (3)
  • src/components/CommonCard.tsx
  • src/components/FooterTabBar.tsx
  • src/components/Transfers.tsx

@TinyKitten TinyKitten self-assigned this Mar 9, 2026

@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/components/SelectBoundModal.tsx (1)

244-250: nameRomanがnullの場合の考慮(任意)

normalLineDirectionTextでは.filter(Boolean)でnull値を除外していますが、ここでは除外していません。一貫性のため、同様のフィルタリングを追加することを検討してください。

♻️ 提案
  const inboundNamesRoman = useMemo(
-   () => inboundStations.map((s) => s.nameRoman).join(' and '),
+   () => inboundStations.map((s) => s.nameRoman).filter(Boolean).join(' and '),
    [inboundStations]
  );
  const outboundNamesRoman = useMemo(
-   () => outboundStations.map((s) => s.nameRoman).join(' and '),
+   () => outboundStations.map((s) => s.nameRoman).filter(Boolean).join(' and '),
    [outboundStations]
  );
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/components/SelectBoundModal.tsx` around lines 244 - 250,
inboundNamesRoman and outboundNamesRoman currently join station.nameRoman
without excluding null/undefined, unlike normalLineDirectionText which uses
.filter(Boolean); update the useMemo callbacks for inboundNamesRoman and
outboundNamesRoman to filter out falsy nameRoman values before joining (e.g.,
filter by s.nameRoman or map then filter(Boolean)) so nulls are not included in
the joined string, keeping the dependency arrays the same.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@src/components/SelectBoundModal.tsx`:
- Around line 244-250: inboundNamesRoman and outboundNamesRoman currently join
station.nameRoman without excluding null/undefined, unlike
normalLineDirectionText which uses .filter(Boolean); update the useMemo
callbacks for inboundNamesRoman and outboundNamesRoman to filter out falsy
nameRoman values before joining (e.g., filter by s.nameRoman or map then
filter(Boolean)) so nulls are not included in the joined string, keeping the
dependency arrays the same.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: d189730e-587d-410e-b96f-30cd3af46eb3

📥 Commits

Reviewing files that changed from the base of the PR and between d9673ca and bf04808.

📒 Files selected for processing (4)
  • src/components/PadLineMarks.tsx
  • src/components/PresetCard.tsx
  • src/components/RouteInfoModal.tsx
  • src/components/SelectBoundModal.tsx

@TinyKitten
TinyKitten merged commit 73b75d5 into dev Mar 9, 2026
5 checks passed
@TinyKitten
TinyKitten deleted the claude/ios-version-requirements-Uw9Qc branch March 9, 2026 16:09
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