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 6629e4c.
  • Loading branch information
marcustyphoon committed Oct 24, 2024
1 parent 64ae782 commit 7539bd3
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/state/sagas/calculationSaga.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/* eslint-disable no-console */
import { freeze } from '@reduxjs/toolkit';
import { call, put, select, take, takeEvery, takeLatest } from 'typed-redux-saga';
import { next, setup } from '../optimizer/optimizer';
import type { Character } from '../optimizer/optimizerCore';
import { ERROR, RUNNING, STOPPED, SUCCESS, WAITING } from '../optimizer/status';
import type { ExtraFilterMode } from '../slices/controlsSlice';
Expand All @@ -20,6 +19,10 @@ import { getParsedJsHeuristicsTarget } from '../slices/extras';
import type { RootState } from '../store';
import SagaTypes from './sagaTypes';

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

function* runCalc() {
const reduxState: RootState = yield* select();
const state = reduxState.optimizer;
Expand All @@ -46,11 +49,13 @@ function* runCalc() {
let elapsed = 0;
let timer = performance.now();

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

let nextPromise = worker.next();

while (true) {
// eslint-disable-next-line no-loop-func
const result = yield* call(() => next());
const result = yield* call(() => nextPromise);

const { percent, heuristicsPercent, isChanged, list, filteredLists } = result.value;
currentPercent = percent;
Expand All @@ -76,6 +81,9 @@ function* runCalc() {
break;
}

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

yield* put(
updateResults({
list: currentList,
Expand Down

0 comments on commit 7539bd3

Please sign in to comment.