Skip to content

Implemented ReadByte/WriteByte on streams to improve performance - #384

Merged
adamhathcock merged 1 commit into
adamhathcock:masterfrom
MrJul:perf-readbyte
May 28, 2018
Merged

adamhathcock merged 1 commit into
adamhathcock:masterfrom
MrJul:perf-readbyte

Conversation

@MrJul

@MrJul MrJul commented May 27, 2018

Copy link
Copy Markdown
Contributor

NonDisposingStream and ReadOnlySubStream should implement ReadByte: currently they don't, and the default Stream implementation allocates a new one-byte buffer each time.

Stream.ReadByte() is used extensively by the LZMA decoder. With this simple change, I get a ~16-17% speed improvement on my machine while extracting all files in a 43MB LZMA-compressed zip file, and total memory allocations are cut by 1GB!

In the same fashion, I've also overridden CountingWritableSubStream.WriteByte to improve encoding. The speed results are marginal (2-3% improvement) since the encoding algorithm takes most of the CPU time, but they exist. Additional, memory traffic is also cut by a fair margin.

I've also implemented ReadByte/WriteByte on most SharpCompress streams where it was trivial to do so.

@adamhathcock

Copy link
Copy Markdown
Owner

Thanks for this. I've barely done any kind of perf or memory usage testing.

If you want to keep doing it and/or implement some kind BenchmarkDotNet tests I wouldn't say no :)

@adamhathcock
adamhathcock merged commit f9bd7eb into adamhathcock:master May 28, 2018
@SuperJMN

SuperJMN commented Jul 9, 2018

Copy link
Copy Markdown

Looking forward to having it integrated into the NuGet package!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants