Skip to content
Snippets Groups Projects
Commit f9154ab4 authored by David Sehnal's avatar David Sehnal
Browse files

more chunker updates

parent 9890d480
No related branches found
No related tags found
No related merge requests found
...@@ -221,7 +221,10 @@ class ChunkerImpl implements Computation.Chunker { ...@@ -221,7 +221,10 @@ class ChunkerImpl implements Computation.Chunker {
private updater: Computation.Context['update']; private updater: Computation.Context['update'];
private computeChunkSize(delta: number) { private computeChunkSize(delta: number) {
if (!delta) return this.nextChunkSize; if (!delta) {
this.processedSinceUpdate = 0;
return this.nextChunkSize;
}
const rate = (this.context as ObservableContext).updateRate || DefaulUpdateRateMs; const rate = (this.context as ObservableContext).updateRate || DefaulUpdateRateMs;
const ret = Math.round(this.processedSinceUpdate * rate / delta + 1); const ret = Math.round(this.processedSinceUpdate * rate / delta + 1);
this.processedSinceUpdate = 0; this.processedSinceUpdate = 0;
...@@ -241,23 +244,34 @@ class ChunkerImpl implements Computation.Chunker { ...@@ -241,23 +244,34 @@ class ChunkerImpl implements Computation.Chunker {
async process(nextChunk: (size: number) => number, update: (updater: Computation.Context['update']) => Promise<void> | void, nextChunkSize?: number) { async process(nextChunk: (size: number) => number, update: (updater: Computation.Context['update']) => Promise<void> | void, nextChunkSize?: number) {
if (typeof nextChunkSize !== 'undefined') this.setNextChunkSize(nextChunkSize); if (typeof nextChunkSize !== 'undefined') this.setNextChunkSize(nextChunkSize);
this.processedSinceUpdate = 0;
// track time for the actual computation and exclude the "update time" // track time for the actual computation and exclude the "update time"
let chunkStart = Computation.now(); let chunkStart = Computation.now();
let lastChunkSize: number; let lastChunkSize: number;
let chunkCount = 0;
let totalSize = 0;
let updateCount = 0;
while ((lastChunkSize = nextChunk(this.getNextChunkSize())) > 0) { while ((lastChunkSize = nextChunk(this.getNextChunkSize())) > 0) {
chunkCount++;
this.processedSinceUpdate += lastChunkSize; this.processedSinceUpdate += lastChunkSize;
totalSize += lastChunkSize;
if (this.context.requiresUpdate) { if (this.context.requiresUpdate) {
let time = Computation.now(); let time = Computation.now();
await update(this.updater); await update(this.updater);
this.nextChunkSize = this.computeChunkSize(time - chunkStart); this.nextChunkSize = updateCount > 0
? Math.round((totalSize + this.computeChunkSize(time - chunkStart)) / (chunkCount + 1))
: this.computeChunkSize(time - chunkStart)
updateCount++;
chunkStart = Computation.now(); chunkStart = Computation.now();
} }
} }
if (this.context.requiresUpdate) { if (this.context.requiresUpdate) {
let time = Computation.now(); let time = Computation.now();
await update(this.updater); await update(this.updater);
this.nextChunkSize = this.computeChunkSize(time - chunkStart); this.nextChunkSize = updateCount > 0
? Math.round((totalSize + this.computeChunkSize(time - chunkStart)) / (chunkCount + 1))
: this.computeChunkSize(time - chunkStart)
} }
} }
......
...@@ -148,7 +148,7 @@ async function runCIF(input: string | Uint8Array) { ...@@ -148,7 +148,7 @@ async function runCIF(input: string | Uint8Array) {
export async function _cif() { export async function _cif() {
let path = `./examples/1grm_updated.cif`; let path = `./examples/1grm_updated.cif`;
// path = '../test/3j3q.cif' // lets have a relative path for big test files // path = '../test/3j3q.cif' // lets have a relative path for big test files
//path = 'e:/test/quick/3j3q_updated.cif'; // path = 'e:/test/quick/3j3q_updated.cif';
const input = await readFileAsync(path, 'utf8') const input = await readFileAsync(path, 'utf8')
console.log('------------------'); console.log('------------------');
console.log('Text CIF:'); console.log('Text CIF:');
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment