Repository navigation
perf(server,web,mobile): Changes tab loads faster on large diffs, 20s -> 1.4s #26011
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
+1,333
−527
Closed
Changes from 2 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
ed3f388
perf(web,mobile,server): Changes tab lists every file at once and sto…
Yuruzuu e549ebc
Merge upstream/main into perf/changes-tab-fast-open
Yuruzuu 8c36130
fix(mobile): review keeps loaded patches while the connection drops
Yuruzuu a61764e
fix(web): find in the Changes tab searches collapsed files
Yuruzuu 780beef
perf(server,web,mobile): review diffs load and refresh faster
Yuruzuu 6bed5c7
Merge upstream/main into perf/changes-tab-fast-open
Yuruzuu f5054de
merge: resolve upstream main conflicts for PR #26011
Yuruzuu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
41 changes: 41 additions & 0 deletions
41
apps/mobile/src/features/review/reviewFilePatchDemand.test.ts
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| import { describe, expect, it } from "vite-plus/test"; | ||
|
|
||
| import { getReviewFilePatchLookahead } from "./reviewFilePatchDemand"; | ||
|
|
||
| const files = Array.from({ length: 30 }, (_, index) => ({ | ||
| path: `file-${index}.ts`, | ||
| previousPath: null, | ||
| additions: 1, | ||
| deletions: 1, | ||
| })); | ||
|
|
||
| describe("getReviewFilePatchLookahead", () => { | ||
| it("preserves default expanded viewport lookahead", () => { | ||
| expect(getReviewFilePatchLookahead(files, 0, undefined)).toEqual([ | ||
| "file-0.ts", | ||
| "file-1.ts", | ||
| "file-2.ts", | ||
| ]); | ||
| }); | ||
|
|
||
| it("does not request collapsed files or scan past the lookahead window", () => { | ||
| expect(getReviewFilePatchLookahead(files, 10, ["file-11.ts", "file-20.ts"])).toEqual([ | ||
| "file-11.ts", | ||
| ]); | ||
| expect(getReviewFilePatchLookahead(files, 0, [])).toEqual([]); | ||
| }); | ||
|
|
||
| it("keeps a requested path valid when another file is inserted before it", () => { | ||
| const requested = getReviewFilePatchLookahead(files, 10, ["file-10.ts"]); | ||
| const updated = [{ ...files[0]!, path: "earlier.ts" }, ...files]; | ||
|
|
||
| expect( | ||
| updated.filter((file) => requested.includes(file.path)).map((file) => file.path), | ||
| ).toEqual(["file-10.ts"]); | ||
| }); | ||
|
|
||
| it("bounds the window at the last file and ignores missing selections", () => { | ||
| expect(getReviewFilePatchLookahead(files, 29, undefined)).toEqual(["file-29.ts"]); | ||
| expect(getReviewFilePatchLookahead(files, -1, undefined)).toEqual([]); | ||
| }); | ||
| }); |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| import type { ReviewDiffFileStat } from "@t3tools/contracts"; | ||
|
|
||
| export function getReviewFilePatchLookahead( | ||
| files: ReadonlyArray<ReviewDiffFileStat>, | ||
| startIndex: number, | ||
| expandedFileIds: ReadonlyArray<string> | undefined, | ||
| ): ReadonlyArray<string> { | ||
| if (startIndex < 0) return []; | ||
|
|
||
| return files | ||
| .slice(startIndex, startIndex + 3) | ||
| .filter((file) => expandedFileIds === undefined || expandedFileIds.includes(file.path)) | ||
| .map((file) => file.path); | ||
| } |
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
69 changes: 69 additions & 0 deletions
69
apps/mobile/src/features/review/useReviewDiffPrewarming.test.ts
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| import { describe, expect, it, vi } from "vite-plus/test"; | ||
|
|
||
| import { getCachedNativeReviewDiffData } from "./nativeReviewDiffAdapter"; | ||
| import type { ReviewSectionItem } from "./reviewModel"; | ||
| import { getCachedReviewParsedDiff } from "./reviewState"; | ||
| import { getReviewDiffPrewarmSections, prewarmReviewDiffSection } from "./useReviewDiffPrewarming"; | ||
|
|
||
| vi.mock("./nativeReviewDiffAdapter", () => ({ getCachedNativeReviewDiffData: vi.fn() })); | ||
| vi.mock("./reviewState", () => ({ | ||
| getCachedReviewParsedDiff: vi.fn(() => ({ kind: "empty" })), | ||
| getReviewParsedDiffSourceCharacterCount: (input: { diff: string | null }) => | ||
| input.diff?.length ?? 0, | ||
| MAX_CACHED_REVIEW_DIFFS: 8, | ||
| MAX_CACHED_REVIEW_SOURCE_CHARACTERS: 4_194_304, | ||
| })); | ||
|
|
||
| function section(id: string, lazy = false): ReviewSectionItem { | ||
| return { | ||
| id, | ||
| kind: "working-tree", | ||
| title: id, | ||
| subtitle: null, | ||
| diff: "patch", | ||
| isLoading: false, | ||
| source: { | ||
| id, | ||
| kind: "working-tree", | ||
| title: id, | ||
| diff: "patch", | ||
| diffHash: id, | ||
| truncated: lazy, | ||
| files: [], | ||
| baseRef: null, | ||
| headRef: null, | ||
| }, | ||
| }; | ||
| } | ||
|
|
||
| describe("review diff prewarming", () => { | ||
| it("skips truncated stat-backed neighbors whose bodies use file queries", () => { | ||
| const sections = [section("selected"), section("lazy", true), section("complete")]; | ||
|
|
||
| expect( | ||
| getReviewDiffPrewarmSections({ | ||
| threadKey: "thread", | ||
| sections, | ||
| selectedSectionId: "selected", | ||
| }).map((item) => item.id), | ||
| ).toEqual(["complete"]); | ||
| }); | ||
|
|
||
| it("does not parse or prepare a lazy source even when invoked directly", () => { | ||
| vi.clearAllMocks(); | ||
|
|
||
| prewarmReviewDiffSection({ threadKey: "thread", section: section("lazy", true) }); | ||
|
|
||
| expect(getCachedReviewParsedDiff).not.toHaveBeenCalled(); | ||
| expect(getCachedNativeReviewDiffData).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it("still prewarms complete section bodies", () => { | ||
| vi.clearAllMocks(); | ||
|
|
||
| prewarmReviewDiffSection({ threadKey: "thread", section: section("complete") }); | ||
|
|
||
| expect(getCachedReviewParsedDiff).toHaveBeenCalledOnce(); | ||
| expect(getCachedNativeReviewDiffData).toHaveBeenCalledOnce(); | ||
| }); | ||
| }); |
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.