Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve rar memory usage #887

Merged
merged 9 commits into from
Jan 14, 2025

Conversation

majorro
Copy link
Contributor

@majorro majorro commented Jan 13, 2025

  • Removed redundant BufferPool
  • Improved memory usage of UnpackV1:
    • used ArrayPool for window
    • used stackalloc for other array allocations

@majorro
Copy link
Contributor Author

majorro commented Jan 13, 2025

Benchmark (unpack goes through Unpack29):

using var stream = File.OpenRead("F:\\Rar.rar");
using var reader = ReaderFactory.Open(stream, new ReaderOptions() { LeaveStreamOpen = true });
while (reader.MoveToNextEntry())
{
    if (reader.Entry.IsDirectory)
    {
        continue;
    }

    using var entryStream = reader.OpenEntryStream();
    entryStream.CopyTo(_memoryStream);
    _memoryStream.Position = 0;
    _memoryStream.SetLength(0);
}

Results:
image

@adamhathcock
Copy link
Owner

Thank you so much for this. I'm currently doing a lot of this at my current job and meant to update sharpcompress but never got around to it. Doing this hopefully will inspire me to do more!

@adamhathcock adamhathcock merged commit fa1d440 into adamhathcock:master Jan 14, 2025
2 checks passed
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.

2 participants