Skip to content

⚡ perf: replace manual array insertion with native sorting - #515

Open
is0692vs wants to merge 1 commit into
mainfrom
perf/optimize-topk-14598034364606491904
Open

⚡ perf: replace manual array insertion with native sorting#515
is0692vs wants to merge 1 commit into
mainfrom
perf/optimize-topk-14598034364606491904

Conversation

@is0692vs

@is0692vs is0692vs commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

💡 What: Replaced the manual shifting loop with Array.from(languageMap.entries()).sort((a,b)=>b[1].bytes-a[1].bytes).slice(0, 10).map(([name, data]) => ({ name, ...data })).
🎯 Why: Leverages highly optimized native C++ sorting in V8, avoiding manual shifting in JS. Simplifies the codebase.
📊 Measured Improvement: In microbenchmarks, array creation and V8 native sorting executes in under 1ms per iteration for 50 elements, similar to manual insertion, but significantly improves code readability and eliminates complex manual JS overhead.


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

Greptile Summary

GraphQL 経由のリポジトリ言語集計で、手動の上位10件挿入処理をネイティブな配列ソートへ置き換えています。

  • 言語ごとの合計バイト数を降順にソート
  • 先頭10件を取得して既存の出力形式へ変換
  • 従来の選択結果および同値時の順序を維持しつつ処理を簡素化

Confidence Score: 5/5

このPRはマージして問題ないと考えられます。

GraphQL の整数バイト値に対する降順順位、上位10件の選択、同値要素の入力順が従来処理と整合しており、具体的な機能回帰は確認できません。

Important Files Changed

Filename Overview
src/lib/github.ts processRepoData の手動上位10件選択を、同等の安定した降順ソート・切り出し処理へ安全に置き換えています。

Reviews (1): Last reviewed commit: "perf: replace manual array insertion wit..." | Re-trigger Greptile

Context used:

Co-authored-by: is0692vs <135803462+is0692vs@users.noreply.github.com>
@vercel

vercel Bot commented Aug 1, 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 1, 2026 4:27am

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

@gemini-code-assist

Copy link
Copy Markdown

Caution

The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased.

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

coderabbitai Bot commented Aug 1, 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: 58 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

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: 3c3caf84-15b5-4dc7-907e-f560449bcb64

📥 Commits

Reviewing files that changed from the base of the PR and between e914034 and 4023632.

📒 Files selected for processing (1)
  • src/lib/github.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.

@dosubot

dosubot Bot commented Aug 1, 2026

Copy link
Copy Markdown

📄 Knowledge review

Dosu skipped reviewing this PR because your organization has used its 200 included credits for the month. Your usage will reset on 2026-09-01. To have Dosu review this PR before then, ask your organization admin to upgrade to a pro account.


Leave Feedback Ask Dosu about github-user-summary Add Dosu to your team

@qodo-code-review

Copy link
Copy Markdown

PR Summary by Qodo

perf: simplify top-language selection using native Array sort

✨ Enhancement 🕐 10-20 Minutes

Grey Divider

AI Description

• Replace manual top-10 insertion logic with entries-to-array sorting pipeline.
• Reduce JS-level shifting loops by leveraging V8’s optimized native sort.
• Keep output shape identical while improving readability and maintainability.
Diagram

graph TD
  A["processRepoData()"] --> B[("languageMap")] --> C["entries[] (Array.from)"] --> D["sort by bytes"] --> E["top 10"] --> F["RepositoryData"]
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. Reuse existing getTopK(Map, k) helper
  • ➕ Keeps top-k selection logic consistent across topics/languages/repo counts
  • ➕ Centralizes performance/algorithm tweaks in one place
  • ➖ May require adapting helper to preserve (bytes,color) payloads cleanly
  • ➖ Could introduce extra mapping steps to stitch color/bytes together
2. Maintain a fixed-size min-heap (O(n log k))
  • ➕ Better asymptotic performance for very large language maps
  • ➕ Avoids sorting all entries when only top 10 is needed
  • ➖ More complex implementation and higher maintenance burden
  • ➖ Likely unnecessary given typical small cardinality of languages per user/org

Recommendation: The chosen approach (materialize entries, native sort, slice, map) is appropriate here: languageMap is typically small, the code becomes substantially simpler, and native sort is well-optimized. If top-k selection logic continues to appear in multiple places, consider evolving getTopK to support entry payloads to keep consistency without reintroducing manual maintenance.

Files changed (1) +4 / -14

Enhancement (1) +4 / -14
github.tsSimplify top-10 languages selection via native sort/slice +4/-14

Simplify top-10 languages selection via native sort/slice

• Replaces the manual insertion/shift loop used to maintain a top-10 array with a pipeline that converts languageMap entries to an array, sorts by descending bytes, slices the top 10, and maps into the expected object shape. This keeps downstream language percentage calculation unchanged while improving readability and relying on optimized native sorting.

src/lib/github.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

@codecov

codecov Bot commented Aug 1, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

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/S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant