Performance
The measured allocation and time numbers behind fusion-orm's SQL-first engine, a reproducible benchmark setup, and tuning knobs that actually matter.
fusion-orm's engine is built for cheap per-statement work: byte-slice SQL builders, precompiled per-field closures, copy-on-write chains, and an allocation-reduction pass in every release since 0.3.0. The numbers below come from the project's own benchmark runs — they are indicative, and hardware-dependent, but the setup is reproducible.
The v0.4.0 headline numbers
Measured (benchcmp, in-memory SQLite, interleaved n=10): allocation
geomean 97/op vs bun 126 (+29%) and gorm 249 (+155%). Per-op vs v0.3.1:
Update 46→28, Delete 30→19, Count 31→24, Pluck 57→45, Create 46→37,
First 57→49, Preload 294→273, Batch100 814→809. Time geomean leads bun
by ~8% and gorm by ~47% on this run.| Metric (allocation geomean, benchcmp run) | fusion-orm | bun | gorm |
|---|---|---|---|
| Allocations/op | 97 | 126 (+29% vs fusion) | 249 (+155% vs fusion) |
| Time/op on this run | fastest | ~8% slower | ~47% slower |
Allocation reductions, release by release
Per-operation allocations/op, fusion-orm only, measured with the same interleaved setup:
| Operation | v0.3.1 | v0.4.0 | Change |
|---|---|---|---|
| Update | 46 | 28 | −39% |
| Delete | 30 | 19 | −37% |
| Count | 31 | 24 | −23% |
| Pluck | 57 | 45 | −21% |
| Create | 46 | 37 | −20% |
| First | 57 | 49 | −14% |
| Preload | 294 | 273 | −7% |
| Batch100 | 814 | 809 | −1% |
The v0.4.0 wins come from embedding Statement by value (one allocation
per chain hop instead of two), a slot-array clause registry that keeps
AddClause/clone allocation-free for standard clauses, and a pre-checked
WouldTrace gate so disabled loggers allocate nothing per statement
(CHANGELOG.md:36-49).
The v0.3.1 pass rebuilt the per-row hot paths:
| Operation | before v0.3.1 | after v0.3.1 |
|---|---|---|
| Pluck (allocs/op) | 2067 | 57 |
| FindAll (allocs/op) | 9798 | 4797 |
| Create (allocs/op) | 86 | 46 |
Overall: "fusion geomean now leads bun by ~8% and gorm by ~28% across 11
operations; allocs/op down 30–97% per operation" (CHANGELOG.md:79-81).
Read the numbers honestly
These are in-memory SQLite runs with interleaved A/B/C iterations — they measure the ORM's overhead, not your database. Real workloads dominated by network round-trips or I/O will see much smaller relative differences. Treat every number above as indicative.
Reproduce it
The benchmarks ship with the library. From the repository root:
make benchor directly:
go test -run '^$' -bench . -benchmem ./...Both run the full benchmark suite with allocation counts. To compare
against a baseline, save one run's output and feed both to benchcmp —
that is exactly how the release numbers above were produced. The CI pipeline
runs the same alloc benchmarks with a PostgreSQL service, so cross-dialect
regressions are caught too (README.md:178).
Tuning guidance
Prepare statements for hot paths
// PrepareStmt enables the LRU+TTL prepared-statement cache.PrepareStmt: true wraps the connection pool with an LRU+TTL cache
(prepared_stmt.go:153) that survives ErrBadConn recovery and is
transaction-aware. Size it explicitly:
db, err := fusion.Open(sqlite.Open("app.db"), &fusion.Config{
TranslateError: true,
PrepareStmt: true,
PreparedStmtCacheSize: 500,
})Statements are refcounted so concurrent eviction cannot close one out from
under a caller (CHANGELOG.md:123-126).
Skip the implicit transaction when it is not needed
// SkipDefaultTransaction disables the implicit transaction wrapping
// single create/update/delete operations (honored by M3 callbacks).Two honest notes:
- Since v0.3.1, a single-row
Createis already not wrapped in a synthetic BEGIN/COMMIT when the write is provably one statement — no relations, no hooks, no multi-chunk batch — halving the common-case write path automatically (CHANGELOG.md:63-65,callbacks_default.go:70-76). SkipDefaultTransactionstill removes the implicit transaction for the remaining cases: writes that carry relations, hooks that may issue statements, or multi-chunk batches. If your transaction wrapper handles atomicity at a higher level, set it and pay one flag instead of a round-trip pair.
Batch large inserts
// CreateBatchSize sets the maximum rows per INSERT statement.Without a batch size, Create on a slice builds one INSERT for all rows;
with CreateBatchSize(n) it chunks into statements of at most n rows,
which bounds parameter counts and packet sizes. The implicit-transaction
bail-out above respects the chunking (callbacks_default.go:82-87).
Select only the columns you scan
// Select restricts the selected columns. A single comma-separated string is
// split into columns.SELECT * scans every column back into your struct. An explicit
Select("id", "name") cuts the wire payload and the scan work in
proportion — the scan loop assigns through precompiled per-field closures
(schema/scanner.go:8-9), so the cost is roughly proportional to columns
touched, not table width.
No per-row reflection
The schema layer resolves each field's appender and scanner once at table-init time:
// AppenderFunc renders a field value as a SQL literal using the active
// dialect. It is resolved once at table-init time; no per-row reflection.// ScannerFunc assigns a database value to a field. Resolved at table-init
// time, so scanning rows performs no type dispatch through reflection.Wide row reads and writes cost typed closures, not reflect dispatch.
This is also why the scan-loop and timestamp backfill optimizations landed
in v0.3.1 (CHANGELOG.md:67-73).
Logging costs nothing when disabled
The default logger is Warn-level with a 200ms slow threshold, and the
query path asks WouldTrace before allocating the trace closure
(logger/logger.go:62-66, exec.go:46-51):
// Tracer is an optional interface a logger implements so callers can skip
// building the Trace closure entirely when no line would be emitted. The
// hot query path allocates the closure per statement; gated loggers avoid
// it. Trace remains the authority: it decides output through WouldTrace.Turn logging up for debugging without paying for it in the hot loop afterwards.
Where next
Security
How fusion-orm keeps attacker-controlled data out of your SQL — parameterized values, quoted identifiers, hardened literal appenders, guardrails, and logging hygiene.
Comparison
An honest, row-by-row comparison of fusion-orm against gorm and bun — capabilities, ergonomics, and measured overhead.