mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-05-13 05:12:55 -07:00
perf(cli): parallelize and background startup cleanup tasks (#23545)
This commit is contained in:
+31
-15
@@ -213,12 +213,36 @@ export async function main() {
|
|||||||
loadSettingsHandle?.end();
|
loadSettingsHandle?.end();
|
||||||
|
|
||||||
// If a worktree is requested and enabled, set it up early.
|
// If a worktree is requested and enabled, set it up early.
|
||||||
|
// This must be awaited before any other async tasks that depend on CWD (like loadCliConfig)
|
||||||
|
// because setupWorktree calls process.chdir().
|
||||||
const requestedWorktree = cliConfig.getRequestedWorktreeName(settings);
|
const requestedWorktree = cliConfig.getRequestedWorktreeName(settings);
|
||||||
let worktreeInfo: WorktreeInfo | undefined;
|
let worktreeInfo: WorktreeInfo | undefined;
|
||||||
if (requestedWorktree !== undefined) {
|
if (requestedWorktree !== undefined) {
|
||||||
|
const worktreeHandle = startupProfiler.start('setup_worktree');
|
||||||
worktreeInfo = await setupWorktree(requestedWorktree || undefined);
|
worktreeInfo = await setupWorktree(requestedWorktree || undefined);
|
||||||
|
worktreeHandle?.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const cleanupOpsHandle = startupProfiler.start('cleanup_ops');
|
||||||
|
Promise.all([
|
||||||
|
cleanupCheckpoints(),
|
||||||
|
cleanupToolOutputFiles(settings.merged),
|
||||||
|
cleanupBackgroundLogs(),
|
||||||
|
])
|
||||||
|
.catch((e) => {
|
||||||
|
debugLogger.error('Early cleanup failed:', e);
|
||||||
|
})
|
||||||
|
.finally(() => {
|
||||||
|
cleanupOpsHandle?.end();
|
||||||
|
});
|
||||||
|
|
||||||
|
const parseArgsHandle = startupProfiler.start('parse_arguments');
|
||||||
|
const argvPromise = parseArguments(settings.merged).finally(() => {
|
||||||
|
parseArgsHandle?.end();
|
||||||
|
});
|
||||||
|
|
||||||
|
const rawStartupWarningsPromise = getStartupWarnings();
|
||||||
|
|
||||||
// Report settings errors once during startup
|
// Report settings errors once during startup
|
||||||
settings.errors.forEach((error) => {
|
settings.errors.forEach((error) => {
|
||||||
coreEvents.emitFeedback('warning', error.message);
|
coreEvents.emitFeedback('warning', error.message);
|
||||||
@@ -232,15 +256,7 @@ export async function main() {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
await Promise.all([
|
const argv = await argvPromise;
|
||||||
cleanupCheckpoints(),
|
|
||||||
cleanupToolOutputFiles(settings.merged),
|
|
||||||
cleanupBackgroundLogs(),
|
|
||||||
]);
|
|
||||||
|
|
||||||
const parseArgsHandle = startupProfiler.start('parse_arguments');
|
|
||||||
const argv = await parseArguments(settings.merged);
|
|
||||||
parseArgsHandle?.end();
|
|
||||||
|
|
||||||
if (
|
if (
|
||||||
(argv.allowedTools && argv.allowedTools.length > 0) ||
|
(argv.allowedTools && argv.allowedTools.length > 0) ||
|
||||||
@@ -467,12 +483,10 @@ export async function main() {
|
|||||||
await config.getHookSystem()?.fireSessionEndEvent(SessionEndReason.Exit);
|
await config.getHookSystem()?.fireSessionEndEvent(SessionEndReason.Exit);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Cleanup sessions after config initialization
|
// Launch cleanup expired sessions as a background task
|
||||||
try {
|
cleanupExpiredSessions(config, settings.merged).catch((e) => {
|
||||||
await cleanupExpiredSessions(config, settings.merged);
|
|
||||||
} catch (e) {
|
|
||||||
debugLogger.error('Failed to cleanup expired sessions:', e);
|
debugLogger.error('Failed to cleanup expired sessions:', e);
|
||||||
}
|
});
|
||||||
|
|
||||||
if (config.getListExtensions()) {
|
if (config.getListExtensions()) {
|
||||||
debugLogger.log('Installed extensions:');
|
debugLogger.log('Installed extensions:');
|
||||||
@@ -524,7 +538,9 @@ export async function main() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const terminalHandle = startupProfiler.start('setup_terminal');
|
||||||
await setupTerminalAndTheme(config, settings);
|
await setupTerminalAndTheme(config, settings);
|
||||||
|
terminalHandle?.end();
|
||||||
|
|
||||||
const initAppHandle = startupProfiler.start('initialize_app');
|
const initAppHandle = startupProfiler.start('initialize_app');
|
||||||
const initializationResult = await initializeApp(config, settings);
|
const initializationResult = await initializeApp(config, settings);
|
||||||
@@ -548,7 +564,7 @@ export async function main() {
|
|||||||
isAlternateBufferEnabled(config),
|
isAlternateBufferEnabled(config),
|
||||||
config.getScreenReader(),
|
config.getScreenReader(),
|
||||||
);
|
);
|
||||||
const rawStartupWarnings = await getStartupWarnings();
|
const rawStartupWarnings = await rawStartupWarningsPromise;
|
||||||
const startupWarnings: StartupWarning[] = [
|
const startupWarnings: StartupWarning[] = [
|
||||||
...rawStartupWarnings.map((message) => ({
|
...rawStartupWarnings.map((message) => ({
|
||||||
id: `startup-${createHash('sha256').update(message).digest('hex').substring(0, 16)}`,
|
id: `startup-${createHash('sha256').update(message).digest('hex').substring(0, 16)}`,
|
||||||
|
|||||||
Reference in New Issue
Block a user