Skip to content

Commit

Permalink
Lots of refactoring and cleanup, especially with how workers are managed
Browse files Browse the repository at this point in the history
  • Loading branch information
jlongster committed Aug 4, 2021
1 parent 50e8833 commit 8e27e3b
Show file tree
Hide file tree
Showing 22 changed files with 1,124 additions and 8,736 deletions.
49 changes: 10 additions & 39 deletions dist/indexeddb-backend.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import * as perf from 'perf-deets';

let FINALIZED = 0xdeadbeef;

let WRITEABLE = 0;
Expand Down Expand Up @@ -259,9 +261,6 @@ class Writer {
}
}

// Noops in prod
async function end() {}

function range(start, end, step) {
let r = [];
for (let i = start; i <= end; i += step) {
Expand Down Expand Up @@ -443,6 +442,8 @@ class File {
return length;
}

perf.record('read');

position = Math.max(position, 0);
let dataLength = Math.min(length, this.meta.size - position);

Expand All @@ -465,6 +466,8 @@ class File {
view[offset + i] = 0;
}

perf.endRecording('read');

return length;
}

Expand Down Expand Up @@ -586,15 +589,6 @@ class File {
getattr() {
return this.meta;
}

startStats() {
this.ops.startStats();
}

stats() {
end();
this.ops.stats();
}
}

// These are temporarily global, but will be easy to clean up later
Expand All @@ -608,22 +602,6 @@ function positionToKey(pos, blockSize) {

function invokeWorker(method, args) {
switch (method) {
case 'stats-start': {
writer.string('stats-start');
writer.finalize();
reader.int32();
reader.done();
break;
}

case 'stats': {
writer.string('stats');
writer.finalize();
reader.int32();
reader.done();
break;
}

case 'readBlocks': {
let { name, positions, blockSize } = args;

Expand Down Expand Up @@ -737,14 +715,6 @@ class FileOps {
this.filename = filename;
}

startStats() {
return invokeWorker('stats-start');
}

stats() {
return invokeWorker('stats');
}

getStoreName() {
return this.filename.replace(/\//g, '-');
}
Expand Down Expand Up @@ -808,13 +778,13 @@ function startWorker(argBuffer, resultBuffer) {
let workerReady = new Promise(resolve => (onReady = resolve));

self.postMessage({
type: 'spawn-idb-worker',
type: '__absurd:spawn-idb-worker',
argBuffer,
resultBuffer
});

self.addEventListener('message', e => {
if (e.data.type === 'worker-ready') {
if (e.data.type === '__absurd:worker-ready') {
onReady();
}
});
Expand Down Expand Up @@ -848,14 +818,15 @@ class IndexedDBBackend {
}

startProfile() {
perf.start();
this.writer.string('profile-start');
this.writer.finalize();
reader.int32();
reader.done();
}

stopProfile() {
end();
perf.end();
this.writer.string('profile-end');
this.writer.finalize();
reader.int32();
Expand Down
34 changes: 34 additions & 0 deletions dist/indexeddb-main-thread-worker-ef816922.js

Large diffs are not rendered by default.

88 changes: 27 additions & 61 deletions dist/indexeddb-main-thread.js

Large diffs are not rendered by default.

16 changes: 5 additions & 11 deletions dist/memory-backend.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// Noops in prod
async function end() {}
import * as perf from 'perf-deets';

function range(start, end, step) {
let r = [];
Expand Down Expand Up @@ -182,6 +181,8 @@ class File {
return length;
}

perf.record('read');

position = Math.max(position, 0);
let dataLength = Math.min(length, this.meta.size - position);

Expand All @@ -204,6 +205,8 @@ class File {
view[offset + i] = 0;
}

perf.endRecording('read');

return length;
}

Expand Down Expand Up @@ -325,15 +328,6 @@ class File {
getattr() {
return this.meta;
}

startStats() {
this.ops.startStats();
}

stats() {
end();
this.ops.stats();
}
}

class FileOps {
Expand Down
194 changes: 0 additions & 194 deletions dist/perf/index.js

This file was deleted.

Loading

0 comments on commit 8e27e3b

Please sign in to comment.