Repository navigation
Lay out diffs lazily and bound Changes and File Viewer memory - #1061
Conversation
Unified diff (Changes and edit details), both platforms: - Collapsed rows come from two linear passes and are computed once per document instead of comparing every context row with every change on each render. - Rows sit at one measured height and only the rows near what the enclosing scroll view shows are composed or drawn, so the diff stays lazy inside the Changes viewer and the tool result sheet. The scroll width comes from the few widest rows. - The edit detail parses its patch once per patch value. Changes: - A server patch over 1 MB is cut at its last line end and the viewer says it shows the first 1 MB of the file's changes. - A patch built from before/after is written once into a buffer of its final size instead of splitting and joining both files. - The empty-source hint reads the last turn's file count from its published summary instead of fetching the whole turn diff. File Viewer: a file over 10,000 lines keeps syntax colors only for the 10,000 lines around the visible ones; v1 text is no longer encoded to bytes just to measure it. Refs #1057 Co-Authored-By: Claude Opus 5.5 <[email protected]>
…anges-file-viewer
There was a problem hiding this comment.
Automated review: no finding that 2+ of 3 passes agreed on.
5 finding(s) from a single pass, not posted
ios/OpenCode Mobile/OpenCode Mobile/Domain/Session/UnifiedPatch.swift:66high: CRLF is not counted as a line break when building a patch (muse-spark-1.3-contributor)ios/OpenCode Mobile/OpenCode Mobile/Domain/Session/UnifiedPatch.swift:23medium: Truncation strips \r from a CRLF line end (muse-spark-1.3-contributor)android/app/src/main/java/dev/opencode/mobile/domain/session/UnifiedPatch.kt:22medium: Patch preview limit uses chars instead of UTF-8 bytes (muse-spark-1.3-contributor)ios/OpenCode Mobile/OpenCode Mobile/Components/Chat/OpenCodeUnifiedDiff.swift:293medium: iOS hunk-header detection now treats context lines that start with "@@ " as new hunks (deepseek-v4.1-flash)android/app/src/main/java/dev/opencode/mobile/ui/components/chat/OpenCodeUnifiedDiff.kt:446medium: Row count is clamped to MAX_DIFF_LAYOUT_HEIGHT, silently dropping the tail of very long diffs (deepseek-v4.1-flash)
opencode pr-review · passes: muse-spark-1.3-contributor, glm-5.3-flash, deepseek-v4.1-flash · $0.116 · 1 pass(es) stopped early
|
Automated review single-pass findings, triaged:
|
Device check (#1057, after merge)This was checked as a local merge with #1060 and Defect found: line numbers past 2 digits are cut (both platforms, regression)Every row now gets one measured height, and the line-number columns are still 24 dp/pt wide. On
So any diff past line 99 (iOS) or 999 (Android) shows wrong or unreadable line numbers. A fix is ready as a local commit on top of Heap and timing (Android, combined build, after 10 child sessions were opened and released: 38 MB live)
The server fills patches only up to a budget. In the 67-file diff, 60 files came back with an empty patch and show "Preview unavailable", the same as before this PR. The banner was checked with that file as one of 4 changed files. Behaviour
Not checked: expanding context, hunk navigation, wide-glyph rows (tabs, CJK, emoji), the edit-detail sheet, scrolling to the very end of the cut patch, and the Android File Viewer. The device tool kept refusing touch injection on the emulator after a reinstall, and the scope was cut to an hour.
TestsCI |






Part of #1057: the unified diff view, the Changes screen and the File Viewer. Releasing closed sessions' transcripts is separate work.
Problem
On an Android emulator with a 192 MB Java heap and about 94 MB already live, opening a turn's Changes (60 files, about 620,000 added lines) and then a 1 MB file in the File Viewer took the heap to 191 MB, and the process died. Reading the code showed the same problems on both platforms:
@Stateinitial value is rebuilt each time the parent renders.before/aftercontents were split and joined into a patch several times over.What changed
Unified diff (Changes file viewer and edit details), Android and iOS
canExpandContextreads the cached result.Substrings and only splits a line when it could be a hunk header.How the diff stays lazy inside a parent that scrolls
The parents keep their current scroll containers: the Changes viewer's scroll column and the bottom sheet's scroll body on both platforms. Nesting a
LazyColumnorLazyVStackthere would either crash (Compose) or stop being lazy (SwiftUI). Instead the diff reads what the parent shows:SubcomposeLayoutreadsboundsInWindow()inonGloballyPositioned, so its visible rows are already clipped by every ancestor.bounds(of: .scrollView(axis: .vertical))throughonGeometryChange. With no vertical scroll view around it (the Appearance sample), every row is drawn.The design-system component's public API is unchanged.
Changes
FileDiffgainsisPatchTruncated(defaultfalse). A server patch longer than 1 MB is cut at its last line end when it is mapped, so the full string is not kept. The parser accepts a cut last hunk that holds fewer rows than its header says.before/afteris written once, straight into a buffer of its final size (UnifiedPatch). Each input is read a bounded number of times, and building stops at the same 1 MB. The output matches the old builder byte for byte, including iOS keeping\r\ninside a line.File Viewer
What a 1 MB file held, by reading the code. The text cap was already 1 MB:
Now:
Cap and what the user sees
Only in the Changes file viewer, and only for a file whose patch is over 1 MB (UTF-8 bytes on iOS, UTF-16 characters on Android, the same for ASCII):
Edit details in the tool result sheet are not capped.
Checks
./gradlew :app:testDebugUnitTest(full suite),:app:assembleDebug,:app:assembleDebugAndroidTest,:hexcode:assembleDebug: pass.xcodebuild buildandbuild-for-testingforgeneric/platform=iOS Simulator(OpenCode Mobile), andbuildfor Hex Code: pass. iOS tests were compiled but not run.FileViewerStatedoes not parse until it is read.Risks / Follow-ups
Device checks needed on both platforms (none were run here):
main, then expand and collapse context, use hunk previous/next, scroll vertically and horizontally, and check the selected hunk highlight.Other risks:
🤖 Generated with Claude Code
Open in [code]smith · Need help on this PR? Tag
@codesmith-botwith what you need.