Octonica / ClickHouseClient

ClickHouse .NET Core driver
Apache License 2.0
140 stars 23 forks source link

Fix over-allocaction for (ReadOnly)Memory<T> #83

Closed alec-anikin closed 10 months ago

alec-anikin commented 10 months ago

Hi!

There is a strange memory allocation behavior on writing arrays as Memory\ReadOnlyMemory

Method Mean Error StdDev Allocated
Array 102.6 ms 1.61 ms 1.50 ms 200.64 KB
Memory 101.9 ms 1.52 ms 1.35 ms 1169.16 KB
ReadonlyMemory 101.9 ms 1.68 ms 1.57 ms 1169.83 KB

Benchmark code insert the same data as array, Memory and ReadOnlyMemory.

I try to solve the issue with this PR and new code benchmarks are below

Method Mean Error StdDev Allocated
Array 101.6 ms 1.61 ms 1.42 ms 202.37 KB
Memory 102.2 ms 1.88 ms 1.76 ms 202.38 KB
ReadonlyMemory 101.7 ms 1.99 ms 1.95 ms 201.43 KB

Thank you!