Skip to content

⚡ Bolt: 불필요한 배열 할당 및 Date 파싱 최적화 (성능 개선) - #399

Open
seonghobae wants to merge 2 commits into
developmentalfrom
bolt/performance-improvement-12076806521130125588
Open

⚡ Bolt: 불필요한 배열 할당 및 Date 파싱 최적화 (성능 개선)#399
seonghobae wants to merge 2 commits into
developmentalfrom
bolt/performance-improvement-12076806521130125588

Conversation

@seonghobae

@seonghobae seonghobae commented Aug 6, 2026

Copy link
Copy Markdown

💡 What: session-timeline-chart.tsxevents/route.ts에서 불필요한 반복문 중첩(filter, map)과 Date 객체 생성 방식을 단일 루프 및 사전 파싱 방식으로 변경했습니다.

🎯 Why: 정렬 함수의 비교기(comparator) 내부나 필터/맵 체이닝 과정에서 반복적인 Date 객체 할당과 다중 O(N) 순회가 발생해 성능 저하 및 메모리 가비지 컬렉션 부하를 야기합니다.

📊 Impact:

  • session-timeline-chart.tsx에서 정렬 전 사전 날짜 파싱을 통해 O(N log N) 객체 할당을 방지.
  • events/route.ts 및 차트 내에서 .filter().map() 체인을 하나의 루프로 병합하여 배열 순회 횟수를 단축하고 임시 배열 할당을 제거.

🔬 Measurement: 대량의 툴 이벤트나 세션 사용량이 있을 때 클라이언트 렌더링 지연 시간 및 API 이벤트 처리 시간 감소.


PR created automatically by Jules for task 12076806521130125588 started by @seonghobae

Summary by CodeRabbit

  • 성능 개선
    • 과거 사용량 데이터 처리 속도와 메모리 효율을 개선했습니다.
    • 세션 타임라인 차트의 메시지 수집 및 날짜 정렬 성능을 향상했습니다.
    • 대규모 배열과 날짜 데이터를 더 효율적으로 처리하도록 최적화했습니다.

@google-labs-jules

Copy link
Copy Markdown

👋 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 @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@coderabbitai

coderabbitai Bot commented Aug 6, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

API의 과거 날짜 수집과 SessionTimelineChart의 배열 처리 및 타임스탬프 파싱을 최적화했습니다. 관련 실행 지침도 추가했습니다.

Changes

처리 성능 최적화

Layer / File(s) Summary
과거 사용량 날짜 수집
.jules/bolt.md, packages/web/src/app/api/events/route.ts
API가 단일 반복문과 Set으로 과거 날짜를 수집합니다. 대규모 배열 처리와 날짜 정렬 최적화 지침을 추가했습니다.
타임라인 데이터 처리
packages/web/src/components/dashboard/session-timeline-chart.tsx
사용량 타임스탬프를 정렬 전에 한 번 파싱합니다. TOOL 메시지 추출과 ToolCallPoint 생성은 단일 반복문으로 처리합니다.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

Suggested reviewers: greatsumini

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed 제목은 날짜 파싱과 불필요한 배열 할당을 최적화하는 PR의 주요 변경 사항을 정확하고 간결하게 설명합니다.
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.
✨ 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 bolt/performance-improvement-12076806521130125588

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
packages/web/src/app/api/events/route.ts (1)

187-195: 🚀 Performance & Scalability | 🔵 Trivial | ⚡ Quick win

날짜 키를 숫자로 유지해 불필요한 변환을 제거하세요.

ms는 이미 UTC 자정의 epoch 값입니다. 하지만 Line 192에서 ISO 문자열로 직렬화한 뒤 Line 200에서 다시 Date로 파싱합니다. 과거 날짜가 많으면 불필요한 문자열 할당과 Date 생성을 추가합니다. Set<number>ms를 저장하고 Date 배열을 직접 생성하세요.

제안된 수정
-            const pastDatesSet = new Set<string>()
+            const pastDatesSet = new Set<number>()
             for (const u of payload.usagePerTurn) {
               const d = new Date(u.timestamp)
               const ms = Date.UTC(d.getUTCFullYear(), d.getUTCMonth(), d.getUTCDate())
               if (ms < todayMs) {
-                pastDatesSet.add(new Date(ms).toISOString())
+                pastDatesSet.add(ms)
               }
             }
