Repository navigation
perf(processor): run one-morsel node scans on the calling thread, allocate TopK scratch on use - #1499
Merged
Conversation
…n the caller A node table scan whose source hands out one morsel, and an ORDER BY merge with one sorted run, have no work for a second thread. Narrow those tasks to one thread so they run inline instead of waking the worker pool. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
TopKBuffer allocated and zeroed two 2048-value vectors per payload column plus the boundary vectors in every local and shared buffer. Only reduce() and merge() use them, so a buffer under the reduce threshold never needed them. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
|
I was concerned about sub-morsel parallelism. But it's not an issue. In the cases where the node groups are split, this optimization is bypassed because getNumMorsels() > 1. |
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.
This work was produced with the help of language models.
Part of #1432.
On the issue's 50-row table, a prepared
MATCH (t:T) RETURN t.id, t.agetook 94 µs with the default 16 threads and 11 µs withCALL threads=1. The table is one morsel, but its scan ran as a parallel task, so every execution woke the worker pool;ORDER BYwoke it twice. TopK also allocated and zeroed two 2048-value vectors per payload column in every buffer, which glibc faulted back in on each execution (36 page faults forLIMIT 10on one thread).Fix. A node table scan with at most one morsel, counting uncommitted node groups, and an
ORDER BYmerge with at most one sorted run become one-thread tasks, which run on the calling thread unless a query timeout is set (#1297). Only one thread had work there, so no parallelism is lost. The scan now sets up its shared state, where it counts morsels, just before scheduling.TopKBufferallocates its scratch vectors on first use inreduce()ormerge().Median µs, Ryzen 9 6900HS, 16 threads, C++ API:
main→ PRmain→ PRWHERE t.age > 45+ ORDER BY t.age DESC+ LIMIT 10Most of the remaining text-query time is compiling; the comment on #1432 covers it.
Tests.
SingleMorselTaskTestrecords each scanned row's thread with a UDF: a one-morsel scan runs on the caller, while three morsels, an uncommitted row, or two tables underMATCH (n)run on workers. A merge task accepts one thread for one sorted run and two for two.top_k_reduce.testreaches TopK'sreduce(), which no test did. Each check fails when its condition is removed. Arrow and ice-disk tables with several row groups are not covered. Full ctest: no failures.Cost. Scans of more than one morsel are unchanged. A 2M-node table (sum, sort, TopK) and a 1,000-node source with 2M edges stay within 0.4% of
main's instructions, TopK measured on one thread. On LDBC SNB SF1 (the 30-query suite and complex IC1–IC14, 4 and 16 cores), no query is slower in every round; geomeans are 0.97–1.02 ofmain.