241a916e03
As stated in #23157, this PR merges all the operations into 1 worker thread (`processBuffer` in `impl.ts`) and only pass a list of operation names and args into the worker. This should improve the speed and memory usage of next/image. Fixes #23157. X-ref: #22925.
25 lines
611 B
TypeScript
25 lines
611 B
TypeScript
import { Worker } from 'jest-worker'
|
|
import * as path from 'path'
|
|
import { execOnce } from '../../../lib/utils'
|
|
import { Operation, Encoding } from './impl'
|
|
|
|
const getWorker = execOnce(
|
|
() =>
|
|
new Worker(path.resolve(__dirname, 'impl'), {
|
|
enableWorkerThreads: true,
|
|
})
|
|
)
|
|
|
|
export { Operation }
|
|
|
|
export async function processBuffer(
|
|
buffer: Buffer,
|
|
operations: Operation[],
|
|
encoding: Encoding,
|
|
quality: number
|
|
): Promise<Buffer> {
|
|
const worker: typeof import('./impl') = getWorker() as any
|
|
return Buffer.from(
|
|
await worker.processBuffer(buffer, operations, encoding, quality)
|
|
)
|
|
}
|