-            const pastDates = Array.from(pastDatesSet)
+            const pastDates = Array.from(
+              pastDatesSet,
+              (dateMs) => new Date(dateMs),
+            )

Line 200도 다음과 같이 변경해야 합니다.

-                  date: { in: pastDates.map((iso) => new Date(iso)) },
+                  date: { in: pastDates },
🤖 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 `@packages/web/src/app/api/events/route.ts` around lines 187 - 195, Update the
past-date collection in the usage-per-turn processing to use Set<number> and
store each UTC-midnight ms value directly instead of converting it to an ISO
string. Update the downstream pastDates construction to create Date objects
directly from those numeric keys, preserving the existing filtering and ordering
behavior.
🤖 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.

Inline comments:
In @.jules/bolt.md:
- Around line 2-4: Update the “Date Parsing and Chain Iteration Optimizations”
entry in .jules/bolt.md to accurately distinguish the costs: describe filter/map
chains as two O(N) passes plus O(N) intermediate allocation, and date parsing
inside sort comparators as approximately O(N log N) parses/allocations. Also
revise the matching O(N*M) description near the events API logic associated with
the visible Line 186 reference in packages/web/src/app/api/events/route.ts.

---

Nitpick comments:
In `@packages/web/src/app/api/events/route.ts`:
- Around line 187-195: Update the past-date collection in the usage-per-turn
processing to use Set<number> and store each UTC-midnight ms value directly
instead of converting it to an ISO string. Update the downstream pastDates
construction to create Date objects directly from those numeric keys, preserving
the existing filtering and ordering behavior.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 7faa4872-d033-4883-90ca-73ea1259c604

📥 Commits

Reviewing files that changed from the base of the PR and between a5be9b0 and a5e9df4.

📒 Files selected for processing (3)
  • .jules/bolt.md
  • packages/web/src/app/api/events/route.ts
  • packages/web/src/components/dashboard/session-timeline-chart.tsx

Comment thread .jules/bolt.md
Comment on lines +2 to +4
## 2025-02-12 - Date Parsing and Chain Iteration Optimizations
**Learning:** In both API routes and client chart components, chaining `.filter()` and `.map()` over large arrays or instantiating `Date` objects inside tight loops or `sort()` comparators results in severe `O(N*M)` or `O(N log N)` allocation bottlenecks and multiple intermediate garbage collections.
**Action:** When filtering/mapping large arrays, use a single `for...of` loop with a `Set` (or push to an array) instead of `.filter().map()` chains. When sorting by dates, implement a Schwartzian transform by pre-parsing the timestamps into primitives (e.g., `.getTime()`) once beforehand.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

복잡도 설명을 실제 연산에 맞게 수정하세요.

.filter().map() 체인은 일반적으로 두 번의 O(N) 순회와 O(N) 중간 배열 할당을 수행합니다. 이 연산은 O(N*M)이 아닙니다. sort() 비교 함수에서 날짜를 파싱하면 일반적인 비교 정렬에서 약 O(N log N)번의 파싱과 할당이 발생할 수 있습니다. 두 경우를 분리해 기록해야 이 지침이 잘못된 병목 분석을 유도하지 않습니다. 동일한 O(N*M) 표현을 사용하는 packages/web/src/app/api/events/route.tsLine 186도 함께 수정하세요.

제안된 수정
-**Learning:** In both API routes and client chart components, chaining `.filter()` and `.map()` over large arrays or instantiating `Date` objects inside tight loops or `sort()` comparators results in severe `O(N*M)` or `O(N log N)` allocation bottlenecks and multiple intermediate garbage collections.
+**Learning:** In both API routes and client chart components, chaining `.filter()` and `.map()` over large arrays performs two `O(N)` passes and allocates intermediate arrays. Instantiating `Date` objects inside `sort()` comparators can cause approximately `O(N log N)` parsing and allocation work, increasing garbage-collection pressure.
🤖 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 @.jules/bolt.md around lines 2 - 4, Update the “Date Parsing and Chain
Iteration Optimizations” entry in .jules/bolt.md to accurately distinguish the
costs: describe filter/map chains as two O(N) passes plus O(N) intermediate
allocation, and date parsing inside sort comparators as approximately O(N log N)
parses/allocations. Also revise the matching O(N*M) description near the events
API logic associated with the visible Line 186 reference in
packages/web/src/app/api/events/route.ts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant