On Wednesday, 21 July 2021 at 22:51:38 UTC, hanabi1224 wrote:
>Hi, I'm new to D lang and encounter some performance issues with fiber, not sure if there's something obviously wrong with my code.
I took a quick look, and the first problem I saw was that you were using spawnLinked
but not replacing the scheduler.
std.concurrency
uses a global scheduler
variable to do its job.
Hence doing:
- auto scheduler = new FiberScheduler();
+ scheduler = new FiberScheduler();
Will ensure that spawnLinked
works as expected.
There are a few other things to consider, w.r.t. fibers:
- Our Fibers are 4 pages (on Linux) by default;
- We have an extra guard page, because we are a native language, so we can't do the same trick as Go to auto-grow the stack;
- Spawning fibers is expensive and other languages reuse fibers (Yes, Go recycle them);
The FiberScheduler
implementation is unfortunately pretty bad: it does not re-use fibers. I believe this is the core of the issue.