Marfusios/crypto-websocket-extensions

Concurrent Dictionary - Debug Vs Release latency

InTheta opened this issue · 3 comments

Hi,

Not really an issue, just an observation..
I’m sure you are aware but, the latency between debug and release version of build have a HUGE impact on speed / spin up of concurrent dictionary.

Thanks for info.
I was a little afraid about the performance of ConcurrentDictionary so I've removed it altogether and leave it just for simple Dictionary

private readonly Dictionary<string, OrderBookLevel> _asksBook = new Dictionary<string, OrderBookLevel>();

It could bring a few concurrency issues, I'm waiting for some result from real-life complex usage.

I did a quick research and I rather bring ConcurrentDictionary back.
It seems to be too much dangerous.

I did lots of performance testing previously (Dictionary vs ConcurrentDictionary), but I didn’t know debug version of concurrent dictionary was causing the latency and haven’t tested since.

I prefer the concurrent dictionary currently as with Dictionary you have to have a try catch on every iteration as you get “collection modified, cannot continue error” if reading /writing same time.

Locking Dictionary was bad as it drops data if locked.
If doing and HFT it needs to be fast and fresh data.

We could maybe do some speed tests on both, release and debug mode too?