Skip to content

perf(orm): cache the immutable model validation result - #104

Merged
Antruly merged 1 commit into
masterfrom
perf/orm-cache
Nov 27, 2026
Merged

Antruly merged 1 commit into
masterfrom
perf/orm-cache

Conversation

@Antruly

@Antruly Antruly commented Nov 27, 2026

Copy link
Copy Markdown
Owner

Part of #95. Follow-up to #103.

What changed

src/orm/uvcpp_orm_model.h only: validate_model<T>() now caches the validation result (status + message) on first use. Model metadata is static, so the per-call column walk was pure repeated work. Callers still receive a copy of the error string; no shared mutable state.

Why

The ORM A/B benchmark showed point-select p50 overhead still slightly above the 15% target after #103. Validation was one of the remaining fixed per-call costs. Single-round after this change:

pk p50 extra          6.5%
find_all100 p50 extra 11.0%
update p50 extra      0.6%
insert p50 extra     -0.3%
remove p50 extra      0.0%

The 3-round fixed-runner report belongs to the benchmark PR; this PR only claims the code-level improvement, not a release gate.

Verification

ctest -R '^test_orm_(model|sql|sqlite|tx_async)_func$'
4/4 passed

No DB, transaction, async or C ABI behavior changed. The benchmark remains unverified for MySQL/PostgreSQL/Windows and on a fixed performance runner.

Model metadata is static; validate_model<T> was re-walking every column on every CRUD call. Cache the validation result (status and message) on first use and return copies to callers.
@Antruly

Antruly commented Nov 27, 2026

Copy link
Copy Markdown
Owner Author

Local review before merge: ORM model/SQL/SQLite/transaction tests 4/4 pass; single-run A/B point select p50 extra is ~6.5%, find_all ~11%, write paths ~0%. Static metadata makes the cache safe; callers still get a copy of the error string. Fixed-runner 3-round gate remains in the benchmark PR.

@Antruly
Antruly merged commit 3d86fd7 into master Nov 27, 2026
45 of 52 checks passed
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