[Performance] Memoize terminal capability check for prompting#7990
[Performance] Memoize terminal capability check for prompting#7990gonzaloriestra wants to merge 2 commits into
Conversation
Memoize the terminalSupportsPrompting function to avoid redundant environment variable lookups and TTY checks. This function checks if the process is running in CI and if both stdin and stdout are TTYs, values that are constant during the process lifetime. Added an exported _resetTerminalSupportsPromptingCache function and corresponding unit tests to verify memoization and cache reset.
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
Memoize the terminalSupportsPrompting function to avoid redundant environment variable lookups and TTY checks. Key changes: - Introduced memoizedTerminalSupportsPrompting variable in `system.ts`. - Updated terminalSupportsPrompting to use the cached value. - Added `_resetTerminalSupportsPromptingCache` for test isolation. - Added unit tests for memoization and reset logic. - Updated `base-command.test.ts` to reset the cache when simulating different TTY/CI environments.
Differences in type declarationsWe detected differences in the type declarations generated by Typescript for this branch compared to the baseline ('main' branch). Please, review them to ensure they are backward-compatible. Here are some important things to keep in mind:
New type declarationsWe found no new type declarations in this PR Existing type declarationspackages/cli-kit/dist/public/node/system.d.ts@@ -99,6 +99,11 @@ export declare function terminalSupportsHyperlinks(): boolean;
* @returns True if the standard input and output streams support prompting.
*/
export declare function terminalSupportsPrompting(): boolean;
+/**
+ * Resets the memoized value for the terminal prompting support check.
+ * This is used for testing purposes.
+ */
+export declare function _resetTerminalSupportsPromptingCache(): void;
/**
* Check if the current environment is a CI environment.
*
|
Memoized the terminalSupportsPrompting function in packages/cli-kit/src/public/node/system.ts using a module-level variable and the nullish coalescing assignment operator (??=). This optimization eliminates redundant calls to isTruthy(process.env.CI) and TTY checks, improving efficiency in high-frequency execution paths.
Key changes:
PR created automatically by Jules for task 5260638415555878059 started by @gonzaloriestra