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
+5 -2
View File
@@ -1,4 +1,4 @@
import { createCanvas } from '@napi-rs/canvas'
// @napi-rs/canvas is a native module (~85 ms to load); load it on first OCR render (P6).
export async function* renderOcrPdf(
buffer: Buffer,
@@ -6,7 +6,10 @@ export async function* renderOcrPdf(
signal?: AbortSignal
): AsyncGenerator<{ pageNumber: number; data: Buffer; width: number; height: number }> {
signal?.throwIfAborted()
const { getDocument } = await import('pdfjs-dist/legacy/build/pdf.mjs')
const [{ getDocument }, { createCanvas }] = await Promise.all([
import('pdfjs-dist/legacy/build/pdf.mjs'),
import('@napi-rs/canvas')
])
const task = getDocument({
data: Uint8Array.from(buffer), disableFontFace: true,
isOffscreenCanvasSupported: false, useSystemFonts: false, useWorkerFetch: false