Skip to content

⚡ Bolt: optimize single-model inserts via direct streaming#151

Merged
cungminh2710 merged 1 commit into
mainfrom
bolt-optimize-single-model-insert-14140129265122056175
Jul 1, 2026
Merged

⚡ Bolt: optimize single-model inserts via direct streaming#151
cungminh2710 merged 1 commit into
mainfrom
bolt-optimize-single-model-insert-14140129265122056175

Conversation

@cungminh2710

Copy link
Copy Markdown
Contributor

This change optimizes the SQL compilation path for single-model inserts in the Rain ORM.

By introducing a specialized writeSingleModelSQL method that uses stack-allocated buffers for values and column metadata, we bypass the creation of intermediate []assignment slices. This significantly reduces heap pressure and improves performance for one of the most frequent database operations.

Benchmark results for single-model insert compilation:

  • Before: 3518 ns/op, 1144 B/op, 19 allocs/op
  • After: 2298 ns/op, 792 B/op, 13 allocs/op
  • Impact: ~35% speedup, ~31% fewer allocations.

The optimization is safely scoped to Model() calls without explicit .Set() overrides and includes a safe fallback for unusually large models.


PR created automatically by Jules for task 14140129265122056175 started by @cungminh2710

Implement writeSingleModelSQL in pkg/rain/query_insert.go to bypass
the overhead of intermediate assignment slices and map lookups for
single-row inserts based on a model.

This optimization uses stack-allocated buffers for values and column
metadata, achieving a ~35% speedup and ~31% reduction in heap
allocations for the most common model-based insert path.

Co-authored-by: cungminh2710 <8063319+cungminh2710@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.

@greptile-apps

greptile-apps Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR adds a faster SQL compilation path for single-model inserts. The main changes are:

  • Direct streaming for model-only single-row inserts.
  • Stack-backed buffers for common column and value lists.
  • A documented optimization note in .jules/bolt.md.

Confidence Score: 5/5

This looks safe to merge.

  • No blocking issues found in the changed code.
  • The fast path is limited to model-only inserts without explicit value overrides.
  • The new path uses the same model plan and insert-value filtering as the existing path.

Important Files Changed

Filename Overview
pkg/rain/query_insert.go Adds a guarded fast path for model-only inserts that mirrors the existing field selection and SQL writing behavior.
.jules/bolt.md Documents the single-model insert optimization.

Reviews (1): Last reviewed commit: "perf(rain): optimize single-model insert..." | Re-trigger Greptile

@cungminh2710
cungminh2710 merged commit 6f4194a into main Jul 1, 2026
5 checks passed
@cungminh2710
cungminh2710 deleted the bolt-optimize-single-model-insert-14140129265122056175 branch July 1, 2026 02:57
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