Repository navigation
dmp: bound diffs by work (diffWorkLimit 25M), not the clock (P3 of #26) - #30
Merged
Merged
Conversation
…get (diffWorkLimit 25M) instead of diffTimeout 0.2 The same two texts now give the same patch on any machine, however fast or loaded; 25M units are about 0.2 s on V8 on an AMD EPYC core (dmp README). Requires @cocalc/diff-match-patch ^1.1.0.
williamstein
marked this pull request as ready for review
October 21, 2026 07:50
1.1.0 was published by us via npm trusted publishing on 2026-10-21; the new-release guard protects against malicious third-party releases and does not apply to our own package. Approved by William (Oct 21).
Contributor
Author
|
Merge evidence (@sagebrush): head d32e70a. William approved merging #30 when green (Oct 21), and approved overriding the minimumReleaseAge guard for our own @cocalc/diff-match-patch 1.1.0 (published by us via trusted publishing). Commit d32e70a adds |
This was referenced Oct 21, 2026
Merged
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.
Bound diffs by @cocalc/diff-match-patch's deterministic work budget (
diffWorkLimit, new in 1.1.0) instead of the clock (diffTimeout = 0.2).Why
diffTimeoutcuts a diff off by wall-clock time. So the same two texts give a different diff, a different patch and a different patch size depending on how fast and how loaded the machine is: a commit's patch isn't reproducible.diffWorkLimitcuts it off after a fixed amount of abstract work, so the same inputs give the same patch everywhere. This is step P3 of #26 (a deterministic diff bound).The change
src/dmp.ts:dmp.diffWorkLimit = DIFF_WORK_LIMIT(25,000,000, exported) replacesdmp.diffTimeout = 0.2. When set,diffWorkLimitreplacesdiffTimeout, and the clock is never read. That coversmakePatch/patchMake,diffMain, andapplyPatch's fuzzy matching diffs.diffWorkLimit + 24 × (n + 2). It doesn't bound all ofpatch_make, whose assembly and context search are linear in 1.1.0 (dmp#2).package.json:@cocalc/diff-match-patch^1.0.0→^1.1.0. The lockfile changes only those three dmp lines. pnpm also wanted to bump tinyglobby's picomatch; I left that out.src/merge3.tsis unchanged. It already usesdiffTimeout = 0and bounds its own work deterministically withMAX_DIFF_PRODUCT.Compatibility
Only newly made patches change, and only for diffs large enough to hit the cutoff. Below it, both settings give the exact diff. Stored patches, and applying them, are unaffected. Patches made by replicas on 0.14.0 and on this release are equally valid.
Tests (
src/dmp-work-limit.test.ts, 3)Date.nowthat throws,makePatch,diffMainandapplyPatchstill work, both on small texts and on a 100,000-character pair of unrelated texts whose diff the budget cuts off.diffTimeout = 0.2. I checked by reverting the line.Checks
vitest run: 22 files, 223 passed (1 skipped).oxlint --deny-warnings src: clean.tsc(types, CJS), rollup (ESM) and postbuild: OK.Note on CI: release age
The repo's pnpm policy,
minimumReleaseAge, is one day. dmp 1.1.0 was published at 2026-10-21T07:13:59Z, sopnpm install --frozen-lockfilerefuses it until about 2026-10-22 07:14 UTC. CI fails at install until then. I'll re-run it after that time. I haven't changed the policy (nominimumReleaseAgeExclude): that's William's call. The tests above ran locally against the installed 1.1.0.Not in this PR
Owner:
@cocalc-dev-lite2on cocalc.ai, project lite2 - cocalc #dev (1c8ec4b3)