Skip to content

⚡ Optimize regex creation in gemini service#7

Open
ayush1920 wants to merge 1 commit intomainfrom
optimize-gemini-regex-10392586217534968436
Open

⚡ Optimize regex creation in gemini service#7
ayush1920 wants to merge 1 commit intomainfrom
optimize-gemini-regex-10392586217534968436

Conversation

@ayush1920
Copy link
Owner

💡 What:
Moved the discountRegex and roundOffKeywords definitions from inside the sanitizeParsedData function to the module scope (top-level constants).

🎯 Why:
Previously, these were being re-created every time sanitizeParsedData was called (which happens for every receipt processed). While V8 optimizes regex literals well, defining them as module-level constants DISCOUNT_REGEX and ROUND_OFF_KEYWORDS guarantees they are initialized only once, avoiding any potential reallocation overhead and adhering to best performance practices.

📊 Measured Improvement:
Benchmark runs (500,000 iterations) showed a slight fluctuation in execution time (approx 1636ms vs 1565ms), indicating the improvement is within the noise margin (likely < 5%). This suggests the JS engine was already optimizing the literal efficiently, but the change makes the optimization explicit and robust. Correctness was verified with existing logic tests.


PR created automatically by Jules for task 10392586217534968436 started by @ayush1920

Moved `discountRegex` and `roundOffKeywords` to module scope to avoid re-creation on every `sanitizeParsedData` call. This is a safe optimization to reduce overhead.
Benchmark showed negligible improvement (~4%), likely due to V8 regex literal optimizations, but this change ensures optimal behavior and cleaner code.

Co-authored-by: ayush1920 <45363959+ayush1920@users.noreply.github.com>
@google-labs-jules
Copy link
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

vercel bot commented Jan 29, 2026

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

Project Deployment Review Updated (UTC)
eazy-split Ready Ready Preview, Comment Jan 29, 2026 3:59am
eazy-split-server Ready Ready Preview, Comment Jan 29, 2026 3:59am

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