Process plugins round-robin in a web worker queue

Speeds it up a lot!
This commit is contained in:
2022-03-03 01:33:36 -05:00
parent 5144f8d6e1
commit 20144ae130
2 changed files with 29 additions and 23 deletions

View File

@@ -1,6 +1,6 @@
import React, { useContext, useEffect, useRef } from "react";
import { WorkerContext } from "../pages/index";
import { WorkersContext } from "../pages/index";
import { useAppSelector, useAppDispatch } from "../lib/hooks";
import {
addPluginInOrder,
@@ -22,12 +22,12 @@ export const excludedPlugins = [
type Props = {};
const DataDirPicker: React.FC<Props> = () => {
const worker = useContext(WorkerContext);
const workers = useContext(WorkersContext);
const dispatch = useAppDispatch();
const plugins = useAppSelector((state) => state.plugins.plugins);
const onDataDirButtonClick = async () => {
if (!worker) {
if (workers.length === 0) {
return alert("Worker not loaded yet");
}
const dirHandle = await (
@@ -53,13 +53,13 @@ const DataDirPicker: React.FC<Props> = () => {
}
dispatch(setPending(plugins.length));
for (const plugin of plugins) {
plugins.forEach(async (plugin, index) => {
const file = await plugin.getFile();
console.log(file.lastModified);
console.log(file.lastModifiedDate);
const contents = new Uint8Array(await file.arrayBuffer());
try {
worker.postMessage(
workers[index % workers.length].postMessage(
{
skipParsing: excludedPlugins.includes(plugin.name),
filename: plugin.name,
@@ -71,7 +71,7 @@ const DataDirPicker: React.FC<Props> = () => {
} catch (error) {
console.error(error);
}
}
});
};
return (
@@ -80,7 +80,7 @@ const DataDirPicker: React.FC<Props> = () => {
To see all of the cell edits and conflicts for your current mod load
order select your <code>Data</code> directory below to load the plugins.
</p>
<button onClick={onDataDirButtonClick} disabled={!worker}>
<button onClick={onDataDirButtonClick} disabled={workers.length === 0}>
{plugins.length === 0 ? "Open" : "Reload"} Skyrim Data directory
</button>
</>