NCronJob-Dev / NCronJob

A Job Scheduler sitting on top of IHostedService in dotnet.
https://docs.ncronjob.dev/
MIT License
159 stars 11 forks source link

fix: Don't use Unsafe version for scheduler #88

Closed linkdotnet closed 5 months ago

linkdotnet commented 5 months ago

We probably don't wanna use the unsafe version for no good reason.

falvarez1 commented 5 months ago

I used that construct cautiously to maximize performance, fully aware of the potential security risks. However, based on my initial, basic profiling tests, I did not notice any statistically significant performance difference. Given the potential benefits like reduced allocations, better diagnostics, and more control over threading, I think it's worth taking a deeper dive. I'll set aside some time for a more thorough analysis.

We can either use the safer method or just set the ConcurrencySettings.UseDeterministicTaskScheduler to false to use the regular OTB TaskScheduler for the time being.

References: https://github.com/dotnet/runtime/issues/27483

https://github.com/dotnet/orleans/pull/6261

https://learn.microsoft.com/en-us/dotnet/api/system.threading.threadpool.unsafequeueuserworkitem?view=net-8.0

linkdotnet commented 5 months ago

Then let's park it and set the flag to false - that let's us keep the original impl.

I will do this on another PR :D