panjf2000 / ants

🐜🐜🐜 ants is the most powerful and reliable pooling solution for Go.
https://ants.andypan.me/
MIT License
12.83k stars 1.36k forks source link

opt: using anonymous functions to keep goroutines alive after a panic #320

Closed coticom closed 6 months ago

coticom commented 6 months ago

1. Are you opening this pull request for bug-fixs, optimizations or new feature?

optimizations

2. Please describe how these code changes achieve your intention.

In scenarios where panics occur frequently, by using anonymous functions to keep the goroutine alive, one can reduce the repeated creation of goroutines. Here are my benchmark results: lQLPJw56Chp5HJ3NAdvNBZ6wqo8qFrqXrO0F8aJ0_7lrAQ_1438_475 lQLPJx4SuKEJfJ3NAg7NBX2wDFj_kjvlAYMF8aJ0_7lrAA_1405_526

3. Please link to the relevant issues (if any).

4. Which documentation changes (if any) need to be made/updated because of this PR?

4. Checklist

panjf2000 commented 6 months ago

I appreciate your efforts on this, but I don't think this is what we want in ants. PanicHandler is created to prevent the tasks from unexpected panics, which should be very rare and sufficient for handling panics. If the user submits a task that has a high probability of panicking, they should recover the panic in the task function. It makes little sense for ants to introduce this complexity for a rare case which is also unexpected and discouraged.

coticom commented 6 months ago

I appreciate your efforts on this, but I don't think this is what we want in ants. PanicHandler is created to prevent the tasks from unexpected panics, which should be very rare and sufficient for handling panics. If the user submits a task that has a high probability of panicking, they should recover the panic in the task function. It makes little sense for ants to introduce this complexity for a rare case which is also unexpected and discouraged.

Based on your response, upon further consideration, it is indeed unreasonable to increase complexity for the sake of optimizing extreme cases. Thank you for the reminder.

coticom commented 5 months ago

潘少,有个空投你感兴趣吗?claim.fluence.network,这个是flt币,我看你是有资格的,如果你不感兴趣的话,能卖给我吗?我以2000元的价格收

---Original--- From: "Andy @.> Date: Thu, Mar 28, 2024 09:14 AM To: @.>; Cc: @.**@.>; Subject: Re: [panjf2000/ants] opt: using anonymous functions to keepgoroutines alive after a panic (PR #320)

I appreciate your efforts on this, but I don't think this is what we want in ants. PanicHandler is created to prevent the tasks from unexpected panics, which should be very rare and sufficient for handling panics. If the user submits a task that has a high probability of panicking, they should recover the panic in the task function. It makes little sense for ants to introduce this complexity for a rare case which is also unexpected and discouraged.

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.***>