From c0a35141e6b70eed1a9ba576fe43b7f7d690b968 Mon Sep 17 00:00:00 2001 From: Adam <2363879+adamdotdevin@users.noreply.github.com> Date: Tue, 2 Dec 2025 06:50:16 -0600 Subject: feat: better code and diff rendering performance --- packages/ui/src/components/code.tsx | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) (limited to 'packages/ui/src/components/code.tsx') diff --git a/packages/ui/src/components/code.tsx b/packages/ui/src/components/code.tsx index 788baf549..b4b772816 100644 --- a/packages/ui/src/components/code.tsx +++ b/packages/ui/src/components/code.tsx @@ -1,6 +1,22 @@ import { type FileContents, File, FileOptions, LineAnnotation } from "@pierre/precision-diffs" import { ComponentProps, createEffect, splitProps } from "solid-js" -import { createDefaultOptions, styleVariables } from "./pierre" +import { createDefaultOptions, styleVariables } from "../pierre" +import { getOrCreateWorkerPoolSingleton } from "@pierre/precision-diffs/worker" +import { workerFactory } from "../pierre/worker" + +const workerPool = getOrCreateWorkerPoolSingleton({ + poolOptions: { + workerFactory, + // poolSize defaults to 8. More workers = more parallelism but + // also more memory. Too many can actually slow things down. + // poolSize: 8, + }, + highlighterOptions: { + theme: "OpenCode", + // Optionally preload languages to avoid lazy-loading delays + // langs: ["typescript", "javascript", "css", "html"], + }, +}) export type CodeProps = FileOptions & { file: FileContents @@ -14,10 +30,13 @@ export function Code(props: CodeProps) { const [local, others] = splitProps(props, ["file", "class", "classList", "annotations"]) createEffect(() => { - const instance = new File({ - ...createDefaultOptions("unified"), - ...others, - }) + const instance = new File( + { + ...createDefaultOptions("unified"), + ...others, + }, + workerPool, + ) container.innerHTML = "" instance.render({ -- cgit v1.2.3