⚡ Bolt: Optimize single-model insert compilation performance#149
⚡ Bolt: Optimize single-model insert compilation performance#149cungminh2710 wants to merge 2 commits into
Conversation
- Implement writeSingleModelSQL to stream SQL directly from models, bypassing intermediate assignment slice allocations. - Add fast-paths for common primitive types in fieldValueForInsert and insertValueForField to avoid redundant reflection and boxing. - Add BenchmarkInsertToSQL/SingleModel to track compilation performance. BenchmarkInsertToSQL/SingleModel (Postgres dialect): - Allocations: 16 -> 5 allocs/op (~69% reduction) - Speed: 3415 -> 1503 ns/op (~56% faster) Co-authored-by: cungminh2710 <8063319+cungminh2710@users.noreply.github.com>
|
👋 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 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 SummaryThis PR optimizes single-model insert SQL compilation in Rain ORM. The main changes are:
Confidence Score: 5/5This looks safe to merge.
|
| Filename | Overview |
|---|---|
| pkg/rain/query_insert.go | Adds the direct single-model insert SQL path for model-only inserts. |
| pkg/rain/query_model_assignments.go | Adds guarded primitive fast paths for insert value resolution and auto-increment zero checks. |
| pkg/rain/compile_bench_test.go | Adds benchmark coverage for the single-model insert compilation path. |
Reviews (2): Last reviewed commit: "refactor(rain): optimize single-model in..." | Re-trigger Greptile
|
@jules Fix the following 2 code review issues. Work through them one at a time, proposing concise fixes. Issue 1 of 2pkg/rain/query_model_assignments.go:167-176 When a model field uses a named primitive type such as a string or int wrapper with custom insert serialization, this branch returns the raw primitive before the existing interface-based value path can run. That changes Issue 2 of 2pkg/rain/query_model_assignments.go:108-127 For an auto-increment column backed by a named primitive field, a zero Go value is dropped here before the custom value path is consulted. A field that intentionally supplies its ID through custom serialization can now be omitted from the |
I've addressed both issues by restricting the primitive fast-paths to built-in types (where |
…er bypass - Implement writeSingleModelSQL for direct streaming of single-model inserts. - Add fast-paths for built-in primitive types in assignment resolution. - Ensure custom providers (named primitive wrappers) are still consulted by restricting fast-paths to types with PkgPath() == "". - Add BenchmarkInsertToSQL/SingleModel to track compilation performance. BenchmarkInsertToSQL/SingleModel: - Allocations: 16 -> 5 allocs/op (~69% reduction) - Speed: 3415 -> 1536 ns/op (~55% faster) Co-authored-by: cungminh2710 <8063319+cungminh2710@users.noreply.github.com>
This PR optimizes the SQL compilation path for single-model
INSERTstatements in Rain ORM.By identifying that most inserts use a single model without additional
.Set()overrides, we now bypass the expensive creation of intermediateassignmentslices and map lookups. Instead,writeSingleModelSQLstreams values directly from the model fields to the compilation context.Additionally, we've optimized the assignment resolution logic with fast-paths for common primitive types (
int64,int,string,bool), avoiding the overhead ofreflect.Value.Interface()and associated boxing where possible.Verification:
BenchmarkInsertToSQL/SingleModelshows a ~69% reduction in allocations and ~56% improvement in compilation speed.go test ./pkg/rain/....PR created automatically by Jules for task 15259031699631847227 started by @cungminh2710