Repository navigation
perf: Build ORM query strings and result rows once - #6004
Open
abdelaziz-mahdy wants to merge 2 commits into
Open
abdelaziz-mahdy wants to merge 2 commits into
abdelaziz-mahdy wants to merge 2 commits into
Conversation
Every query rebuilt the same strings for each column: its quoted name, its aliases and its table's query prefix, and compiled a new RegExp per column to check that it belongs to the queried table. Columns and tables don't change once created, so the strings are now built on first use, and the table check is a plain prefix comparison (same matches).
Rows went through ResultRow.toColumnMap(), then a copy that unwraps UndecodedBytes, then the alias-resolved map. The first two are now one map built from the row values with the same keys, and rows are materialized once, so resolving includes doesn't rebuild them.
This was referenced Nov 13, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Each query rebuilt the same strings for every column of the table:
Column.toString);queryAliasandfieldQueryAlias;queryPrefix.hasBaseTablealso compiled a newRegExpper column per query. Regularexpressions run in an interpreter in AOT. Columns and tables don't change once
created, so the strings are now built on first use.
hasBaseTableis aprefix comparison with the same matches.
Result rows went
ResultRow.toColumnMap(), then a copy unwrappingUndecodedBytes, then the alias-resolved map. The first two are now one mapbuilt from the row values, with the same keys.
Part of #6002
Measurements
AOT, macOS arm64, retired CPU instructions per request, mean of 3 shuffled
runs, each change alone against
main:findByIdfind, 20 rowsinsertRowBold: every run below every run of
main.Tests
Full Serverpod test run on the combined branch (the PR branches are subsets): unit tests of serverpod, serverpod_serialization, serverpod_shared and serverpod_database pass; integration tests 1,683 (serial) + 529 (
util/run_tests_integration_concurrently) pass;dart analyzeis clean on this branch. No behaviour change, so no new tests. The existing query builderand result parser tests cover the strings and maps.
How it was measured: the app is compiled AOT and run natively; for each request type, k6 sends 15 s at 1,000 req/s, and the server process's retired instructions (
proc_pid_rusage(RUSAGE_INFO_V4)) before and after are divided by the number of requests. Builds ofmainand this PR were run alternately in shuffled order. I can share the scripts.Pre-launch Checklist
///), and made sure that the documentation follows the same style as other Serverpod documentation. I checked spelling and grammar.Breaking changes
None.