feat: better code and diff rendering performance

This commit is contained in:
Adam
2025-12-02 06:50:16 -06:00
parent 221bb64aeb
commit c0a35141e6
14 changed files with 225 additions and 100 deletions

View File

@@ -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<T = {}> = FileOptions<T> & {
file: FileContents
@@ -14,10 +30,13 @@ export function Code<T>(props: CodeProps<T>) {
const [local, others] = splitProps(props, ["file", "class", "classList", "annotations"])
createEffect(() => {
const instance = new File<T>({
...createDefaultOptions<T>("unified"),
...others,
})
const instance = new File<T>(
{
...createDefaultOptions<T>("unified"),
...others,
},
workerPool,
)
container.innerHTML = ""
instance.render({