diff --git a/server/ocr/engine.js b/server/ocr/engine.js index d10a5df..e9d3c36 100644 --- a/server/ocr/engine.js +++ b/server/ocr/engine.js @@ -2,6 +2,7 @@ // PaddleOCR's own pre- and post-processing: DB detection, min-area boxes with // unclip, then CTC decoding of each line crop. import { readFileSync } from "node:fs"; +import { availableParallelism } from "node:os"; import { join } from "node:path"; import ort from "onnxruntime-node"; import sharp from "sharp"; @@ -257,6 +258,12 @@ export async function createOcr(modelDir, { detSide = 1600 } = {}) { graphOptimizationLevel: "all", // The arena would keep ~2 GB of detection buffers after the first scan. enableCpuMemArena: false, + // ONNX Runtime splits each step evenly across its threads, so on hybrid + // CPUs every step waits for the slowest efficiency core: an i7-14700K + // took ~7 s per label with its default 20 threads and 1.9 s with 8. + // Idle threads sleep instead of spinning, which was also faster there. + intraOpNumThreads: Math.min(8, availableParallelism()), + extra: { session: { intra_op: { allow_spinning: "0" } } }, }; const [det, rec] = await Promise.all([ ort.InferenceSession.create(