Repository navigation
v1.22.0
-
DBSQLAdapter.executedSQLsCount: the number of SQL statements (round
trips) executed for entity and relationship operations. The shared DB
tests pin the statements of each operation (insert,selectByID,
selectByQuery,length, update,deleteByID) on every SQL adapter, so
an optimization or a regression changes them visibly.benchmark/db_users:--repeat N(the median of N rounds per
operation, with their range). The users registered by eachregister
round are removed after it, so every round (andupdate/removeafter
it) runs on the same table sizes. The benchmark'sUser.create()no
longer hashes an empty password for every user loaded, and
Address.stateis indexed (user/byState).
-
Optimization: storing the relationships of a just inserted entity, with
an ID generated by that insert, no longer runs aDELETEof its other
relationship rows (it has none) on the adapters whose generated IDs are
never reused (DBSQLAdapter.generatedIDsHaveNoRelationships: PostgreSQL,
MySQL): one statement (round trip) less per relationship field on every
insert. An insert of a user with an address (2 relationship fields) and
2 roles: from 9 statements to 6.TransactionOperationStoreRelationship.newEntity.- The relationship tables bones_api generates delete a deleted entity's
rows (ON DELETE CASCADE). A relationship table without it, on a
database that can reuse an ID (MySQL before 8.0 resetsAUTO_INCREMENT
on restart; a reset PostgreSQL sequence), could give a new entity a
deleted one's relationship rows: override
generatedIDsHaveNoRelationshipsasfalsethen.
-
Optimization: generated relationship tables no longer get an index on the
source column (<table>__<source>__idx): it's the first column of their
UNIQUE (source, target)constraint's index, which already serves
lookups by it (one index less to update on every write). Existing tables
keep it;checkTablesdoesn't require it (PostgreSQL resolves an index
by its first column). -
Optimization:
Transactionno longer captures aStackTraceon every
commit (it only located an unexpected error): only with asserts enabled
(debug, tests).user/countof the users benchmark: +62% (memory), +32%
(SQLite). -
Optimization:
SQL.sqlPositional(SQLite) is computed once per SQL text
(with the default placeholder), not with a regular expression per
statement. -
Optimization:
DBPostgreSQLAdapterresolves the column names of a result
once for all its rows. -
Optimization:
@pragma('vm:prefer-inline')on small functions of hot
paths that a CPU profile showed not inlined:ZoneField.get(the
executingTransaction), the row layout match ofcreateFromMap, the
digits ofparseDateTimeISOUTCFast(a top-level function, not a closure)
and the common values (null,num,String,bool) of the tracking
copy of an entity's fields. Users benchmark:byState(a join, 20 users)
+3% (SQLite), +1% (memory); the others within their variation. -
Behavior change: a SQL select with a
limit(and noorderByID) is
now ordered by the ID column (ORDER BY id ... LIMIT n), as one with an
offsetalready was: which rows an unorderedLIMITreturns is
undefined in SQL (it can change with the query plan), e.g. which row a
selectFirstByQueryreturns. PassorderByID: falseto opt out. The
in-memory adapters (DBSQLMemoryAdapter, the object adapters,
IterableEntityRepository) keep their rows in insertion order and still
order only for anoffset. Alimitof0(noLIMITclause) doesn't
order.OrderDirection.resolveOrderByID(orderByID, offset, [limit]).
-
Fix:
DBObjectGCSAdapter: parallel cache writes over the cache limits
(cacheLimit/cacheFilesLimit) started concurrent limit checks, which
listed and deleted the same files: the second delete threw a
PathNotFoundExceptionin a future nobody awaited (an unhandled error).
The checks now run one at a time: a call during a check queues one more
check after it (shared by the calls until then), since the running one
may have listed the files before that call's write. A cached file already
removed counts as deleted, and an error of a check (nobody awaits it: e.g.
the cache directory removed) is logged, not left as an unhandled error. -
Optimization: turning rows (or any
Map) into entities
(EntityHandler.createFromMap), for every adapter:resolveFieldsValuesresolves the values into one map, synchronously
when none of them is aFuture(noforEachAsync, entries and
intermediate maps per row).- The key of each field in a row is matched once per row layout (its
keys, in order) and reused for the next rows with the same keys,
instead of per row (with 2 lookup maps built per row). resolveValueByTypeno longer builds aTypeInfoof every value: the
conditions that don't depend on the value are checked first.parseDateTimeISOUTCFast: theDateTimesDBSQLiteAdapterstores
(toUtc().toIso8601String()) are parsed without a regular expression.- Users benchmark vs 1.22.0's previous changes: SQLite
list/byState
(20 users per call) +31%, single-user reads +11–12%; memorybyId
+12%.
-
Fix:
DBMySQLAdapter: aNULLcolumn of a select with parameters (e.g.
selectByQuery(' name == ? ')) was read as absent, so the entity field
got its default (e.g.0) instead ofnull:mysql1leaves it out of a
row'sfieldsin its binary protocol (a statement with parameters). The
rows are now read from theirvalues. -
Fix:
ConditionSQLEncoder.encodeIDCondition/encodeIDConditionINbuilt
the ID column from the encoding parameter key, which is renamed (e.g.
"param_id") when the query has a parameter named like the ID column. -
SQL: the IDs of an ID condition (
#ID == x,selectByID,selectByIDs
and the selects of references) are now parameters (placeholders), not
values written into the statement: its text is the same for any ID. An
INlist of IDs is padded (repeating its last ID) to1,2,4,8
...256, then multiples of256(ConditionSQLEncoder.idsListPaddedLength),
so its text is the same for lists of similar lengths. An ID that is
already a parameter of the query (#ID == ?) keeps it. Not faster by
itself (users benchmark: within −1.5% and +0.6%): the groundwork for
reusing statements (prepared statements per connection).SQLDialect.intParameterTypeSuffix(PostgreSQL::int8): an integer
ID parameter is typed, so an ID beyond the column's type matches
nothing (as a literal did) instead of failing ("out of range").SQLDialect.maxIDsAsParameters: anINlist padded beyond it is
written as values. A parameter is only faster when its statement is
reused, which a long list's length seldom is, and a statement's
parameters are limited (SQLite: 32766; PostgreSQL: 65535; e.g. a
selectByIDsof 40000 IDs). Measured selecting N rows by ID (reused
parameters vs values): PostgreSQL512(parameters 16–29% faster up
to ~400 IDs, about even at ~640–768, values faster from ~1024); SQLite
1024(the same cost per ID, ~10–15% less when reused); MySQL0, which
keeps the IDs written as values:mysql1runs a statement with
parameters as prepare + execute (2 round trips, not reused), one
without as 1. Splitting a list into batches is never faster than
values (PostgreSQL: a round trip per batch).
-
Behavior change: prepared statements, reused by SQL text
(PreparedStatementsCache; the least recently used released over
preparedStatementsCacheSize, default100per connection). On by
default; db configpreparedStatements: falsedisables them. Behind
PgBouncer in transaction pooling mode before 1.21, disable them: a
prepared statement's name can then refer, on a shared server connection,
to another client's statement, which runs instead (silently).DBSQLAdapter.preparedStatementsInfo: hits, prepared, evicted and
stale counters. An invalidpreparedStatementsCacheSize(< 1) passed to
an adapter's constructor throws anArgumentErrorthere (a config value
falls back to the default).DBPostgreSQLAdapter: per connection. A SQL text is prepared when it
repeats (preparing costs a round trip; a statement run once doesn't pay
it), and only outside a transaction (it would be prepared on the
transaction's session, ending with it); a prepared statement is reused
also inside the connection's transactions. A stale one (0A000: a
schema change altered its result columns;26000) is replaced, and the
statement run again unprepared (outside a transaction: inside one the
error aborted it). A cached statement runs only while its session is
open: on the session of a finished transaction it fails, as an
unprepared one does, instead of running outside that transaction.DBSQLiteAdapter: per database handle, on the first use (no round
trip); SQLite recompiles a prepared statement after a schema change.
Released before the handle is closed. A SQL with more than one
statement is still rejected (checkNoTail), not run up to its first.DBMySQLAdapter: none (mysql1doesn't reuse prepared statements).- Users benchmark vs the previous changes: SQLite single-user reads
+17–19%, writes +13–15%,list/byState+4–5%; PostgreSQL reads
+8–12%, writes about the same.