Skip to content

bound editor git diff refinement - #19462

Merged
kevinushey merged 23 commits into
mainfrom
feature/19218-token-first-experiment
Nov 10, 2026
Merged

kevinushey merged 23 commits into
mainfrom
feature/19218-token-first-experiment

Conversation

@kevinushey

@kevinushey kevinushey commented Nov 5, 2026 •

Copy link
Copy Markdown
Collaborator

Large replacements can exhaust Ace's character-refinement budget and leave the editor without Git markers. Enable the bounded provider option while retaining the original line-alignment heuristics. The gutter and side-by-side review now use the same hunk-selection policy, so opening review preserves navigation and revert scope.

The integration refreshes cached chunks when review toggles, preserves coarse selection-mapping metadata through common-prefix offsets, and uses the provider's explicit timeout status instead of rerunning the diff on tokens. Character reads and Myers frontier advances share deterministic work budgets. Character highlights fall back to whole-line highlighting when their separate budget is exhausted.

The Ace source change is https://github.com/rstudio/rstudio-ace/pull/15. sync-ace-commits pins its repository and exact source commit; build-ace regenerates the bundles and supports an isolated Ace worktree. The pin includes the tokenizer fixes from rstudio/rstudio-ace#13 already shipped by RStudio. A baseline rebuild matched the existing core and diff bundles byte-for-byte. Review then corrected sparse-array context comparisons, added a plain-data clone fallback for Node 16, removed lint errors in that tokenizer dependency, and raised the per-group highlight read budget past the dynamic-programming path's worst case. This update regenerates the core and diff bundles; other generated outputs remain unchanged.

