Skip to content

⚡ Bolt: Optimized concurrency and DOM efficiency#39

Open
LVT-ENG wants to merge 1 commit intomainfrom
bolt-perf-optimization-concurrency-dom-1679399217605503802
Open

⚡ Bolt: Optimized concurrency and DOM efficiency#39
LVT-ENG wants to merge 1 commit intomainfrom
bolt-perf-optimization-concurrency-dom-1679399217605503802

Conversation

@LVT-ENG
Copy link
Copy Markdown
Member

@LVT-ENG LVT-ENG commented Mar 27, 2026

This PR implements several performance optimizations across the backend and frontend to improve responsiveness and concurrency.

Key Changes:

  • FastAPI Event Loop Optimization: The /api/recommend endpoint now uses a synchronous def. Since it contains blocking LLM logic, this change allows FastAPI to handle requests in a separate thread pool, enabling parallel request processing (verified with a benchmark script).
  • HMAC Pre-encoding: The LVT_SECRET_KEY is now pre-encoded to bytes at the module level, saving redundant .encode() calls during every authentication handshake.
  • Frontend DOM Caching: Frequently accessed elements like the result container and text areas are now cached in the TryOnYouBunker constructor, reducing DOM lookup overhead during user interactions.
  • Resource Management: The IntersectionObserver used for luxury transitions now calls unobserve() on elements once they have become visible, freeing up browser resources.

Measurements:

  • Concurrency: Handling 2 concurrent requests now takes ~3s total (parallel) instead of ~6s (sequential).
  • Backend Tests: Passed (backend/tests/test_main.py).
  • Frontend Tests: Passed (pnpm vitest run).

PR created automatically by Jules for task 1679399217605503802 started by @LVT-ENG

- Changed /api/recommend to a sync 'def' to prevent blocking the FastAPI event loop during LLM calls.
- Pre-encoded HMAC secret key to bytes to reduce redundant CPU operations.
- Implemented DOM element caching in the TryOnYouBunker class to minimize lookups.
- Optimized IntersectionObserver by unobserving elements after initial transition.

Co-authored-by: LVT-ENG <214667862+LVT-ENG@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
Copy link
Copy Markdown

vercel bot commented Mar 27, 2026

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

Project Deployment Actions Updated (UTC)
_deploy_build Ready Ready Preview, Comment Mar 27, 2026 6:12am
tryonyou-org Ready Ready Preview, Comment Mar 27, 2026 6:12am

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces several performance optimizations across the backend and frontend. Key changes include pre-encoding the secret key in the Python backend to reduce redundant operations and converting an asynchronous endpoint to synchronous. On the frontend, DOM element caching is implemented to minimize lookups, and the Intersection Observer is updated to unobserve elements after their initial transition. Review feedback recommends centralizing the caching of the submit button within the class constructor to improve consistency and suggests using destructuring to simplify the retrieval of these cached elements in the event handler.

Comment on lines +39 to +43
this.dom = {
resultContainer: document.getElementById('jules-result'),
resultText: document.getElementById('recommendation-text'),
submitBtn: null // Assigned in handleDivineoExecution for contextual accuracy if needed
};
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

For consistency and to make dependencies explicit, it would be better to also cache the submit button here. The current implementation caches it on first use in handleDivineoExecution, which can be fragile if the handler is ever reused for a different form. Since the form has a stable ID (#jules-form), you can reliably select the button in the constructor.

Suggested change
this.dom = {
resultContainer: document.getElementById('jules-result'),
resultText: document.getElementById('recommendation-text'),
submitBtn: null // Assigned in handleDivineoExecution for contextual accuracy if needed
};
this.dom = {
resultContainer: document.getElementById('jules-result'),
resultText: document.getElementById('recommendation-text'),
submitBtn: document.querySelector('#jules-form button[type="submit"]')
};

Comment on lines +121 to +126
const resultContainer = this.dom.resultContainer;
const resultText = this.dom.resultText;
if (!this.dom.submitBtn) {
this.dom.submitBtn = event.target.querySelector('button[type="submit"]');
}
const submitBtn = this.dom.submitBtn;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Following the suggestion to cache the submit button in the constructor, this block can be simplified significantly by destructuring all needed DOM elements from this.dom.

Suggested change
const resultContainer = this.dom.resultContainer;
const resultText = this.dom.resultText;
if (!this.dom.submitBtn) {
this.dom.submitBtn = event.target.querySelector('button[type="submit"]');
}
const submitBtn = this.dom.submitBtn;
const { resultContainer, resultText, submitBtn } = this.dom;

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