Skip to content

reduce: stop keeping visited synthetic times as witnesses - #1113

Draft
frankmcsherry wants to merge 1 commit into
master-nextfrom
reduce-forget-visited-synth
Draft

frankmcsherry wants to merge 1 commit into
master-nextfrom
reduce-forget-visited-synth

Conversation

@frankmcsherry

Copy link
Copy Markdown
Member

The cursor reduce keeps every synthetic time it visits in times_current for the rest of the round, and those times never cancel.
When many input times are retired in one round, that can cost about n²/2 evaluations where one round per step costs about 3n.
This PR stops keeping them, and relies on the batch buffer and output_produced, which do cancel.
It is a draft for discussion; open questions are at the end.

The problem

At step i of the test workload, a record is inserted at (i, n+1-i) and retracted at (i+1, n+1-i), and another record lives at (i, 0) for one step.
The sweep finds the retraction time as the join of the seed (i+1, 0) with the still-live insert, visits it, and pushes it into times_current.
The insert and retraction then cancel in the batch buffer, but the bare time in times_current stays.
Advanced by the meet it becomes (s, n+1-i), which never merges with the others, and every later seed (s, 0) joins it into a fresh synthetic time that changes nothing.
This is the case the TODO at the push described: "If we knew that the time derived from a canceled batch update, we could remove the time."

The change

  • A visited synthetic time is no longer pushed into times_current.
  • A time is also interesting if a correction emitted this round lies at or below it.
  • Every time, interesting or not, joins with output_produced, as it does with times_current. Interesting times already did.

times_current now holds only the due pending times.

Measurements

Logic calls and wall time on the test workload, one key, release, on an M4 Mac mini:

n master-next, one round this PR, one round either, one round per step
500 126,252 (0.37 s) 1,502 (2.0 ms) 1,502
1,000 502,502 (2.7 s) 3,002 (2.4 ms) 3,002
2,000 2,005,002 (21 s) 6,002 (4.7 ms) 6,002

On master-next the counts are exactly (n+1)(n+4)/2; with this PR they are 3n+2, the same as one round per step.

The new test reduce_scaling_cancelled_history runs n = 100,000 in one round, in about 2 s in debug.
On master-next the same test takes 46 s at n = 1,000 and 361 s at n = 2,000, in debug.
As with reduce_scaling and join_scale_*, a regression shows up as a test that does not finish.

Correctness checks, none committed:

  • A randomized test against a from-scratch oracle, with three-dimensional times and random frontiers: 50,000 seeds pass. The same harness finds 5 failures in 2,000 seeds on the code before reduce: pend joins of history times advanced past upper #1109.
  • A churn version of it, where four in five records are retracted in the same round at a time at or after their insertion: 50,000 seeds pass. It makes 654,184 logic calls against 655,920 on master-next, so the changed path is exercised.
  • examples/dynamic.rs (BFS) at four sizes up to 100,000 nodes: identical output, same time.
  • cargo test -p differential-dataflow -p differential-dogs3 --all-targets: 114 passed, 3 ignored. Doc tests: 54 passed.

How it lines up with formal/

No change to the model is needed.
In Model.lean the enumeration joins seeds with base times, and the base is the support of the stored input and output plus the seeds (viewBase).
A time reached inside the interval is a seed joined with base times one at a time (reached_of_mem_cl), so joins between two reached times add nothing there.
A visited synthetic time that emitted nothing is in no support, so when a round is read as a sequence of finer rounds (#1110), later pieces never join with it.
The new interesting test is the README's "debt is created only above the seeds", read through the meet-advanced buffers: a time with no surviving batch entry, correction, or due pending time below it owes only what it owed before the round, and that sits above a pending time.

What is not proved is the step from the sweep to the model, the same informal step as before (#1110's "Not covered").
This change leans on it more: a visited time is now remembered only through buffers that cancel, where before the bare time stayed.

Questions

  1. output_produced is advanced by the meet and consolidated only when a correction is added (the existing NOTE). It now does witness duty, so stale entries mean extra evaluations, never wrong output. Should it be compacted every step, as times_current is?
  2. The proxy reduce is also quadratic on this workload: 2,005,004 logic calls and 26 s at n = 2,000 in one round. The cause is different: it keeps its seed times bare in reached, by design, and the same change there leaves the count unchanged (502,504 at n = 1,000 either way). Fixing it would mean letting seed evidence cancel. Separate PR, or not at all?
  3. The change replaces two comments that no longer describe the code: "We don't know enough about next_time to avoid putting it in to times_current." and the TODO quoted above.

Written by Claude Code (Claude Opus 5.5) from a design discussion; measured on an M4 Mac mini.

🤖 Generated with Claude Code

The cursor reduce kept every synthetic time it visited in `times_current`, as a bare time.
A bare time never cancels, so it stayed after the updates that produced it cancelled, and kept making later times interesting.
With many input times retired in one round, this can cost about n²/2 evaluations where single steps cost about 3n.

A visited synthetic time is no longer kept.
What made it interesting stays in the batch buffer, and what it emits goes to `output_produced`.
`output_produced` now also marks later times interesting and joins with uninteresting times, as `times_current` did.
Both are advanced by the meet and consolidated, so they vanish once they cancel.

`reduce_scaling_cancelled_history` runs such a round with n = 100,000.
It takes about 2 s in debug with this change; on master-next the same workload takes 46 s at n = 1,000 and 361 s at n = 2,000.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

This branch has not been deployed

No deployments
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.

1 participant