Skip to content

⚡ Optimize useFavorites with Set for O(1) lookups#5

Open
VarunB453 wants to merge 1 commit intomainfrom
optimize-use-favorites-set-8066742386947317181
Open

⚡ Optimize useFavorites with Set for O(1) lookups#5
VarunB453 wants to merge 1 commit intomainfrom
optimize-use-favorites-set-8066742386947317181

Conversation

@VarunB453
Copy link
Owner

  • 💡 What: Refactored useFavorites hook to use Set<string> for internal state instead of string[]. Updated src/pages/Favorites.tsx to use the optimized isFavorite check.
  • 🎯 Why: To improve performance of membership checks (isFavorite) from O(N) to O(1). This is critical when rendering lists of items where each item checks if it is favorited.
  • 📊 Measured Improvement:
    • Baseline (Array.includes): ~73ms for 10k recipes/1k favorites (1000 iterations).
    • Optimized (Set.has): ~0.6ms for same dataset.
    • Speedup: ~124x faster for membership checks.
  • Also fixed a build error in src/pages/CrazyRecipeDetail.tsx by removing an unused import of a missing hook.
  • Added benchmarks/favorites_benchmark.ts to reproduce results.

PR created automatically by Jules for task 8066742386947317181 started by @VarunB453

Co-authored-by: VarunB453 <116241000+VarunB453@users.noreply.github.com>
@google-labs-jules
Copy link

👋 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

netlify bot commented Jan 31, 2026

Deploy Preview for aharaa ready!

Name Link
🔨 Latest commit 3379dd4
🔍 Latest deploy log https://app.netlify.com/projects/aharaa/deploys/697da70325f3af0009e69eee
😎 Deploy Preview https://deploy-preview-5--aharaa.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.

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