Skip to content

⚡ Bolt: [performance improvement] optimize sequential db queries#61

Open
bobdivx wants to merge 1 commit into
devfrom
bolt-perf-agent-budget-concurrent-queries-467754568389280079
Open

⚡ Bolt: [performance improvement] optimize sequential db queries#61
bobdivx wants to merge 1 commit into
devfrom
bolt-perf-agent-budget-concurrent-queries-467754568389280079

Conversation

@bobdivx
Copy link
Copy Markdown
Owner

@bobdivx bobdivx commented May 24, 2026

💡 What: Replaced three independent sequential db.select() operations in src/pages/api/agent-budget.ts with a single concurrent Promise.all().

🎯 Why: To avoid unnecessary I/O bottleneck waiting time when querying database tables that do not depend on each other.

📊 Impact: Reduces the total query execution time to the duration of the longest query, rather than the sum of all three queries.

🔬 Measurement: Verifiable via API request timing to /api/agent-budget or reviewing database query logs. Added a journal entry in .jules/bolt.md.


PR created automatically by Jules for task 467754568389280079 started by @bobdivx

- Grouped sequential `db.select()` queries in `src/pages/api/agent-budget.ts` inside a single `Promise.all()`.
- Created `.jules/bolt.md` to journal the codebase-specific learning about optimizing independent query lookups via concurrency.

Co-authored-by: bobdivx <6737167+bobdivx@users.noreply.github.com>
@google-labs-jules
Copy link
Copy Markdown

👋 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 May 24, 2026

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

Project Deployment Actions Updated (UTC)
forge Ready Ready Preview, Comment May 24, 2026 5:37pm

Copy link
Copy Markdown

@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 optimizes the agent-budget API endpoint by executing database queries concurrently using Promise.all and adds a performance optimization note to the documentation. Feedback suggests further improving efficiency by selecting only required columns to avoid fetching large unused fields, considering SQL aggregations for better scalability, and removing tool-specific branding from code comments.

Comment on lines +20 to +25
// ⚡ Bolt: Concurrent query execution to avoid sequential I/O bottlenecks
const [budgets, allEvents, instructions] = await Promise.all([
db.select().from(AgentBudget),
db.select().from(CostEvent),
db.select().from(AgentInstruction),
]);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

While using Promise.all is a correct optimization for concurrency, the queries themselves still fetch all columns from the database.

  1. Efficiency: AgentInstruction contains a systemPrompt field which can be very large and is not used in this endpoint. Similarly, CostEvent fetches several unused columns. Selecting only the required columns will significantly reduce memory usage and network overhead.
  2. Scalability: Fetching all rows from CostEvent will eventually lead to performance issues as the table grows. For future improvement, consider using SQL aggregations (SUM, COUNT) and filtering by date (occurredAt) directly in the query instead of processing everything in JavaScript.
  3. Style: Consider removing the tool-specific branding (⚡ Bolt:) from the comment to maintain a standard, clean codebase.
Suggested change
// ⚡ Bolt: Concurrent query execution to avoid sequential I/O bottlenecks
const [budgets, allEvents, instructions] = await Promise.all([
db.select().from(AgentBudget),
db.select().from(CostEvent),
db.select().from(AgentInstruction),
]);
// Fetch data concurrently to reduce total I/O wait time
const [budgets, allEvents, instructions] = await Promise.all([
db.select().from(AgentBudget),
db.select({
agentId: CostEvent.agentId,
costCents: CostEvent.costCents,
inputTokens: CostEvent.inputTokens,
outputTokens: CostEvent.outputTokens,
occurredAt: CostEvent.occurredAt,
}).from(CostEvent),
db.select({
agentId: AgentInstruction.agentId,
model: AgentInstruction.model,
}).from(AgentInstruction),
]);

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