gammazero / workerpool

Concurrency limiting goroutine pool
MIT License
1.33k stars 138 forks source link

perf: unify startWorker and worker to spawn less goroutines #59

Closed Wondertan closed 2 years ago

Wondertan commented 2 years ago

This PR is more like a question, more than a fix, as I think worker and startWorker are in split for a reason, which I just probably don't get. Can you pls explain it? I couldn't find the answer in git history and out of curiosity.

If there is no reason for that, then this PR should decrease the load on the runtime by spawning fewer routines in general and one less per worker in particular. Thanks for the great library anyway.

Wondertan commented 2 years ago

Kind ping @gammazero

gammazero commented 2 years ago

When starting a new worker, I want that new worker to run the new task directly, instead of pulling it off the work queue. Since the behavior was slightly different, I split it into two functions. Other than that, there is no reason it cannot be the same function.