27 lines
812 B
TypeScript
27 lines
812 B
TypeScript
import { WorkerPoolContextProvider } from "@pierre/diffs/react";
|
|
import DiffsWorker from "@pierre/diffs/worker/worker.js?worker";
|
|
import { useMemo, type ReactNode } from "react";
|
|
|
|
export function DiffWorkerPoolProvider({ children }: { children?: ReactNode }) {
|
|
const workerPoolSize = useMemo(() => {
|
|
const cores =
|
|
typeof navigator === "undefined" ? 4 : Math.max(1, navigator.hardwareConcurrency || 4);
|
|
return Math.max(2, Math.min(6, Math.floor(cores / 2)));
|
|
}, []);
|
|
|
|
return (
|
|
<WorkerPoolContextProvider
|
|
poolOptions={{
|
|
workerFactory: () => new DiffsWorker(),
|
|
poolSize: workerPoolSize,
|
|
totalASTLRUCacheSize: 240,
|
|
}}
|
|
highlighterOptions={{
|
|
tokenizeMaxLineLength: 1_000,
|
|
}}
|
|
>
|
|
{children}
|
|
</WorkerPoolContextProvider>
|
|
);
|
|
}
|