Repository navigation
⚡ Bolt: 배열 최댓값 계산 시 reduce 및 useMemo 적용하여 성능 최적화 #793
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: developmental
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,3 @@ | ||
| ## 2026-08-11 - Use `Date.parse` for timestamp primitives | ||
|
|
||
| **Learning:** `Date.parse(value)` returns the timestamp primitive directly, while `new Date(value).getTime()` also constructs a `Date` object. Both use the same ECMAScript string-parsing semantics for these call sites. | ||
|
|
||
| **Action:** In frequently executed paths that only need a timestamp primitive, prefer `Date.parse(value)`. Treat the allocation reduction as a bounded micro-optimization unless a committed benchmark establishes a larger runtime effect. | ||
| ## 2025-02-19 - 배열 최댓값 계산 시 Math.max와 스프레드 연산자 사용으로 인한 성능 및 콜 스택 이슈 해결 | ||
| **Learning:** React 컴포넌트(`DelegationInsight`, `MembersPage`, `TopUsersList` 등)에서 리스트 렌더링 시 배열의 최댓값을 구하기 위해 `Math.max(...array)`를 사용하면 배열 크기가 클 때 'Maximum call stack size exceeded' 에러가 발생할 수 있습니다. 또한 매 렌더링 주기마다 무거운 동기적 계산을 반복하여 성능 저하를 초래합니다. | ||
| **Action:** 항상 `Math.max(...array)` 대신 `.reduce((max, item) => Math.max(max, item), 0)`를 사용하여 모든 크기의 데이터셋을 안전하게 처리해야 합니다. React 컴포넌트에서 이러한 파생 값을 계산할 때는 `useMemo`로 감싸 데이터가 변경될 때만 재계산되도록 하여 불필요한 렌더링을 방지해야 합니다. | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,15 +1,24 @@ | ||
| import Link from 'next/link' | ||
| import { Wand2, ArrowUpRight } from 'lucide-react' | ||
| import { ChartCard } from '@/components/dashboard/chart-card' | ||
| import { StatList, StatListRow } from '@/components/dashboard/stat-list' | ||
| import type { WeeklyInsights } from '@/types/reports' | ||
| import Link from "next/link"; | ||
| import { useMemo } from "react"; | ||
| import { Wand2, ArrowUpRight } from "lucide-react"; | ||
| import { ChartCard } from "@/components/dashboard/chart-card"; | ||
| import { StatList, StatListRow } from "@/components/dashboard/stat-list"; | ||
| import type { WeeklyInsights } from "@/types/reports"; | ||
|
|
||
| interface DelegationInsightProps { | ||
| insight: WeeklyInsights['delegation'] | ||
| orgSlug: string | ||
| insight: WeeklyInsights["delegation"]; | ||
| orgSlug: string; | ||
| } | ||
|
|
||
| export function DelegationInsight({ insight, orgSlug }: DelegationInsightProps) { | ||
| export function DelegationInsight({ | ||
| insight, | ||
| orgSlug, | ||
| }: DelegationInsightProps) { | ||
| const maxCount = useMemo( | ||
| () => insight.topAgents.reduce((max, a) => Math.max(max, a.callCount), 1), | ||
| [insight.topAgents], | ||
| ); | ||
|
Comment on lines
+17
to
+20
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔍 Bounded lists weaken the performance case The weekly agent list holds at most ten entries; overview users holds five. Neither spread-based maximum reaches argument limits, and memoization adds bookkeeping for these small reductions. Was this helpful? React with 👍 or 👎 to provide feedback. |
||
|
|
||
| if (insight.taskCount === 0) { | ||
| return ( | ||
| <ChartCard | ||
|
|
@@ -25,11 +34,9 @@ export function DelegationInsight({ insight, orgSlug }: DelegationInsightProps) | |
| 이번 주 위임 활용 없음 | ||
| </p> | ||
| </ChartCard> | ||
| ) | ||
| ); | ||
| } | ||
|
|
||
| const maxCount = Math.max(1, ...insight.topAgents.map((a) => a.callCount)) | ||
|
|
||
| return ( | ||
| <ChartCard | ||
| title={ | ||
|
|
@@ -56,7 +63,9 @@ export function DelegationInsight({ insight, orgSlug }: DelegationInsightProps) | |
| )} | ||
| {insight.sampleSessionIds.length > 0 && ( | ||
| <div className="pt-2 border-t border-border"> | ||
| <div className="text-xs text-muted-foreground mb-2">효과적 위임 사례</div> | ||
| <div className="text-xs text-muted-foreground mb-2"> | ||
| 효과적 위임 사례 | ||
| </div> | ||
| <div className="flex flex-wrap gap-2"> | ||
| {insight.sampleSessionIds.map((sid) => ( | ||
| <Link | ||
|
|
@@ -73,5 +82,5 @@ export function DelegationInsight({ insight, orgSlug }: DelegationInsightProps) | |
| )} | ||
| </div> | ||
| </ChartCard> | ||
| ) | ||
| ); | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔍 Earlier optimization guidance disappears
The new lesson replaces the existing
Date.parseguidance rather than adding to it. Reviewers lose the prior optimization rationale.Was this helpful? React with 👍 or 👎 to provide feedback.