diff --git a/src/mol-util/computation.ts b/src/mol-util/computation.ts index 6bafb7a99b7159cc6fa0edc65554b86ab32e8458..81f92920a3cf9587295c00f107f7ff3e010a20f4 100644 --- a/src/mol-util/computation.ts +++ b/src/mol-util/computation.ts @@ -124,8 +124,6 @@ class ObservableContext implements Computation.Context { private observers: Computation.ProgressObserver[] | undefined = void 0; private progress: Computation.Progress = { message: 'Working...', current: 0, max: 0, elapsedMs: 0, isIndeterminate: true, requestAbort: void 0 }; - lastDelta = 0; - private checkAborted() { if (this.abortRequested) throw Computation.Aborted; } @@ -186,7 +184,6 @@ class ObservableContext implements Computation.Context { } } - this.lastDelta = time - this.lastUpdated; this.lastUpdated = time; return Scheduler.immediatePromise(); @@ -223,11 +220,10 @@ class ChunkerImpl implements Computation.Chunker { private processedSinceUpdate = 0; private updater: Computation.Context['update']; - private computeChunkSize() { - const lastDelta = (this.context as ObservableContext).lastDelta || 0; - if (!lastDelta) return this.nextChunkSize; + private computeChunkSize(delta: number) { + if (!delta) return this.nextChunkSize; const rate = (this.context as ObservableContext).updateRate || DefaulUpdateRateMs; - const ret = Math.round(this.processedSinceUpdate * rate / lastDelta + 1); + const ret = Math.round(this.processedSinceUpdate * rate / delta + 1); this.processedSinceUpdate = 0; return ret; } @@ -246,17 +242,22 @@ class ChunkerImpl implements Computation.Chunker { async process(nextChunk: (size: number) => number, update: (updater: Computation.Context['update']) => Promise<void> | void, nextChunkSize?: number) { if (typeof nextChunkSize !== 'undefined') this.setNextChunkSize(nextChunkSize); + // track time for the actual computation and exclude the "update time" + let chunkStart = Computation.now(); let lastChunkSize: number; while ((lastChunkSize = nextChunk(this.getNextChunkSize())) > 0) { this.processedSinceUpdate += lastChunkSize; if (this.context.requiresUpdate) { + let time = Computation.now(); await update(this.updater); - this.nextChunkSize = this.computeChunkSize(); + this.nextChunkSize = this.computeChunkSize(time - chunkStart); + chunkStart = Computation.now(); } } if (this.context.requiresUpdate) { + let time = Computation.now(); await update(this.updater); - this.nextChunkSize = this.computeChunkSize(); + this.nextChunkSize = this.computeChunkSize(time - chunkStart); } } diff --git a/src/perf-tests/structure.ts b/src/perf-tests/structure.ts index 6fdd03c754e5fbd9a87e892dd9fab97e891b3430..013f08ae0a1642a97a00f4c734034f70d4ade73b 100644 --- a/src/perf-tests/structure.ts +++ b/src/perf-tests/structure.ts @@ -29,6 +29,23 @@ async function readData(path: string) { } } +function *test() { + yield 10; + return 15; +} + +async function runIt<T>(itP: () => IterableIterator<T>) { + const it = itP(); + let lastValue: T | undefined; + while(true) { + const { value, done } = it.next(); + if (done) return value; + lastValue = value; + } +} + +runIt(test).then(r => console.log('rerdasdasda', r)) + export async function readCIF(path: string) { console.time('readData'); const input = await readData(path) diff --git a/src/script.ts b/src/script.ts index 03c5d970ae0e3540eecf67b85967d1af0ecad3fa..03ac84b99889c9eef8fb0bc8283f4d47fe3e9a50 100644 --- a/src/script.ts +++ b/src/script.ts @@ -148,13 +148,14 @@ async function runCIF(input: string | Uint8Array) { export async function _cif() { let path = `./examples/1grm_updated.cif`; // path = '../test/3j3q.cif' // lets have a relative path for big test files + //path = 'e:/test/quick/3j3q_updated.cif'; const input = await readFileAsync(path, 'utf8') console.log('------------------'); console.log('Text CIF:'); runCIF(input); path = `./examples/1cbs_full.bcif`; - // const path = 'c:/test/quick/3j3q.cif'; + const input2 = await readFileAsync(path) console.log('------------------'); console.log('BinaryCIF:');