Poor PpmdStream performance #557

Open
opened 2026-01-29 22:13:42 +00:00 by claunia · 1 comment
Owner

Originally created by @klasyc on GitHub (Jan 31, 2023).

Hello guys,

I am trying to extract PPMd files created by Dmitrij Sharkin's PPMd compressor variant I using SharpCompress library. These files are basically the PpmdStream data equipped by a simple header, for which I created a simple parser. I am using the code below for data extraction:

using (var fs = new FileStream("C:/Users/Vojtech/test.bdc.ppmd", FileMode.Open)) {
	PpmdHeader header = PpmdHeader.Read(fs);
	using (PpmdStream ppmdStream = new PpmdStream(new PpmdProperties(), fs, false)) {
		using (var ws = new FileStream("C:/Users/Vojtech/test.bdc", FileMode.Create)) {
			ppmdStream.CopyTo(ws);
		}
	}
}

The code above works, but it is very inefficient: My test file is approximately 9 MB long and extracts to roughly 168 MB. When I unpack it by 7-zip, it takes 1 - 2 seconds on my Core i7 laptop with SSD drive. Extracting the same file using the code above takes 11 seconds. Here are screenshots of my profiler:

obrazek
obrazek

It seems my program spends the majority of time inside the SharpCompress library, but unfortunately I don't understand how the PpmdStream is implemented and for me, it would be very hard to optimize it.

Anyway, thank you for any suggestions.

Originally created by @klasyc on GitHub (Jan 31, 2023). Hello guys, I am trying to extract PPMd files created by Dmitrij Sharkin's [PPMd compressor variant I](http://www.compression.ru/ds/) using SharpCompress library. These files are basically the `PpmdStream` data equipped by a simple header, for which I created a simple parser. I am using the code below for data extraction: ```CSharp using (var fs = new FileStream("C:/Users/Vojtech/test.bdc.ppmd", FileMode.Open)) { PpmdHeader header = PpmdHeader.Read(fs); using (PpmdStream ppmdStream = new PpmdStream(new PpmdProperties(), fs, false)) { using (var ws = new FileStream("C:/Users/Vojtech/test.bdc", FileMode.Create)) { ppmdStream.CopyTo(ws); } } } ``` The code above works, but it is very inefficient: My test file is approximately 9 MB long and extracts to roughly 168 MB. When I unpack it by 7-zip, it takes 1 - 2 seconds on my Core i7 laptop with SSD drive. Extracting the same file using the code above takes 11 seconds. Here are screenshots of my profiler: ![obrazek](https://user-images.githubusercontent.com/15925102/215757770-c9a50b68-390d-44a6-a61c-2f532a6b06ac.png) ![obrazek](https://user-images.githubusercontent.com/15925102/215757904-2988fee7-9aba-446d-84f5-e1fec2f86812.png) It seems my program spends the majority of time inside the SharpCompress library, but unfortunately I don't understand how the `PpmdStream` is implemented and for me, it would be very hard to optimize it. Anyway, thank you for any suggestions.
claunia added the enhancementup for grabs labels 2026-01-29 22:13:42 +00:00
Author
Owner

@adamhathcock commented on GitHub (Mar 1, 2023):

PRs are welcome to improve this. Been out of it for personal reasons.

@adamhathcock commented on GitHub (Mar 1, 2023): PRs are welcome to improve this. Been out of it for personal reasons.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/sharpcompress#557