Skip to content

Commit beb9fd9

Browse files
committed
feat: pre-warm environment manager caches during activation and background refresh
1 parent 8e3904b commit beb9fd9

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/extension.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
window,
1111
} from 'vscode';
1212
import { PythonEnvironment, PythonEnvironmentApi, PythonProjectCreator } from './api';
13-
import { ENVS_EXTENSION_ID } from './common/constants';
13+
import { ENVS_EXTENSION_ID, SYSTEM_MANAGER_ID, VENV_MANAGER_ID } from './common/constants';
1414
import { ensureCorrectVersion } from './common/extVersion';
1515
import { registerLogger, traceError, traceInfo, traceWarn } from './common/logging';
1616
import { clearPersistentState, setPersistentState } from './common/persistentState';
@@ -547,6 +547,18 @@ export async function activate(context: ExtensionContext): Promise<PythonEnviron
547547
safeRegister('shellStartupVars', shellStartupVarsMgr.initialize()),
548548
]);
549549

550+
// Pre-warm system and venv manager caches before initial environment selection.
551+
await Promise.all([
552+
envManagers
553+
.getEnvironmentManager(SYSTEM_MANAGER_ID)
554+
?.getEnvironments('all')
555+
.catch(() => {}),
556+
envManagers
557+
.getEnvironmentManager(VENV_MANAGER_ID)
558+
?.getEnvironments('all')
559+
.catch(() => {}),
560+
]);
561+
550562
await applyInitialEnvironmentSelection(envManagers, projectManager, nativeFinder, api);
551563

552564
// Register manager-agnostic terminal watcher for package-modifying commands

src/managers/common/nativePythonFinder.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,11 @@ class NativePythonFinderImpl implements NativePythonFinder {
238238
1,
239239
'NativeRefresh-task',
240240
);
241+
242+
// Start discovery immediately so the cache is warm before managers call initialize().
243+
void this.refresh(false).catch((err) => {
244+
traceWarn('[pet] Background pre-warm refresh failed:', err);
245+
});
241246
}
242247

243248
public async resolve(executable: string): Promise<NativeEnvInfo> {

0 commit comments

Comments
 (0)