Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP


Combine first run() with Fiber creation #59

laverdet opened this Issue · 3 comments

2 participants


Right now a significant part of the runtime cost of fibers is entering the v8 C++ API; switching between JS and C++ is fairly expensive. The way node-fibers is built, creating a fiber enters C++ which is not necessary. We could restructure the code so that you don't enter C++ until the first time run() is called. Since it seems most uses of fibers create a fiber, immediately run them, and then destroy them, this should be a net gain. Unfortunately it may require rewriting a large portions of fibers in JS.


This sounds great from the asyncblock perspective.

We create a new fiber in every async method (to support running it in parallel with the fiber currently in context), so work that can be done to speed up fiber creation / init will increase performance.

I'm wondering if there's also a chance that this will help with fiber performance while debugging :).


So I tried it and it's slower somehow. I tried everything I could think of and couldn't make it any faster. Seems v8 has moved far enough along to where the C++/JS membrane isn't really substantial.

Here's the diff if you're interested:

It exposes a new Fiber.newAndRun() method. First argument is the function to run, and the second argument is the argument to pass to the fiber. It returns an array which is [fiber, returnValue]. On my system it's just a little bit slower. If you can find a case where it's faster I'll add it.


Although d4c0b81 makes it a tiny bit faster, but nothing significant.

@laverdet laverdet closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.