Skip to content

Commit

Permalink
Revert "run optimizer.ts (coordinator) on main thread"
Browse files Browse the repository at this point in the history
This reverts commit 146d220.
  • Loading branch information
marcustyphoon committed Oct 25, 2024
1 parent 2268285 commit 89e51e3
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/state/async/calculationThunks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
/* eslint-disable no-await-in-loop */
/* eslint-disable no-console */
import { freeze } from '@reduxjs/toolkit';
import { next, setup } from '../optimizer/optimizer';
import type { Character } from '../optimizer/optimizerCore';
import { ERROR, RUNNING, STOPPED, SUCCESS, WAITING } from '../optimizer/status';
import type { AppThunk } from '../redux-hooks';
Expand All @@ -22,6 +21,10 @@ import { getParsedJsHeuristicsTarget } from '../slices/extras';

let resume: (() => void) | undefined;

const worker = new ComlinkWorker<typeof import('../optimizer/optimizer')>(
new URL('../optimizer/optimizer.ts', import.meta.url),
);

export const startCalc: AppThunk = async (dispatch, getState) => {
const reduxState = getState();

Expand Down Expand Up @@ -51,11 +54,13 @@ export const startCalc: AppThunk = async (dispatch, getState) => {
let elapsed = 0;
let timer = performance.now();

await setup(reduxState, jsHeuristicsEnabled, jsHeuristicsTarget, threads);
await worker.setup(reduxState, jsHeuristicsEnabled, jsHeuristicsTarget, threads);

let nextPromise = worker.next();

// eslint-disable-next-line no-constant-condition
while (true) {
const result = await next();
const result = await nextPromise;

const { percent, heuristicsPercent, isChanged, list, filteredLists } = result.value;
currentPercent = percent;
Expand All @@ -81,6 +86,9 @@ export const startCalc: AppThunk = async (dispatch, getState) => {
break;
}

// concurrency: send next request to worker thread before rendering current on main thread
nextPromise = worker.next();

dispatch(
updateResults({
list: currentList,
Expand Down

0 comments on commit 89e51e3

Please sign in to comment.