Repository navigation
perf(desktop): low-risk fixes from the canary performance review #9177
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
base: main
Are you sure you want to change the base?
Changes from all commits
9c94bcb
611c90d
b921724
945f835
85ead7b
65e68b7
027cc33
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| import { describe, expect, test } from "bun:test"; | ||
| import { createDownloadProgressMilestones } from "./download-progress-milestones"; | ||
|
|
||
| describe("createDownloadProgressMilestones", () => { | ||
| test("logs once per crossed milestone", () => { | ||
| const milestones = createDownloadProgressMilestones(); | ||
| const logged = [1, 24.9, 25, 30, 49, 80, 99, 100, 100].filter((percent) => | ||
| milestones.shouldLog(percent), | ||
| ); | ||
| expect(logged).toEqual([25, 80, 100]); | ||
| }); | ||
|
|
||
| test("starts again after reset", () => { | ||
| const milestones = createDownloadProgressMilestones(); | ||
| expect(milestones.shouldLog(100)).toBe(true); | ||
| expect(milestones.shouldLog(100)).toBe(false); | ||
| milestones.reset(); | ||
| expect(milestones.shouldLog(26)).toBe(true); | ||
| }); | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| const MILESTONES = [25, 50, 75, 100]; | ||
|
|
||
| export function createDownloadProgressMilestones() { | ||
| let nextIndex = 0; | ||
|
|
||
| return { | ||
| shouldLog(percent: number): boolean { | ||
| let crossed = false; | ||
| while ( | ||
| nextIndex < MILESTONES.length && | ||
| percent >= MILESTONES[nextIndex] | ||
| ) { | ||
| nextIndex++; | ||
| crossed = true; | ||
| } | ||
| return crossed; | ||
| }, | ||
| reset(): void { | ||
| nextIndex = 0; | ||
| }, | ||
| }; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,6 +13,7 @@ import { | |
| augmentPathForMacOS, | ||
| buildMinimalEnv, | ||
| clearStrictShellEnvCache, | ||
| createShellEnvCache, | ||
| getStrictShellEnvironment, | ||
| parseEnvOutput, | ||
| } from "./clean-shell-env.ts"; | ||
|
|
@@ -92,6 +93,52 @@ describe("augmentPathForMacOS", () => { | |
| }); | ||
| }); | ||
|
|
||
| describe("createShellEnvCache", () => { | ||
| test("concurrent callers share one spawn and each get a copy", async () => { | ||
| let spawns = 0; | ||
| const cache = createShellEnvCache(async () => { | ||
| spawns++; | ||
| return { HOME: "/x" }; | ||
| }); | ||
| const [a, b] = await Promise.all([cache.get(), cache.get()]); | ||
|
Comment on lines
+96
to
+103
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The new Add tests that start a request, clear the cache, start another request, and then resolve or reject the old request. Assert that the old request neither fills the cache nor clears the newer request. Prompt To Fix With AIThis is a comment left during a code review.
Path: packages/host-service/src/terminal/clean-shell-env.test.ts
Line: 96-103
Comment:
**Cache clearing lacks tests**
The new `createShellEnvCache` tests never call `clear()`. They do not protect the checks that keep an old shell request from replacing a newer result or clearing a newer pending request.
Add tests that start a request, clear the cache, start another request, and then resolve or reject the old request. Assert that the old request neither fills the cache nor clears the newer request.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time! |
||
| expect(spawns).toBe(1); | ||
| expect(a).toEqual({ HOME: "/x" }); | ||
| expect(a).not.toBe(b); | ||
| }); | ||
|
|
||
| test("does not cache a failed spawn", async () => { | ||
| let spawns = 0; | ||
| const cache = createShellEnvCache(async () => { | ||
| spawns++; | ||
| if (spawns === 1) throw new Error("boom"); | ||
| return { HOME: "/x" }; | ||
| }); | ||
| await expect(cache.get()).rejects.toThrow("boom"); | ||
| expect(await cache.get()).toEqual({ HOME: "/x" }); | ||
| expect(spawns).toBe(2); | ||
| }); | ||
|
|
||
| test("spawns again after the TTL", async () => { | ||
| let spawns = 0; | ||
| let time = 0; | ||
| const cache = createShellEnvCache( | ||
| async () => { | ||
| spawns++; | ||
| return { HOME: "/x" }; | ||
| }, | ||
| () => time, | ||
| 1_000, | ||
| ); | ||
| await cache.get(); | ||
| time = 999; | ||
| await cache.get(); | ||
| expect(spawns).toBe(1); | ||
| time = 1_000; | ||
| await cache.get(); | ||
| expect(spawns).toBe(2); | ||
| }); | ||
| }); | ||
|
|
||
| const DELIMITER = "__SUPERSET_SHELL_ENV__"; | ||
|
|
||
| function withDelimiters(body: string): string { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Script executed:
Repository: ParadevAI/Paradev
Length of output: 1436
Script executed:
Repository: ParadevAI/Paradev
Length of output: 45663
Script executed:
Repository: ParadevAI/Paradev
Length of output: 41811
Apply the image limits to the wrapper-terminal path.
createTerminalInWrapperconstructsnew ImageAddon()without options. The shipped terminal lifecycle calls this path throughv1TerminalCache.getOrCreate, so v1 terminals can bypass the new image limits.Suggested fix