Added fine-grain timing for aspects of the bake. Improved efficiency of autobakes and moved output decoding into a worker.

This commit is contained in:
n1474335 2023-02-03 14:55:15 +00:00
parent 84f0750525
commit 0b2cb7e68c
9 changed files with 287 additions and 57 deletions

View file

@ -7,6 +7,8 @@
*/
import Dish from "../../core/Dish.mjs";
import Utils from "../../core/Utils.mjs";
import cptable from "codepage";
import loglevelMessagePrefix from "loglevel-message-prefix";
loglevelMessagePrefix(log, {
@ -26,6 +28,9 @@ self.addEventListener("message", function(e) {
case "getDishTitle":
getDishTitle(r.data);
break;
case "bufferToStr":
bufferToStr(r.data);
break;
case "setLogLevel":
log.setLevel(r.data, false);
break;
@ -76,3 +81,32 @@ async function getDishTitle(data) {
}
});
}
/**
* Translates a buffer to a string using a specified encoding
*
* @param {object} data
* @param {ArrayBuffer} data.buffer
* @param {number} data.id
* @param {number} data.encoding
*/
async function bufferToStr(data) {
let str;
if (data.encoding === 0) {
str = Utils.arrayBufferToStr(data.buffer);
} else {
try {
str = cptable.utils.decode(data.encoding, new Uint8Array(data.buffer));
} catch (err) {
str = err;
}
}
self.postMessage({
action: "dishReturned",
data: {
value: str,
id: data.id
}
});
}

View file

@ -174,7 +174,7 @@ self.autoBake = function(inputNum, progress, step=false) {
const input = self.inputs[inputNum];
if (input) {
self.postMessage({
action: "bakeAllInputs",
action: "bakeInputs",
data: {
nums: [parseInt(inputNum, 10)],
step: step,
@ -196,7 +196,7 @@ self.bakeAllInputs = function() {
.map(n => parseInt(n, 10));
self.postMessage({
action: "bakeAllInputs",
action: "bakeInputs",
data: {
nums: nums,
step: false,