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
+2 -1
View File
@@ -1,7 +1,6 @@
import { randomUUID } from 'node:crypto'
import { mkdir, readFile, rename, rm, writeFile } from 'node:fs/promises'
import { basename, dirname, extname, join } from 'node:path'
import { createCanvas, loadImage } from '@napi-rs/canvas'
import { documentResultSchema, type DocumentResult } from '../shared/document-result-contracts'
import type { DocumentParsingSettings } from '../shared/document-parsing-contracts'
import type { ParsedDocument } from './knowledge/document-parser'
@@ -96,6 +95,8 @@ export class DocumentResultStorage {
if (!image) throw new Error('解析图片不存在')
const data = await readFile(join(this.require(id).directory, 'images', imageId))
if (thumbnail) {
// Native canvas loads on first use (P6).
const { createCanvas, loadImage } = await import('@napi-rs/canvas')
const source = await loadImage(data)
const scale = Math.min(1, 640 / Math.max(source.width, source.height))
const canvas = createCanvas(Math.max(1, Math.round(source.width * scale)), Math.max(1, Math.round(source.height * scale)))