Five-sample medians from a 29-case harness (kept in this branch's history, removed before merge):

Case Previous gutter New gutter New review
300-line replacement 294.1 ms 15.8 ms 15.9 ms
800-line replacement 499.7 ms, no markers 110.1 ms 108.2 ms
Large historical Java change 252.8 ms 211.3 ms 227.9 ms

Validation:

  • Roborev full-branch review passed at bfc6c60cc2 after merging current main to reconcile NEWS entries; no actionable findings remain.
  • src/gwt/test/git_diff_test.html (ant testpage) drives the real editor, gutter, and split view: rendering, mode switching, navigation, peeks, individual reverts, mixed-hunk selection mapping, the cost of review toggles, and the provider timeout path. 35 checks pass. Running the test pages in CI is run the GWT test pages (ant testpage) in CI #19539.
  • Ace's ten existing diff tests, nine bounded-refinement tests, and nine tokenizer tests pass. Ace's browser runner also passes all 18 diff tests and all six context tests. Broader Ace checks reproduce baseline failures: Vim clipboard and CSS tokenization under Node, plus three older browser tokenizer tests.
  • The all-platforms E2E run passed at bfc6c60cc2.

Depends on rstudio/rstudio-ace#15: once it is reviewed and merged, the pin moves to the merged rstudio/montauk-daisy commit and the bundles are rebuilt.

Closes #19218.

@github-actions

github-actions Bot commented Nov 6, 2026 •

Copy link
Copy Markdown

RStudio E2E - all platforms

All tests passed!

#################### 100% pass rate

Passed Failed Skipped Flaky
5454 0 242 5
Platform ✅ Passed ❌ Failed ⚠️ Skipped 🔁 Flaky
✅ auth-teardown 4 0 16 0
✅ desktop-linux 1366 0 45 1
✅ desktop-macos 1371 0 40 2
✅ desktop-windows 1361 0 56 1
✅ server-linux 1304 0 53 1
✅ setup 48 0 32 0

View report online


All platforms - commit 188d677caec0d76715219e553b0c266e9d6aebad - Run #2157

@gtritchie gtritchie added this to the 2026.12 (Parrot Balsam) milestone Nov 6, 2026
@kevinushey
kevinushey requested a review from gtritchie November 6, 2026 19:20
@kevinushey
kevinushey marked this pull request as ready for review November 6, 2026 19:20

@gtritchie gtritchie left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Requesting changes mainly for two things: review loses character highlights on mid-size changes because of the highlight read budget, and the Ace pin points at an unreviewed draft. The other comments are smaller: an extra view update and a full re-diff on every review toggle, wasted highlight work with Ignore whitespace, no test for the timeout path, and the size of the experiment harness.

The numbers in the comments come from running the gutter and side-by-side view at bfc6c60 in a browser with logging.

totalCharacters: 65536,
highlightLines: 128,
highlightCharacters: 8192,
highlightGroupReads: 100000,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

highlightGroupReads (100,000) is lower than what refineCharacters spends on its dynamic-programming path, which it takes below 500 characters and which reads about 2·n·m elements. A coarse group of roughly 450–499 characters therefore always runs out and gets no character highlights in review, while larger groups take the Myers path and keep theirs. Measured at this head with N replaced lines like a0 <- f(0) → b0 <- f(1):

Lines Chars Reads Highlights
18 427 91,164 19
20 479 100,000 (exhausted) 0
22 531 13,439 23
60 1,519 99,121 61

Raising the group budget above the DP worst case (2·250·250 = 125,000), or charging DP groups differently, would fix it. The change belongs in rstudio/rstudio-ace#15.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Confirmed: 20 replaced lines of 420 characters got 0 highlights while 18 and 22 kept theirs. The DP path reads about 2nm characters, up to 125,000 at the 500-character threshold. Raised highlightGroupReads to 150,000 in rstudio/rstudio-ace@8fd0c0786 with a test over 18/20/22/60-line groups; pin and regenerated diff bundles in 2db6149.

Comment thread src/gwt/acesupport/git_diff_gutter.js Outdated
// character decorations, while both modes retain the same hunks.
if (refinementModeChanged)
{
this.updatePending = true;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Since updatePending is now always set here, the flushUpdate() at line 379 runs update() → setChunks() → view.setChunks() before view.setBaseLines(), and then view.setChunks() runs again. With logging at this head, every open shows:

view.setChunks hasBase=false baseLen=1
view.setBaseLines 5
view.setChunks hasBase=true baseLen=5

The first pass aligns, updates markers and syncs the selection against an empty base pane, and all of it is redone right away. Before this change the flush only ran when an update was already pending. Calling view.setBaseLines() first and then this.update(), which already hands the view its chunks, would avoid the extra pass.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed in acca597: the view gets the base first, then a single chunk delivery (a flushed update, or the cached chunks when none is pending).

Comment thread src/gwt/acesupport/git_diff_gutter.js Outdated
this.splitView.baseEditor.commands.removeCommand("closeGitPeek");
}

var refinementModeChanged = !!this.splitView !== !!view;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Each open and close of review now reruns the full diff synchronously. Closing doesn't need it: the gutter reads only line ranges, and the comment below says both modes keep the same hunks. Opening only needs it when a cached chunk is coarse, because non-coarse chunks already carry their full charChanges. Measured: a small edit with no coarse chunk re-diffed on both open and close. An 800-line replacement cost about 26 ms per toggle here, and the PR's table has 110–228 ms for its larger cases. Re-diffing only on open, and only if this.chunks.some(c => c.isCoarse), would keep toggles cheap.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed in acca597: closing never re-diffs, and opening only does when a cached chunk is coarse (and whitespace is not ignored). The test page now counts computeChunks calls across toggles for refined, coarse, and whitespace-insensitive diffs.

Comment thread src/gwt/acesupport/git_diff_gutter.js Outdated
var options = {
maxComputationTimeMs: MAX_COMPUTATION_MS,
boundedRefinement: true,
includeBoundedHighlights: !!this.splitView

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

includeBoundedHighlights ignores this.ignoreWhitespace, but GitDiffSplitView.setChunks drops every chunk's charChanges in that mode. With a 20-line coarse group and Ignore whitespace on, the gutter's chunk carried 21 highlights and the view's copy had 0. !!this.splitView && !this.ignoreWhitespace would skip that work.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed in acca597: includeBoundedHighlights is now !!this.splitView && !this.ignoreWhitespace, with a test page check that a whitespace-insensitive diff carries no highlights.

if (this.lastDiffMs >= MAX_COMPUTATION_MS && isWholeDocument(chunks, base, lines))
// Character-budget exhaustion keeps a valid coarse hunk. A failed
// line alignment cannot safely supply markers or a revert scope.
if (chunks.hitTimeout)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is now the gutter's only guard against a failed line alignment, and no test reaches it. The timeout checks in experiment.test.cjs all assert that no timeout happened, and git_diff_test.html only checks diffFailed === false. If hitTimeout were lost (for example dropped in DiffProvider.compute, or offsetChunks applied first), a timed-out alignment would come back as one chunk over the whole trimmed range, with every line marked and Revert scoped to all of it. A test that forces a timeout, e.g. through the harness's budgetMs option on a large alignment, and asserts diffFailed with no chunks would cover it.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Added in acca597: the test page fakes Date.now to force a line-alignment timeout and asserts diffFailed with no chunks in the gutter and the review, then recovery on the next update.

Comment thread src/gwt/tools/sync-ace-commits Outdated
# Based on rstudio/montauk-daisy, including the already-shipped tokenizer
# fixes from rstudio/rstudio-ace#13 and bounded diff refinement for #19218.
REPOSITORY=https://github.com/rstudio/rstudio-ace.git
REVISION=438daddf239cd989210ef48e088179b3e9e9176c

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

438daddf is the head of rstudio/rstudio-ace#15, which is still an open draft with no review, 10 commits ahead of rstudio/montauk-daisy. The committed core and diff bundles were built from it. Before this merges, the pin should move to the merged integration-branch commit and the bundles should be rebuilt from it. Otherwise a squash or rebase merge there leaves these bundles matching no branch.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Agreed. The pin now points at rstudio/rstudio-ace@8fd0c0786 on that branch (the budget fix above); it will move to the merged rstudio/montauk-daisy commit with a rebuild once rstudio-ace#15 is reviewed.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Correction: the integration branch is now rstudio/parrot-balsam, cut today from the montauk-daisy head, since montauk-daisy is what rel-montauk-daisy rebuilds from. rstudio-ace#15 is retargeted to it and d488b55 updates the references here. The pin will move to the merged parrot-balsam commit with a rebuild.

const { test } = require('node:test');
const { STRATEGIES, TOKEN_STRATEGIES, createEngine, createProductionEngine, timedOut, tokenize, validateChunks } = require('./engine.cjs');
const { syntheticCases } = require('./fixtures.cjs');
const engine = createEngine();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

None of the new tests run in CI. The Jenkins PR build runs only ant unittest (gwt-unit-tests.sh), so neither git_diff_test.html (under testpage, like the other test pages) nor this file runs. This file also calls createEngine() at load, which git shows baseline 9bebbdec, so on a shallow clone it fails before any test starts. The tests of shipped behaviour would be more useful somewhere CI runs them, without the baseline dependency.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Removed the harness in 96486bb. The shipped behaviour is covered by Ace's bounded_refinement_test.js and src/gwt/test/git_diff_test.html, which now also covers the toggle costs and the timeout path. Running ant testpage in CI is a pre-existing gap (the autoindent pages are in the same position); I will file a follow-up for it.


const ROOT = path.resolve(__dirname, '../../../..');
const TOKEN_STRATEGIES = ['bare', 'indent', 'padded', 'indent-padded', 'structured'];
const STRATEGIES = ['current', ...TOKEN_STRATEGIES, 'line-only', 'bounded'];

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The harness is 1,657 lines, and most of it compares strategies this PR doesn't ship (current, bare, indent, padded, indent-padded, structured, line-only). That includes a skipCharacterRefinement provider option that isn't in the shipped provider, applied to a pinned historical gutter and provider through 16 replaceOnce patches. The tests of shipped behaviour could stay, and the strategy comparison could live in this PR's history rather than in src/gwt/tools.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Agreed; removed in 96486bb. The strategy comparison stays in this branch's history.

// reads, not elapsed time: review decorations cannot alter hunk selection by
// spending more of a shared deadline. Size caps also bound allocation and
// heuristic work outside getElement(). Line alignment retains its time limit.
function installBoundedRefinement(provider, experiment) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This repeats the limits, characterCount, the read budgets and the refine policy from Ace's bounded_refinement module, and the first test checks the shipped provider against this copy. Any later tuning in rstudio-ace has to be repeated here by hand, and since the test only runs by hand, the two can drift apart without anyone noticing. If the reference copy isn't needed beyond this PR, dropping it removes the second source of truth.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Removed with the harness in 96486bb, so Ace's module is the only copy of the limits.

Groups under 500 characters are refined by dynamic programming, which reads about 2*n*m characters (up to 125,000), so a 100,000 per-group highlight budget always ran out for groups of roughly 420-499 characters while larger groups, refined by Myers, kept their highlights. Pin rstudio-ace 8fd0c0786 (150,000) and regenerate the diff bundles.
Opening review handed the view its chunks against an empty base and then again after the base, and every open and close re-ran the full diff. The view now gets the base first and a single chunk delivery; the diff re-runs only on open, and only when a cached coarse hunk lacks highlights. Whitespace-insensitive diffs no longer request highlights the view drops. The test page checks the toggle costs and the provider timeout path.
The harness compared strategies this PR does not ship, duplicated Ace's refinement limits, and ran only by hand. The shipped behaviour is covered by Ace's bounded_refinement_test.js and the git_diff_test.html test page; the comparison stays in this branch's history.
rstudio/montauk-daisy is the 2026.11 release's fork branch, which rel-montauk-daisy rebuilds from; main-bound Ace changes target a branch named after version/RELEASE.

@gtritchie gtritchie left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The earlier comments are addressed, and git_diff_test.html passes 35/35 at d488b55. What remains before this can merge:

  1. Merge rstudio/rstudio-ace#15. It's approved, but the pin here (8fd0c078) is 3 commits behind its head (b6efba12). Those commits change tokenizer context copying, what the diff budget charges, and the row clamp in selection mapping.
  2. Pin the merged commit and rebuild the core and diff bundles from it.
  3. Resolve the conflict in src/gwt/tools/sync-ace-commits. #19540 on main changed BRANCH= to rstudio/parrot-balsam; keeping this PR's REPOSITORY/REVISION version resolves it. Main's other recent changes in the Ace folder are Java-only, so the rebuild won't drop anything.
  4. Rerun git_diff_test.html after the rebuild, since the budget and clamp changes affect what it checks.

There's also one minor inline comment about reopening review.

Comment thread src/gwt/acesupport/git_diff_gutter.js Outdated
// the view the previous chunks, and its first folds with them.
view.setBaseLines(this.baseLines);
view.setChunks(this.chunks, this.ignoreWhitespace);
if (opening && lacksHighlights(this.chunks, this.ignoreWhitespace))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

lacksHighlights() checks whether a cached chunk is coarse, not whether the cached diff was computed with highlights. Closing review no longer re-diffs, so after a close the coarse chunks still carry the highlights from the last open, and reopening with no edit in between runs the full diff again for nothing.

Measured at d488b55 with a 40-line coarse group: the first open re-diffs and the chunk gets 41 highlights, closing keeps all 41, and reopening with no edit runs another full diff. The test page expects this ("opening review on a coarse hunk runs one diff" right after a close). The function's comment ("Whether a change is missing the character highlights...") also says more than the check does.

Recording in computeChunks whether includeBoundedHighlights was set, and re-diffing on open only when it wasn't, would avoid the extra diff on large files.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Confirmed: a coarse hunk stays coarse after it gets its highlights, so the reopen re-ran the diff. Fixed in 01c6cd6: computeChunks records whether highlights were requested, and opening re-diffs only when a coarse hunk's diff ran without them. The test page now expects no diff on a reopen and one diff when the cached diff ran with review closed, and (58f8e9e) covers a 40-line coarse hunk gaining its highlights on open and keeping them across a close and reopen.

A coarse hunk stays coarse after its diff is run for review, so opening review re-ran the full diff every time, even right after a close with no edit in between. Record whether the cached diff was asked for highlights and re-diff on open only when it was not.
Picks up the three commits approved in rstudio/rstudio-ace#15 since 8fd0c0786: plain-clone tokenizer context copying, a diff budget that charges only the diff algorithm and rejects unknown limits, and the row clamp in selection mapping.
rstudio/rstudio-ace#15 is merged as 8ed240171, whose tree matches b6efba12a, so the bundles are unchanged.
Ace now clamps a mapped row at 0, so a fold from an added first line over two or more lines no longer mapped to row -1 and got a counterpart that left the first shared line visible. Check the chunk for that start instead of the mapped row, and cover a budgeted coarse hunk gaining and keeping its review highlights on the test page.
Opening review only re-ran the diff for a coarse hunk without highlights, so a line alignment that had timed out stayed failed until the next edit.
@kevinushey

Copy link
Copy Markdown
Collaborator Author
  1. rstudio/rstudio-ace#15 is merged as rstudio/rstudio-ace@8ed240171.
  2. The pin is at the merged commit in e5ab271. The core and diff bundles were rebuilt in 77d9e99 from b6efba12a, which has the same tree as the merge commit.
  3. Main is merged in 83bf76e, keeping the REPOSITORY/REVISION version of sync-ace-commits.
  4. git_diff_test.html passes 50/50 after the rebuild (ant testpage: 867 passed, 0 failed across 11 pages).

Three more changes came out of a review pass over the result:

  • 58f8e9e: the row clamp from rstudio-ace#15 changed fold mirroring. A fold from an added first line over two or more lines used to map to row -1 and get no counterpart; clamped to row 0 it got a partial base fold that left the first shared line visible. mirrorFold now checks the chunk for that start rather than the mapped row, with test page coverage.
  • 188d677: opening review also retries a diff whose line alignment timed out. Since the re-diff on open was narrowed to coarse hunks, a timed-out diff stayed failed until the next edit.
  • 571e8fb: sync-ace-commits passes the pinned checkout to build-ace explicitly, so an exported ACE_SOURCE_DIR cannot change what a sync builds.

@kevinushey
kevinushey requested a review from gtritchie November 10, 2026 19:22

@gtritchie gtritchie left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Approving. The review comments are addressed, and I checked at 188d677:

  • The pin is 8ed24017, the merge commit of rstudio/rstudio-ace#15 (same tree as the approved head). Rebuilding with build-ace from a fresh clone at that commit reproduces every committed Ace output byte-for-byte.
  • Reopening review with no edit reuses the cached highlights (no diff); a reopen after an edit, or after turning Ignore whitespace off, runs one.
  • git_diff_test.html passes 50/50 and the other ten test pages pass (867 checks in all). The "tokenizer context is missing ... state" warnings from context_test_rmd.html are identical on main.

Before merging, please update the PR description, since it becomes the squash-merge message. It still says the PR depends on rstudio/rstudio-ace#15 and that the pin will move to rstudio/montauk-daisy, quotes 35 checks instead of 50, says review toggles always refresh cached chunks, and gives E2E and roborev results for bfc6c60. It also doesn't mention the two behaviour changes added since: a failed diff is retried when review opens (188d677), and a fold starting in lines added at the top of the file is left unmirrored (58f8e9e).

@kevinushey
kevinushey merged commit f177f64 into main Nov 10, 2026
48 checks passed
@kevinushey
kevinushey deleted the feature/19218-token-first-experiment branch November 10, 2026 21:28
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.

Git gutter: diff on per-line tokens to skip the provider's character-level refinement

2 participants