mitiko / BWDPerf

BWD stands for Best Word Dictionary as it has the ability to be an optimal dictionary coder.
https://mitiko.github.io/BWDPerf
GNU General Public License v3.0
0 stars 1 forks source link

Pass around references to the underlying buffers for better performance #16

Closed mitiko closed 3 years ago

mitiko commented 3 years ago

Don't copy the whole byte array every time we move from one transform to another. Use Span<T> to only pass a reference to the data, a managed pointer.

mitiko commented 3 years ago

It's working... I did have to use Memory<T> instead of Span<T> of course because of async. And I also made it ReadOnlyMemory<T> since the input buffer is immutable anyway.

I'm currently making some performance tests to see if anything is faster: enwik5 m=12 r=8 Memory
Compression 04:24.486 64MB
Compression Old 03:56.809 64MB
Decompression 00:00.092
Decompression Old 00:00.069
enwik4 m=8 r=7 Memory
Compression 00:02.410 32MB
Compression Old 00:06.050 40MB
Decompression 00:00.016
Decompression Old 00:00.023

I took the mean of 3 runs for each measurement. I didn't dive deep for the memory measurements, just whatever top is saying as a percentage of my RAM. I'll improve perf measurements later on.

Weirdly, for enwik5, the new version keeps memory at 32MB, until the very end when it goes to 64, while the old one is steady at 40MB and goes to 64 at the end as well. I guess this is from parsing when we allocate 4*buffer.Length bytes for the int array and it doesn't matter we've saved some 8MB memory.