Skip to content

Commit 2f4fea4

Browse files
committed
limit workers to 6 concurrent instances
1 parent 44a93b4 commit 2f4fea4

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/components/ControlButtons.vue

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ const uncompressedFiles = computed(() => files.value.filter(getUncompressedFiles
2121
const anyUncompressed = computed(() => Boolean(uncompressedFiles.value.length));
2222
const toCompress = ref<FileObj[]>([]);
2323
24+
// limit to 6 concurrent workers in order to work around a bug in Firefox: https://bugzilla.mozilla.org/show_bug.cgi?id=1885198
25+
const workerLimit = 6;
2426
const availableThreads = Math.max(navigator.hardwareConcurrency - 2, 1);
27+
const workerThreadAmount = Math.min(workerLimit, availableThreads);
2528
2629
async function editFileObj(fileObj: FileObj) {
2730
try {
@@ -37,7 +40,7 @@ async function editFileObj(fileObj: FileObj) {
3740
// add files to toCompress array when a thread is available
3841
watchEffect(() => {
3942
if (isCompressing.value) {
40-
const amountToPush = availableThreads - toCompress.value.filter(getUncompressedFiles).length;
43+
const amountToPush = workerThreadAmount - toCompress.value.filter(getUncompressedFiles).length;
4144
const pool = uncompressedFiles.value.filter((item) => !toCompress.value.includes(item)).slice(0, amountToPush);
4245
if (pool.length) toCompress.value = [...toCompress.value, ...pool];
4346
}

0 commit comments

Comments
 (0)