Skip to content

Commit

Permalink
Limit firefox workers to 2
Browse files Browse the repository at this point in the history
  • Loading branch information
pkong-ds committed Aug 28, 2024
1 parent 68631fb commit d3e784f
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions public/scripts/upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ async function runWorker(worker) {
);
}

const MAX_FIREFOX_WEB_WORKERS = 2
function isUserAgentFirefox() {
return navigator.userAgent.match(/firefox|fxios/i)
}

function runPreviewWorker(worker, imageUpload) {
const imageUploadFile = imageUpload.file;
worker.worker.postMessage({
Expand Down Expand Up @@ -211,7 +216,7 @@ class RootViewModel {
_isGeneratingMockup = false;
worker = new Worker("/scripts/web_worker.js");
workerPool = [];
maxWorkers = 4;
maxWorkers = 0;
selectedColorId = null;
selectedPreviewImageULID = null;

Expand All @@ -228,7 +233,8 @@ class RootViewModel {
this.selectedColorId = selectedColorId;
this.maxMockupWaitSec = maxMockupWaitSec;
this.fileList = fileListViewModel;
this.maxWorkers = navigator.hardwareConcurrency || 4;

this.maxWorkers = isUserAgentFirefox() ? MAX_FIREFOX_WEB_WORKERS : navigator.hardwareConcurrency;

// Reserve one worker to generate the final mockup, will update later
for (let i = 0; i < this.maxWorkers - 1; i += 1) {
Expand Down

0 comments on commit d3e784f

Please sign in to comment.