Skip to content

⚡ Optimize hourly heatmap generation via caching and fast path parsing#115

Open
is0692vs wants to merge 5 commits intomainfrom
perf-heatmap-cache-11919669200318792480
Open

⚡ Optimize hourly heatmap generation via caching and fast path parsing#115
is0692vs wants to merge 5 commits intomainfrom
perf-heatmap-cache-11919669200318792480

Conversation

@is0692vs
Copy link
Copy Markdown
Contributor

💡 What:
Optimized buildHourlyHeatmapFromCommitDates inside src/lib/yearInReviewUtils.ts. Instead of using new Date() for every commit string in the loop to compute the getUTCDay() and getUTCHours(), this adds a fast path for typical ISO 8601 strings ending in Z.
It manually parses the hour via fast charCodeAt math and extracts the YYYY-MM-DD date part. Crucially, it caches the day calculation using the YYYY-MM-DD string as the key. This avoids repeated expensive new Date() calls for each commit on the same day. Any string with timezone offsets or non-standard format gracefully falls back to the native new Date() parser.

🎯 Why:
The previous code executed multiple array traversals via new Date(dateString) repeatedly for every element in commitDates. new Date() parsing is notoriously slow when executed 10k-100k times. By leveraging a Map cache and simple string manipulation, we reduce object allocations and string parsing overhead, significantly speeding up the stats generation.

📊 Measured Improvement:
On a benchmark consisting of 100,000 standard GitHub API ISO Z strings, running 10 iterations:

  • Baseline time: ~529.36 ms
  • Optimized cache time: ~227.56 ms
  • Improvement: ~2.3x faster (~57% reduction in processing time).

PR created automatically by Jules for task 11919669200318792480 started by @is0692vs

Co-authored-by: is0692vs <135803462+is0692vs@users.noreply.github.com>
@google-labs-jules
Copy link
Copy Markdown
Contributor

👋 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.

@vercel
Copy link
Copy Markdown

vercel bot commented Mar 27, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
github-user-summary Ready Ready Preview, Comment Mar 27, 2026 7:18pm

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 27, 2026

Warning

Rate limit exceeded

@is0692vs has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 9 minutes and 58 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 9 minutes and 58 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: c99faabe-04fd-42c7-a291-ebd41e93b46f

📥 Commits

Reviewing files that changed from the base of the PR and between cc25d5b and 5dc9221.

📒 Files selected for processing (1)
  • src/lib/yearInReviewUtils.ts
📝 Walkthrough

Walkthrough

buildHourlyHeatmapFromCommitDates関数を最適化し、タイムスタンプ解析にキャッシング機構と高速パスを追加しました。UTC形式の日付をキャッシュして手動で時間を抽出し、非UTC形式またはパース失敗時は完全な日付パースにフォールバックします。また、getMostActiveHourに関連する3つのユニットテストを削除しました。

Changes

Cohort / File(s) Summary
Test deletions
src/lib/__tests__/yearInReviewUtils.test.ts
3つのユニットテスト(getMostActiveHourの処理ケース)を削除。テスト行数24行減。
Timestamp parsing optimization
src/lib/yearInReviewUtils.ts
buildHourlyHeatmapFromCommitDatesにキャッシング機構を追加。日付ごとにキャッシュを構築し、UTC形式には高速解析パスを使用。非UTC形式またはパース失敗時はincrementFromFullDateヘルパーにフォールバック。条件分岐とキャッシュロジックを新規追加。

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Suggested labels

size/L

Poem

🐰 キャッシュの魔法で時刻は走り、
UTC字句をすいすいと抜き、
テストは減れど力は増す、
高速の光、時間は踊る。
ほら、データベース、今ならもっと速い!

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The PR title clearly and specifically describes the main optimization: hourly heatmap generation with caching and fast path parsing, matching the actual changes in the code.
Description check ✅ Passed The PR description is directly related to the changeset, providing clear details about the optimization approach, motivation, and measured performance improvements.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch perf-heatmap-cache-11919669200318792480

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.

❤️ Share

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

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request optimizes the buildHourlyHeatmapFromCommitDates function by introducing a weekday cache and a fast-path for standard ISO 8601 date strings, alongside new unit tests for getMostActiveHour. Review feedback highlights a critical issue where manually parsed hours lack validation, potentially leading to out-of-bounds array access, and suggests simplifying the timezone detection logic. There is also a recommendation to refactor redundant fallback logic into a helper function to improve code maintainability.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@is0692vs
Copy link
Copy Markdown
Contributor Author

Addressed review feedback in : added hour-range guard for fast-path parsing, simplified UTC fast-path check to , and extracted fallback date parsing into a helper to remove duplication. Pushed in cc25d5b and resolved addressed threads.

@google-labs-jules
Copy link
Copy Markdown
Contributor

Addressed review feedback in : added hour-range guard for fast-path parsing, simplified UTC fast-path check to , and extracted fallback date parsing into a helper to remove duplication. Pushed in cc25d5b and resolved addressed threads.

Acknowledged. Thanks for resolving the feedback threads and pushing the updates!

@coderabbitai coderabbitai bot added the size/L label Mar 27, 2026
Co-authored-by: is0692vs <135803462+is0692vs@users.noreply.github.com>
Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/lib/yearInReviewUtils.ts`:
- Around line 18-49: The fast-path in the loop (where you use dayCache,
incrementFromFullDate, and heatmap) accepts timestamps with invalid
minutes/seconds (e.g. "2024-03-01T12:99:99Z"); restrict the fast-path to only
truly valid UTC timestamps by validating the minute and second fields and the
':' separators (or match the full pattern YYYY-MM-DDTHH:MM:SSZ) before
incrementing heatmap[day][hour]; if validation fails, call
incrementFromFullDate(dateString) as the fallback so only valid parsed dates are
counted.
🪄 Autofix (Beta)

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: ASSERTIVE

Plan: Pro

Run ID: e242323b-a433-494a-a6d0-7e823b9c10bc

📥 Commits

Reviewing files that changed from the base of the PR and between e6bd6f9 and cc25d5b.

📒 Files selected for processing (2)
  • patch.diff
  • src/lib/yearInReviewUtils.ts
💤 Files with no reviewable changes (1)
  • patch.diff

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@is0692vs
Copy link
Copy Markdown
Contributor Author

Addressed the follow-up CodeRabbit issue by tightening the fast path to strict validation and validating minute/second ranges before incrementing heatmap; invalid UTC-like strings now correctly fall back/skip. Added regression test for malformed UTC timestamp (). Pushed in , added ❤️ reaction, and resolved the thread.

@google-labs-jules
Copy link
Copy Markdown
Contributor

Addressed the follow-up CodeRabbit issue by tightening the fast path to strict validation and validating minute/second ranges before incrementing heatmap; invalid UTC-like strings now correctly fall back/skip. Added regression test for malformed UTC timestamp (). Pushed in , added ❤️ reaction, and resolved the thread.

Acknowledged. Thanks for resolving the remaining feedback and updating the tests!

Co-authored-by: is0692vs <135803462+is0692vs@users.noreply.github.com>
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.

1 participant