decimal128 icon indicating copy to clipboard operation
decimal128 copied to clipboard

Thread safety

Open mratsim opened this issue 5 years ago • 1 comments

Just a quick reminder that it might be necessary to use this library in a multithreaded context for example for accounting software with work split across one core per year.

In that case trivial types like arrays should be preferred over sequences if possible, for example here: https://github.com/JohnAD/decimal128/blob/9ec5431b583cb22789ddf1c47dab22e99b1d74b5/src/decimal128/dpd.nim#L72-L127

This also avoids memory allocation which might be a bottleneck if done regularly and which is also problematic for long-running processes as it might lead to memory fragmentation.

mratsim avatar Jun 14 '20 20:06 mratsim

I will put this on my list of improvements!

That particular reference, the contents of dpd.nim are not actually being used right now as the library does not support densley packed binary yet. decimal128.nim does not even import it. But when it does, I'll be sure to convert to a static array. The array is fixed at 34 bytes, so converting to a static array will be easy.

JohnAD avatar Jun 15 '20 00:06 JohnAD