Skip to content

⚡ Optimize package metric lookup in getPackageTimestampWarnings#22

Merged
sunnylqm merged 1 commit intomainfrom
perf-optimize-package-metric-lookup-9392012208154317998
Apr 5, 2026
Merged

⚡ Optimize package metric lookup in getPackageTimestampWarnings#22
sunnylqm merged 1 commit intomainfrom
perf-optimize-package-metric-lookup-9392012208154317998

Conversation

@sunnylqm
Copy link
Copy Markdown
Collaborator

@sunnylqm sunnylqm commented Apr 4, 2026

The getPackageTimestampWarnings function previously used Array.find inside a loop over dictionary entries, resulting in O(N*M) complexity. By pre-calculating Maps for exact matches and package name lookups, we can now find the matching package much more efficiently.

Specifically:

  • exactMatchMap handles the case where the metric value exactly matches the current package metric.
  • nameMatchMap handles the case where the metric value starts with the package name followed by an underscore (indicating a different build time/warning).
  • We iterate backwards from the last underscore in the metric value to find the longest matching package name prefix, ensuring the same "longest prefix match" behavior as the original implementation (which sorted candidates by length descending).

Verification:

  • Added a temporary benchmark/test that confirmed the new implementation produces identical results to the original.
  • Benchmark results showed a reduction from ~2345ms to ~216ms for 50 iterations with 5000 entries and 100 packages.

PR created automatically by Jules for task 9392012208154317998 started by @sunnylqm

Summary by CodeRabbit

  • Refactor
    • Improved the algorithm for matching package metrics in timestamp warning detection, replacing linear search with a more efficient lookup mechanism.
    • Enhanced the matching behavior to better resolve metric values to their corresponding packages through iterative pattern matching.
    • Exported the package timestamp warning utility function to enable external use and integration.

Replaced O(N*M) Array.find inside a loop with O(1) Map lookups and
backward-iterating prefix search. This significantly improves performance
when processing large metric dictionaries with many package candidates.

Measured ~10x speedup with 100 packages and 5000 dictionary entries.

Co-authored-by: sunnylqm <615282+sunnylqm@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.

@netlify
Copy link
Copy Markdown

netlify Bot commented Apr 4, 2026

Deploy Preview for pushy ready!

Name Link
🔨 Latest commit 77af487
🔍 Latest deploy log https://app.netlify.com/projects/pushy/deploys/69d1413765422b00086bb431
😎 Deploy Preview https://deploy-preview-22--pushy.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 4, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: eb6776eb-e112-40d9-a748-550dc3f8b0bd

📥 Commits

Reviewing files that changed from the base of the PR and between 06aa0c8 and 77af487.

📒 Files selected for processing (1)
  • src/utils/hooks.ts

📝 Walkthrough

Walkthrough

The getPackageTimestampWarnings function is now exported and its package matching logic was refactored from per-entry linear searches to precomputed lookup maps with iterative suffix-stripping fallback for improved lookup performance.

Changes

Cohort / File(s) Summary
Performance optimization for package matching
src/utils/hooks.ts
Exported getPackageTimestampWarnings; replaced per-entry linear search with precomputed exactMatchMap and nameMatchMap keyed by full metric value and package name respectively; updated matching behavior to attempt exact lookup first, then iteratively strip suffixes (split by _) to find prefix matches against name map.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 Hopping through the code with speed,
Maps built swift to fill the need,
No more searching line by line,
Lookups dash and match align!
Exported now for all to see,
Efficiency hops with glee!

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically describes the main optimization: replacing O(N*M) linear search with precomputed lookup maps for package metric matching in getPackageTimestampWarnings.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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

✨ 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 perf-optimize-package-metric-lookup-9392012208154317998

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.

@sunnylqm sunnylqm merged commit 3b5ec80 into main Apr 5, 2026
5 checks passed
@sunnylqm sunnylqm deleted the perf-optimize-package-metric-lookup-9392012208154317998 branch April 5, 2026 01:44
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