perf(startup): load canvas, node-pty, ssh2, html-to-text and the OpenCode SDK on first use

Main module evaluation drops from ~420 ms to ~330 ms. Types stay as import type; the DeepSeek Harness chunks stay static because the protocol chunk shares code with Main startup paths.
This commit is contained in:
mesalogo
2026-10-03 17:15:13 +08:00
parent 68cc0792e1
commit 010aafb6f4
12 changed files with 104 additions and 26 deletions
+3 -3
View File
@@ -1,7 +1,7 @@
import { createHmac, getCiphers, randomBytes } from "node:crypto";
import { connect as connectLoopback, type Socket } from "node:net";
import { Client } from "ssh2";
import type { ClientChannel, ConnectConfig, SFTPWrapper } from "ssh2";
import type { Client, ClientChannel, ConnectConfig, SFTPWrapper } from "ssh2";
import { loadSsh2 } from "./ssh2-module";
import {
BoundedStagedSftp,
type BoundedSftpLimits,
@@ -344,7 +344,7 @@ export class Ssh2AuthenticatedConnection implements AuthenticatedSshConnection {
validatePoolTarget(target);
validateConnectionIdentity(target, identity);
const resolvedDependencies: SshConnectionDependencies = {
createClient: () => new Client(),
createClient: () => new (loadSsh2().Client)(),
supportedOpenSslCiphers: getCiphers,
systemAgent: defaultSystemAgent,
controlPlanePackageInstaller: Buffer.alloc(0),
+7 -6
View File
@@ -1,11 +1,12 @@
import { createHash, getCiphers } from 'node:crypto'
import {
import type {
Client,
type Algorithms,
type CipherAlgorithm,
type ConnectConfig,
type ServerHostKeyAlgorithm
Algorithms,
CipherAlgorithm,
ConnectConfig,
ServerHostKeyAlgorithm
} from 'ssh2'
import { loadSsh2 } from './ssh2-module'
import type {
SshHostConnectionTestResult
} from '../../shared/ssh-host-contracts'
@@ -336,7 +337,7 @@ export class Ssh2Transport implements SshTransport {
dependencies: Partial<SshTransportDependencies> = {}
) {
this.dependencies = {
createClient: () => new Client(),
createClient: () => new (loadSsh2().Client)(),
now: Date.now,
supportedOpenSslCiphers: getCiphers,
systemAgent: defaultSystemAgent,
+8
View File
@@ -0,0 +1,8 @@
import { createLazyRequire } from '../lazy-require'
/**
* Loads ssh2 on the first SSH connection instead of at Main startup (P6):
* evaluating it costs ~65 ms and most sessions never open a remote host.
* Synchronous so existing client factories keep their signatures.
*/
export const loadSsh2 = createLazyRequire<typeof import('ssh2')>('ssh2')