在处理 BMP 图像时,`setImage.js` 中出现严重的内存峰值和 CPU 冻结

作者: codeCraft-Ritik创建于 2026年9月13日更新于 2026年9月13日

const size = 5 * 1024 * 1024; // 5MB BMP image const image = new Uint8Array(size);

console.time('Current Implementation'); const keys = Object.keys(image).length; const bufCurrent = Buffer.from(Array.from({ ...image, length: keys })); console.timeEnd('Current Implementation');

console.time('Proposed Zero-Copy Implementation'); const bufProposed = Buffer.from(image.buffer, image.byteOffset, image.byteLength); console.timeEnd('Proposed Zero-Copy Implementation');

内容来源: naptha/tesseract.js