-
-
Notifications
You must be signed in to change notification settings - Fork 41
fix: explicitly start MessagePort
#116
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
Conversation
d40845a
to
caf528c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Linking here the previous attempts/frustration:
But I'm still not sure if this is the right approach. We don't have if (isDeno)
checks either - tinypool
just works there. This is really something Bun should fix instead of us. Tinypool is compatible with NodeJS-like runtimes.
But I'm happy to see what kind of changes are required here and if we can isolate them out of the common code.
This is based on assumption that every other JS runtime like
There are three types of changes:
|
Yes, that is somewhat the assumption on runtimes that have pages like Bun's Node.js compatibility. I wouldn't expect 100% though as there will always be weird edge cases. Previously I've noticed that Bun's If |
commit: |
This is how Tinypool support in Bun should be achieved: oven-sh/bun#19940, exactly as mentioned in #116 (review). Let's see how the progress goes there first. |
I encourage any contribution to Bun runtime, but I personally feel that approaching the main problem with And also expecting Bun or any other runtime to follow NodeJS even when NodeJS is not aligned with JS specs (see (comment)[https://github.com/oven-sh/bun/issues/19863#issuecomment-2929201194]) will help grow that runtime. And no matter what the cross runtime compatibility issues will remain in fine details, so libraries should also be covering that compatibility part. |
We are more than happy to add changes that are required by JS specs, that NodeJS does not follow, such as calling If we indeed want to add runtime specific conditions in libraries, I would also like to see these changes in Piscina that is the upstream of Tinypool. It would be easier to adapt those changes then. Edit: Actually it looks like Piscina maintainers are waiting for support from Bun's side instead: piscinajs/piscina#787 (comment). |
@AriPerkkio This PR now contains the minimum possible change to support Bun. Please review.
|
test/termination.test.ts
Outdated
// TODO: Need to debug the weird issue for this test | ||
if (isBun) return skip() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a weird error in Bun runtime which I yet can't figured out. Do you have any idea what it would be?
TypeError: undefined is not a constructor (evaluating 'new Tinypool({
filename: new URL(import.meta.url, import.meta.url).href,
runtime: "child_process",
isolateWorkers: !0,
minThreads: cpus().length - 1,
maxThreads: cpus().length - 1
})')
c4d635d
to
efc0479
Compare
Rebased the branch with upstream
There are only one item left to figure out further, but seems not integral behavior issue. I am looking on it, if you have nay thoughts please share. Please review rest of the code. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changes under src/**
look good - there's not too many exceptions just for Bun. I would rather remove the changes of test/**
and CI stuff. Did you try if node:worker_threads
works in Bun? That's the runtime: 'worker_threads'
in Tinypool.
Like I mentioned in #116 (comment), for Bun users it would be best to use either Subprocess
or Worker
from Bun directly instead of trying to make Tinypool's NodeJS runtimes compatible. I would expect Bun's "native" APIs be more efficient than Node compatible APIs.
@AriPerkkio Sorry last week was very busy in BBW (Berlin Blockchain Week), so could not get into this feedback. But I would dedicate time this week to get this PR going. Related to your comment about using Bun Related to to you other point |
168d844
to
19f8b43
Compare
19f8b43
to
08e8143
Compare
Vitest run with preview, looks good: https://github.com/AriPerkkio/vitest/actions/runs/15687002111 ✅ |
MessagePort
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, thanks!
I had to remove the Bun CI as it was failing tests constantly, even when using --fileParallelism=false
.
Bun js is getting popularity and a lot of tools are started to support it. And
tinypool
is dependency ofvitest
which is widely used across the ecosystem. So it's really important thatvitest
supports Bun runtime so other projects can also test their specs more easily.The only limitation I observed Vitest supporting Bun is the
tinypool
support for it. I earlier created another test pool implementation for vitest to support Bun https://github.com/nazarhussain/vitest-in-process-pool but I believe the best direction would be to make thetinypool
compatible with Bun, so rest of the ecosystem align automatically.Not everything is working but a lot. Here is a glimps of it.
There are few limitations though:
atomics
is not yet compatible with the Bun, so settinguseAtomics
to false will work fine.resourceLimits
not yet supported by Bun.