Minor edits to reduce memory use (#815)

master
Balearica 1 year ago committed by GitHub
parent 2c2e014ea9
commit 79cacaab95
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 15
      src/worker-script/index.js

@ -120,7 +120,7 @@ res) => {
if (!resp.ok) {
throw Error(`Network error while fetching ${fetchUrl}. Response code: ${resp.status}`);
}
data = await resp.arrayBuffer();
data = new Uint8Array(await resp.arrayBuffer());
// langPath is a local file, read .traineddata from local filesystem
// (adapter.readCache is a generic file read function in Node.js version)
@ -132,8 +132,6 @@ res) => {
}
}
data = new Uint8Array(data);
// Check for gzip magic numbers (1F and 8B in hex)
const isGzip = (data[0] === 31 && data[1] === 139) || (data[1] === 31 && data[0] === 139);
@ -160,8 +158,7 @@ res) => {
log(err.toString());
}
}
return Promise.resolve(data);
return Promise.resolve();
};
res.progress({ workerId, status: 'loading language traineddata', progress: 0 });
@ -445,8 +442,14 @@ const terminate = async (_, res) => {
*/
exports.dispatchHandlers = (packet, send) => {
const res = (status, data) => {
// Return only the necessary info to avoid sending unnecessarily large messages
const packetRes = {
jobId: packet.jobId,
workerId: packet.workerId,
action: packet.action,
};
send({
...packet,
...packetRes,
status,
data,
});

Loading…
Cancel
Save