Skip to content

Commit

Permalink
Minify worker code and rebuild
Browse files Browse the repository at this point in the history
  • Loading branch information
jlongster committed Aug 4, 2021
1 parent 8e27e3b commit 7fdd0dc
Show file tree
Hide file tree
Showing 22 changed files with 2,893 additions and 205 deletions.
56 changes: 37 additions & 19 deletions dist/indexeddb-backend.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import * as perf from 'perf-deets';

let FINALIZED = 0xdeadbeef;

let WRITEABLE = 0;
Expand Down Expand Up @@ -442,8 +440,6 @@ class File {
return length;
}

perf.record('read');

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

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

perf.endRecording('read');

return length;
}

Expand Down Expand Up @@ -773,19 +767,42 @@ class FileOps {
}
}

function startWorker(argBuffer, resultBuffer) {
function startWorker(reader, writer) {
let onReady;
let workerReady = new Promise(resolve => (onReady = resolve));

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

self.addEventListener('message', e => {
if (e.data.type === '__absurd:worker-ready') {
onReady();
switch (e.data.type) {
case '__absurd:worker-ready':
onReady();
break;

// Normally you would use `postMessage` control the profiler in
// a worker (just like this worker go those events), and the
// perf library automatically handles those events. We don't do
// that for the special backend worker though because it's
// always blocked when it's not processing. Instead we forward
// these events by going through the atomics layer to unblock it
// to make sure it starts immediately
case '__perf-deets:start-profile':
writer.string('profile-start');
writer.finalize();
reader.int32();
reader.done();
break;

case '__perf-deets:end-profile':
writer.string('profile-end');
writer.finalize();
reader.int32();
reader.done();
break;
}
});

Expand All @@ -805,30 +822,31 @@ class IndexedDBBackend {
});

let resultBuffer = new SharedArrayBuffer(4096 * 9);
reader = this.reader = new Reader(resultBuffer, {
reader = new Reader(resultBuffer, {
name: 'results',
debug: false
});

await startWorker(argBuffer, resultBuffer);
await startWorker(reader, writer);
}

createFile(filename) {
return new File(filename, this.defaultBlockSize, new FileOps(filename));
}

// Instead of controlling the profiler from the main thread by
// posting a message to this worker, you can control it inside the
// worker manually with these methods
startProfile() {
perf.start();
this.writer.string('profile-start');
this.writer.finalize();
writer.string('profile-start');
writer.finalize();
reader.int32();
reader.done();
}

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

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 0 additions & 34 deletions dist/indexeddb-main-thread-worker-ef816922.js

This file was deleted.

Loading

0 comments on commit 7fdd0dc

Please sign in to comment.