mirror of
https://github.com/adamhathcock/sharpcompress.git
synced 2026-02-12 13:35:11 +00:00
[PR #912] [MERGED] Optimize BufferedSubStream.ReadByte #1343
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/adamhathcock/sharpcompress/pull/912
Author: @jdpurcell
Created: 3/25/2025
Status: ✅ Merged
Merged: 3/25/2025
Merged by: @adamhathcock
Base:
master← Head:pr-bss-optim📝 Commits (1)
a7918d7Optimize BufferedSubStream.ReadByte📊 Changes
1 file changed (+27 additions, -27 deletions)
View changed files
📝
src/SharpCompress/IO/BufferedSubStream.cs(+27 -27)📄 Description
In
BufferedSubStream, by changing whatBytesLeftToReadand_cacheLengthtrack, we can simplify the work to be done when reading a byte.BytesLeftToReadnow tracks the amount of completely unread/uncached data, and_cacheLengthtracks the total cache length including the consumed portion. Then we only need to update the cache offset when reading a byte. It also moves the logic to refresh the cache into its own method. Interestingly, only about half of the performance increase comes from simplifying the variable usage. The other half comes from moving out the cache refresh logic, presumably because it makes theReadBytemethod small enough for callers to inline.Core i7-6700k (1.7% reduction):
Apple M3 (2.8% reduction):
Time to extract a 14MB 7z. The benchmarks are with .NET 8.0 but it also helped slightly with .NET Framework 4.8 (~1.1% reduction).
I wish I could keep going with these optimization PRs but I think I'm out of ideas after this one 😄.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.