Skip to content

test: count work instead of elapsed time - #13452

Merged
tiensonqin merged 2 commits into
logseq:masterfrom
yuxi-liu-wired:test/work-counts
Sep 30, 2026
Merged

tiensonqin merged 2 commits into
logseq:masterfrom
yuxi-liu-wired:test/work-counts

Conversation

@yuxi-liu-wired

@yuxi-liu-wired yuxi-liu-wired commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

What changes

The 5 unit-test assertions that bound elapsed time (listed in #13446) now bound the work done instead, counted with with-redefs wrappers, so they give the same result on a busy machine as on an idle one. Test code only; each test keeps its other assertions.

  • frontend.worker.graph-view-test: the 2 large tags-and-objects graph tests count the d/entity lookups made while building the graph, at a small and a large size, and require the same count.
  • frontend.worker.search-test: the combine-results case counts the reads of result fields and the db lookups at 625 and 2,500 results. The 2 sync-search-indice-300-new-blocks-performance-* cases lose their time bound; other tests in the namespace count the work they guarded, and one of those, sync-search-indice-300-new-blocks-does-not-check-page-descendants, gets a tighter bound (below).

fastest-build and process-cpu-time-ms had no other users and are removed.

Per test

Each count was checked against the slowdown it guards: in a scratch build, never committed, the slow code was put back behind an environment flag and the namespace run with and without the flag. Without it every test passes.

tags-and-objects-graph-skips-large-unrelated-page-set-quickly

Guards f299b4e31 ("enhance: speed up tags graph", in #12604). The graph took every entity that has any tag, looked each up with d/entity and checked its visibility, then kept those tagged with a displayed tag. Every page carries the Page tag, so 12,000 plain pages meant over 12,000 lookups for an empty graph. Since the fix, only candidates of a displayed tag are looked up.

Count: d/entity calls during build-graph, with 12 unrelated pages and with 12,000: 417 and 417. The test asserts they are equal.

Slow code put back (look up and check every entity of the :block/tags datoms before the tag filter): 1,268 and 133,136. Fails.

tags-and-objects-graph-builds-large-tagged-set-quickly

Guards 1cccd59ce ("enhance: speed up graph opening", in #12604). Each tagged object was looked up with d/entity, checked with ldb/hidden?, ldb/recycled?, ldb/class? and ldb/property?, and its node built from entity attributes. Since the fix, visibility, titles and uuids come from datoms for all objects at once.

Count: d/entity calls during build-graph, with 12 tagged objects and with 3,885: 790 and 790, asserted equal. The node and link counts (3,886 and 3,885) stay.

Slow code put back ((visible-entity? (d/entity db id)) for each tagged object): 1,078 and 94,030. Fails.

combine-results-large-result-benchmark

Guards e47539398 ("fix: speed up worker search"). combine-results looked up each result with d/entity and found its keyword result with (first (filter #(= (:id %) id) keyword-results)), a scan of the results for each result. Since the fix, all results are pulled with 1 d/pull-many and walked once.

Count: each keyword result is a map that counts the reads of its fields (ReadCountingResult, a deftype over the map). 625 results: 3,750 reads; 2,500 results: 15,000, 4 times as many. The test asserts under 8 times, the midpoint between linear (4) and quadratic (16) on a log scale. The d/entity and d/pull-many calls are counted too: 1 at both sizes, asserted equal. The result count and the page-boost ranking stay.

Slow code put back:

  • the scan per result: 208,935 and 3,179,944 reads (15.2 times). Fails.
  • 1 d/entity per result instead of d/pull-many: 625 and 2,500 db lookups. Fails.

sync-search-indice-300-new-blocks-performance-when-semantic-search-enabled and ...-disabled

The time bound came with #12818 ("fix: speed up incremental search indexing"), in its first commit 69b60c60b. That commit dropped the vector context: each synced block had its parent, previous and next sibling and children added to the batch, and its vector title built from them, which sorted the parent's children again for every block. A later commit of the same pull request, 4d28bdcc1, stopped checking every new block for page descendants and added sync-search-indice-300-new-blocks-does-not-check-page-descendants, which counts the ldb/page? calls of the same 300-block insert.

These tests already count each of those causes:

  • Sibling sort per block: build-blocks-indice-uses-block-index asserts 0 ldb/sort-by-order calls while block->index, the function sync uses, builds vector titles for 40 siblings. With the sort put back into block->index: 40 calls. Fails.
  • Parent, siblings and children added to the batch: the 300-block cases themselves assert exactly 300 indexed blocks, and sync-search-indice-indexes-only-directly-affected-blocks asserts the parent and siblings stay out. With the expansion put back: 301 blocks (the page joins), and both fail.
  • Page-descendant check of every new block: does-not-check-page-descendants counts 300 page checks now, 1 per new block. With 4d28bdcc1's key line reverted (page-hierarchy-eids keeps the blocks that have a :block/page datom): 600. Its bound was (<= checks 600), so it still passed with the revert; it is now (<= checks 300), and the revert fails it.

The 2 cases keep their other assertions: 300 blocks, and vector titles present and equal to the titles, or absent.

Tests

  • frontend.worker.graph-view-test (20 tests, 59 assertions) and frontend.worker.search-test (65 tests, 213 assertions), with TZ=Etc/GMT+12 and TZ=Pacific/Kiritimati: 0 failures, 0 errors in each. The counts do not vary between runs, so each ran once.
  • The slow-code checks above: 1 scratch build, 1 flag per run; each flag fails the test its section names, and the same build with no flag passes.
  • The whole unit suite, once with TZ=Etc/GMT+12 (2476 tests, 12406 assertions) and once with TZ=Pacific/Kiritimati (the 1446 tests of the date-dependent namespaces). The only failures are the 3 zone-dependent tests that fix(test): build test dates in local time #13430 fixes (6 assertions at UTC-12, 4 at UTC+14), the same as on master.
  • clj-kondo on both files: 0 errors, 0 warnings.

Refs #13446.

Allow edits from maintainers.


Devin Review

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔍 Devin Review: 1 flag

Not posted on this PR by your GitHub settings — view it in Devin Review. (Configure)

Devin Review

@devin-ai-integration

Copy link
Copy Markdown
Contributor

Reasonable tradeoff replacing flaky elapsed-ms asserts with deterministic counters — the ReadCountingResult linearity check and the equal db-lookups assert are better signals anyway.

One coverage note: removing the timing bounds from the two sync-search-indice perf tests drops the guard for slowdowns that don't increase page checks or field reads (e.g. serialization/allocation regressions in the indice path). If that matters, a benchmark-style test that measures and reports without asserting would keep the signal without the flake.

Written by Devin

The 2 large tags-and-objects graph tests bounded wall-clock time (best
of 3 under 1 s). They now count the d/entity lookups made while
building the graph, at a small and a large size, and require the same
count: 12 and 12000 unrelated pages, 12 and 3885 tagged objects.
combine-results: instead of a 200 ms CPU bound, count the reads of
result fields and the db lookups at 625 and 2500 results. 4 times the
results must take under 8 times the reads (linear gives 4, a scan per
result 16) and the same number of db lookups.

The 2 sync cases for 300 new blocks drop their 1 s CPU bound. The
page-check count of the same insert now allows 1 check per new block;
checking every new block for page descendants doubles it, which the
old bound of 2 per block let through.
@tiensonqin
tiensonqin merged commit bc3f592 into logseq:master Sep 30, 2026
10 of 12 checks passed
@yuxi-liu-wired
yuxi-liu-wired deleted the test/work-counts branch September 30, 2026 20:03
devin-ai-integration Bot pushed a commit that referenced this pull request Oct 1, 2026
* test(graph-view): count entity lookups, not time

The 2 large tags-and-objects graph tests bounded wall-clock time (best
of 3 under 1 s). They now count the d/entity lookups made while
building the graph, at a small and a large size, and require the same
count: 12 and 12000 unrelated pages, 12 and 3885 tagged objects.

* test(search): count work instead of CPU time

combine-results: instead of a 200 ms CPU bound, count the reads of
result fields and the db lookups at 625 and 2500 results. 4 times the
results must take under 8 times the reads (linear gives 4, a scan per
result 16) and the same number of db lookups.

The 2 sync cases for 300 new blocks drop their 1 s CPU bound. The
page-check count of the same insert now allows 1 check per new block;
checking every new block for page descendants doubles it, which the
old bound of 2 per block let through.
devin-ai-integration Bot pushed a commit that referenced this pull request Oct 8, 2026
* test(graph-view): count entity lookups, not time

The 2 large tags-and-objects graph tests bounded wall-clock time (best
of 3 under 1 s). They now count the d/entity lookups made while
building the graph, at a small and a large size, and require the same
count: 12 and 12000 unrelated pages, 12 and 3885 tagged objects.

* test(search): count work instead of CPU time

combine-results: instead of a 200 ms CPU bound, count the reads of
result fields and the db lookups at 625 and 2500 results. 4 times the
results must take under 8 times the reads (linear gives 4, a scan per
result 16) and the same number of db lookups.

The 2 sync cases for 300 new blocks drop their 1 s CPU bound. The
page-check count of the same insert now allows 1 check per new block;
checking every new block for page descendants doubles it, which the
old bound of 2 per block let through.
devin-ai-integration Bot pushed a commit that referenced this pull request Oct 8, 2026
* test(graph-view): count entity lookups, not time

The 2 large tags-and-objects graph tests bounded wall-clock time (best
of 3 under 1 s). They now count the d/entity lookups made while
building the graph, at a small and a large size, and require the same
count: 12 and 12000 unrelated pages, 12 and 3885 tagged objects.

* test(search): count work instead of CPU time

combine-results: instead of a 200 ms CPU bound, count the reads of
result fields and the db lookups at 625 and 2500 results. 4 times the
results must take under 8 times the reads (linear gives 4, a scan per
result 16) and the same number of db lookups.

The 2 sync cases for 300 new blocks drop their 1 s CPU bound. The
page-check count of the same insert now allows 1 check per new block;
checking every new block for page descendants doubles it, which the
old bound of 2 per block let through.
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.

2 participants