-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Discussion] tinylibs/tinylet or jimmywarting/await-sync? #4
Comments
This comment was marked as off-topic.
This comment was marked as off-topic.
Competition and Collaboration would always be the case. I'd like to have you and your package in tinylibs and at the same time compete and collaborate with other similar packages! So please continue you amazing work since I believe this is a neat idea and a neat API you're developing for tinylibs. |
If you want to contribute and ship the missing equivalent whatever you decide to do is up to you... |
Yeah, I originally wanted to do that, but I realized it could "specialize" the function for Node.js to hopefully avoid paying shim perf price. I figured the specialized implementation was worth it in this case, as long as it achieves rough feature-parity with the non-Node.js impl that needs JSON-like serialization (it doesn't YET; I still need to buff up that JSON-like serialization) |
As for benchmarks, here's what I got: From this code: https://github.com/tinylibs/tinylet/blob/83eee3371feef310a1ec13b20bb0ed299d78c063/test/redlet-node.bench.js I note that there might be something I'm missing with the "await-sync: create + invoke worker" one. I don't know if I'm using the library wrong or what 😵 2 ops/sec doesn't sound right
|
General comments on the benchmarking stuff though is that redlet() seems WAYYYYY faster. Here's a comparison chart that I collected from ☝☝ bench results: code excerpt for your reading pleasurebench.add("redlet: create only", () => {
redlet(() => {});
});
bench.add("await-sync: create only", () => {
awaitSync(() => new Uint8Array(1));
});
bench.add("redlet: create + invoke worker", () => {
const f = redlet(() => {});
f();
});
bench.add("await-sync: create + invoke worker", () => {
const f = awaitSync(() => new Uint8Array(1));
f();
});
{
const f = redlet(() => {});
bench.add("redlet: invoke worker only", () => {
f();
});
}
{
const f = awaitSync(() => new Uint8Array(1));
bench.add("await-sync: invoke worker only", () => {
f();
});
}
REMEMBER THAT THIS IS JUST RAW |
I included the tinylet into my own benchmark code... import { readFileSync } from 'node:fs'
import { Buffer } from 'node:buffer'
import { createWorker } from '../mod.js'
import makeSynchronous from 'make-synchronous'
import { createSyncFn } from 'synckit'
import { redlet } from 'tinylet'
// the worker path must be absolute
const workerPath = new URL('./synkit-worker.js', import.meta.url).toString().slice(7)
const awaitSync = createSyncFn(workerPath, {})
const sin = makeSynchronous(async path => {
const fs = await import('fs/promises')
return fs.readFile(new URL(path))
})
const path = new URL('./bench.js', import.meta.url) + ''
const jim = createWorker()(async path => {
const fs = await import('fs/promises')
return fs.readFile(new URL(path))
})
let i
// Runs in a worker thread and uses Atomics.wait() to block the current thread.
const redletReader = redlet(async (path) => {
const fs = await import('fs/promises')
return fs.readFile(new URL(path))
})
i = 100
console.time('fs.readFileSync')
while (i--) readFileSync(new URL(path))
console.timeEnd('fs.readFileSync')
globalThis?.gc()
i = 100
console.time('redletReader')
while (i--) redletReader(path)
console.timeEnd('redletReader')
globalThis?.gc()
i = 100
console.time('synkit')
while (i--) awaitSync(path)
console.timeEnd('synkit')
globalThis?.gc()
i = 100
console.time('await-sync')
while (i--) jim(path)
console.timeEnd('await-sync')
globalThis?.gc()
i = 100
console.time('make-syncronous')
while (i--) sin(path)
console.timeEnd('make-syncronous') tried reading the same file 100 times:
same thing for reading it only 10 times:
and 400 times:
|
@Aslemammad @jimmywarting
I just found out that there's https://github.com/jimmywarting/await-sync and that got me thinking... It'd be cool if there was one way of doing things with regard to synchronous worker magic. Right now there is:
I can acknowledge that some of the more low-level Node.js-specific ones are in a "different class" but there's https://github.com/jimmywarting/await-sync and https://github.com/tinylibs/tinylet which seem to do the same thing(ish)...
If possible, I think it'd be great for either this package or https://github.com/jimmywarting/await-sync to be "the one". I'm perfectly OK with deprecating (or yanking since this package has <10 weekly DLs and no dependants) in favor of https://github.com/jimmywarting/await-sync and contributing my changes there, or it could go the other way around. 🤷♂️
TLDR: I think that these two packages overlap enough that I'd like to combine them. Is this a good idea? 🤔 @jimmywarting thoughts? I don't know if I'm overstepping etiquette or anything here.
The text was updated successfully, but these errors were encountered: