Repository navigation
bound editor git diff refinement - #19462
Conversation
RStudio E2E - all platformsAll tests passed!
All platforms - commit |
gtritchie
left a comment
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
| // character decorations, while both modes retain the same hunks. | ||
| if (refinementModeChanged) | ||
| { | ||
| this.updatePending = true; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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).
| this.splitView.baseEditor.commands.removeCommand("closeGitPeek"); | ||
| } | ||
|
|
||
| var refinementModeChanged = !!this.splitView !== !!view; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
| var options = { | ||
| maxComputationTimeMs: MAX_COMPUTATION_MS, | ||
| boundedRefinement: true, | ||
| includeBoundedHighlights: !!this.splitView |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
| # 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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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']; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
The earlier comments are addressed, and git_diff_test.html passes 35/35 at d488b55. What remains before this can merge:
- 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. - Pin the merged commit and rebuild the core and diff bundles from it.
- Resolve the conflict in
src/gwt/tools/sync-ace-commits. #19540 on main changedBRANCH=torstudio/parrot-balsam; keeping this PR'sREPOSITORY/REVISIONversion resolves it. Main's other recent changes in the Ace folder are Java-only, so the rebuild won't drop anything. - Rerun
git_diff_test.htmlafter the rebuild, since the budget and clamp changes affect what it checks.
There's also one minor inline comment about reopening review.
| // 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)) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
Three more changes came out of a review pass over the result:
|
gtritchie
left a comment
There was a problem hiding this comment.
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-acefrom 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.htmlpasses 50/50 and the other ten test pages pass (867 checks in all). The "tokenizer context is missing ... state" warnings fromcontext_test_rmd.htmlare 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).
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-commitspins its repository and exact source commit;build-aceregenerates 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):
Validation:
bfc6c60cc2after 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.bfc6c60cc2.Depends on rstudio/rstudio-ace#15: once it is reviewed and merged, the pin moves to the merged
rstudio/montauk-daisycommit and the bundles are rebuilt.Closes #19218.