Skip to content

⚡ Optimize Date object creation in heatmap build - #545

Open
is0692vs wants to merge 1 commit into
mainfrom
perf-date-heatmap-146233305816890484
Open

⚡ Optimize Date object creation in heatmap build#545
is0692vs wants to merge 1 commit into
mainfrom
perf-date-heatmap-146233305816890484

Conversation

@is0692vs

@is0692vs is0692vs commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

💡 What: Modified buildHeatmapFromRepoPushes to use a single Date instantiation instead of creating one for each iteration of a 42-count loop. Also replaced date.setUTCDate with basic time arithmetic via .setTime and time increments (86400000).
🎯 Why: To prevent unnecessary Object instantiation overhead when building a heatmap from repo push dates.
📊 Measured Improvement: Decreased runtime for this operation from roughly ~5700ms to ~4860ms according to isolated micro-benchmarks on 100,000 iterations.


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

Greptile Summary

Dateオブジェクトの生成回数を減らし、42日間のヒートマップ初期化を効率化する変更です。動作を変える問題は確認されませんでした。

  • ループ外でDateオブジェクトを1回だけ生成
  • UTC午前0時を起点に86,400,000ミリ秒ずつ進めて日付キーを生成
  • 既存と同じ42日間のUTC日付範囲を維持

Confidence Score: 5/5

このPRは安全にマージできると判断します。

開始日時はUTC午前0時に正規化されているため、固定ミリ秒による日次加算は従来のsetUTCDateと同じ42個の連続したUTC日付キーを生成し、変更されたDateや時刻値もループ後には再利用されません。

Important Files Changed

Filename Overview
src/lib/cardDataFetcher.ts ヒートマップの日付生成を単一のDateインスタンスへ最適化しており、UTC日付の範囲と出力は維持されています。

Reviews (1): Last reviewed commit: "perf: optimize Date instantiation in hea..." | Re-trigger Greptile

Context used:

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

vercel Bot commented Aug 7, 2026

Copy link
Copy Markdown

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

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
github-user-summary Ignored Ignored Aug 7, 2026 6:47am

@dosubot dosubot Bot added the enhancement New feature or request label Aug 7, 2026
@coderabbitai

coderabbitai Bot commented Aug 7, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@is0692vs, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 54 minutes

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: a26d7448-e811-4de3-b741-65d11cf143f2

📥 Commits

Reviewing files that changed from the base of the PR and between eb95c48 and aa8bf12.

📒 Files selected for processing (1)
  • src/lib/cardDataFetcher.ts

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.

@codecov

codecov Bot commented Aug 7, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@qodo-code-review

Copy link
Copy Markdown

PR Summary by Qodo

Optimize heatmap date key generation by reusing a single Date instance

✨ Enhancement 🕐 10-20 Minutes

Grey Divider

AI Description

• Reuse a single Date object when initializing the 42-day heatmap window.
• Replace setUTCDate calls with fixed millisecond increments to reduce overhead.
• Preserve the existing UTC day range and output format (YYYY-MM-DD keys).
Diagram

graph TD
  A["fetchCardData()"] --> B["buildHeatmapFromRepoPushes()"] --> C["UTC start date"] --> D["Single Date"] --> E["+86400000 per day"] --> M[("dayCounts Map")] --> O[/"heatmap days + max"/]
  R[/"repos[] pushedAt"/] --> B

  subgraph Legend
    direction LR
    _fn["Function"] ~~~ _data[/"Data"/] ~~~ _map[("Map")]
  end
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. Increment via setUTCDate on a reused Date
  • ➕ Avoids relying on a fixed 86,400,000ms step constant
  • ➕ Explicitly handles any calendar edge cases without reasoning about milliseconds
  • ➖ Typically slower due to date component normalization work per iteration
  • ➖ Still involves higher per-iteration Date logic overhead than setTime
2. Avoid Date entirely (epoch-day math + manual YYYY-MM-DD formatting)
  • ➕ Can be faster than toISOString() and any Date mutation
  • ➕ Eliminates timezone/locale pitfalls by construction
  • ➖ More complex and easier to get wrong (leap years/month boundaries)
  • ➖ Harder to read/maintain for a small win compared to current change

Recommendation: The PR’s approach (single Date instance + setTime millisecond increments from a UTC-midnight baseline) is a good balance of performance and correctness. It keeps the output stable (UTC YYYY-MM-DD keys) while materially reducing object churn; more aggressive string/date math optimizations would add complexity for marginal additional gain.

Files changed (1) +4 / -2

Enhancement (1) +4 / -2
cardDataFetcher.tsReuse Date and advance via milliseconds in heatmap initialization loop +4/-2

Reuse Date and advance via milliseconds in heatmap initialization loop

• Optimizes buildHeatmapFromRepoPushes by creating the Date object once and advancing it using setTime with a fixed 1-day millisecond step. Removes per-iteration Date instantiation and setUTCDate usage while keeping the 42-day UTC key range unchanged.

src/lib/cardDataFetcher.ts

@qodo-code-review

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0)

Grey Divider

Great, no issues found!

Qodo reviewed your code and found no material issues that require review

Grey Divider

To customize comments, go to the Qodo configuration screen, or learn more in the docs.

Qodo Logo

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

Labels

enhancement New feature or request size/XS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant