Repository navigation
Probe identity-keyed expression caches without cloning the key - #10615
robert3005 wants to merge 3 commits into
Conversation
Merging this PR will improve performance by 25.23%2 warnings
Performance Changes
Tip Curious why performance improved? Comment Comparing Footnotes
|
f34b6ff to
1251b6b
Compare
|
This PR has been marked as stale because it has been open for 14 days with no activity. Please comment or remove the stale label if you wish to keep it active, otherwise it will be closed in 7 days |
1251b6b to
f0b73c8
Compare
Every split of a scan prunes with each filter conjunct, and each layout reader on the way looks the conjunct up in a cache keyed by tree identity. Each lookup cloned the expression into a key, hashed the options of its function, such as literal lists, and dropped the key again. The clones touch reference counts that every scan thread shares, and on TPC-DS q39 on DuckDB they were more than half of the pruning time. An ExactKey trait lets these maps be probed with a borrowed expression, the hash uses only the identity of the children, and the struct reader lends its cached partitioning instead of cloning it. Pruning in q39 takes a third of the samples it took before. Signed-off-by: Robert Kruszewski <robert@spiraldb.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
DuckDB scans of local files reuse the layout readers of a file across queries. The readers cache pruning results, partitioned expressions and evaluated dictionary values by the identity of the expression, and every query binds new expressions, so each query added entries that no later lookup could hit. The file statistics reader held every filter it pruned, which kept the expressions alive for all the caches below it. On ClickBench q20 the process grew by about 30 MiB per query, and the pages of each new allocation were faulted in and zeroed. Key these caches with WeakBoundExprKey, which identifies an expression as ExactBoundExpr does but holds its children weakly, and drop the entries of dead expressions when inserting a new one. The weak reference keeps the allocation of the children, so a later expression cannot take their address and match a stale key. ExactKey now compares identities so that both kinds of key can be probed with a borrowed expression. Memory of 13 runs of q20 stays at 190 MiB instead of growing to 540 MiB, and q20 and q21 take 16% and 21% less time. Signed-off-by: Robert Kruszewski <robert@spiraldb.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015qFEJyt9gzF3mi2F91ZwML
f0b73c8 to
4e1f8a4
Compare
Every split of a scan prunes with each filter conjunct, and each layout
reader on the way looks the conjunct up in a cache keyed by tree
identity. Each lookup cloned the expression into a key, hashed the
options of its function, such as literal lists, and dropped the key
again. An ExactKey trait lets these maps be probed with a borrowed expression,
the hash uses only the identity of the children, and the struct reader
lends its cached partitioning instead of cloning it.