Repository navigation
⚡ Bolt: 배열 최댓값 계산 시 reduce 및 useMemo 적용하여 성능 최적화 - #793
seonghobae wants to merge 2 commits into
Conversation
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 38 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
| ## 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`로 감싸 데이터가 변경될 때만 재계산되도록 하여 불필요한 렌더링을 방지해야 합니다. |
| const maxCount = useMemo( | ||
| () => insight.topAgents.reduce((max, a) => Math.max(max, a.callCount), 1), | ||
| [insight.topAgents], | ||
| ); |
There was a problem hiding this comment.
🔍 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.
💡 What
React 컴포넌트(
DelegationInsight,MembersPage,TopUsersList) 내 배열 최댓값 계산 로직에서Math.max(...array)를.reduce()방식으로 변경하고,useMemo를 적용하여 렌더링 최적화를 수행했습니다.🎯 Why
배열 크기가 클 경우
Math.max(...array)방식은 콜 스택 초과(Maximum call stack size exceeded) 에러를 발생시킬 위험이 있습니다. 또한, 매 렌더링마다 배열 전체를 순회하며 최댓값을 구하는 계산은 컴포넌트의 성능 저하를 초래할 수 있으므로 메모이제이션이 필요합니다.📊 Impact
useMemo를 통해 배열이 변경될 때만 최댓값을 다시 계산하므로 불필요한 연산을 줄이고 렌더링 성능이 향상됩니다.🔬 Measurement
pnpm test -- --coverage명령어를 통해 테스트 코드를 실행하여 정상 작동 여부와 커버리지를 확인합니다. 기능의 변경 없이 성능 이점이 적용되었는지 확인할 수 있습니다.PR created automatically by Jules for task 11611458650646585268 started by @seonghobae