Skip to content

#12 Implement Tiff Encoder benchmarks - #1496

Merged
JimBobSquarePants merged 1 commit into
SixLabors:tiff-formatfrom
IldarKhayrutdinov:tiff-format-benchmarks
Jan 26, 2021
Merged

JimBobSquarePants merged 1 commit into
SixLabors:tiff-formatfrom
IldarKhayrutdinov:tiff-format-benchmarks

Conversation

@IldarKhayrutdinov

@IldarKhayrutdinov IldarKhayrutdinov commented Jan 7, 2021 •

Copy link
Copy Markdown
Contributor

Prerequisites

  • I have written a descriptive pull-request title
  • I have verified that there are no overlapping pull-requests open
  • I have verified that I am following matches the existing coding patterns and practice as demonstrated in the repository. These follow strict Stylecop rules 👮.
  • I have provided test coverage for my change (where applicable)

Description

  • Implement encoder benchmarks
  • Rework decoder benchmarks

@IldarKhayrutdinov
IldarKhayrutdinov marked this pull request as draft January 7, 2021 15:05
@IldarKhayrutdinov
IldarKhayrutdinov marked this pull request as ready for review January 7, 2021 18:56
@IldarKhayrutdinov IldarKhayrutdinov mentioned this pull request Jan 7, 2021
17 tasks done
private Configuration configuration;

#if BIG_TESTS
private static readonly int BufferSize = 1024 * 68;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is the reason to change the buffer size here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for large files suitable a larger buffer

quote from spec:

For maximum compatibility with operating systems such as MS-DOS and Windows, the StripOffsets array should be less than or equal to 64K bytes in length,
and the strips themselves, in both compressed and uncompressed forms, should
not be larger than 64K bytes

64+4


private Configuration configuration;

#if BIG_TESTS

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would rather not use the #if BIG_TESTS here and only use the bigger images or why do you think there is a need for both? Does it take too long?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok i, think i can answer my one question here: I understand now why those images are called big 😄
I was not aware that those images are generated. The uncompressed images are more than 700MB, thats way to much.

I would suggest to use the Calliphora_x images in the Tiff folder for the benchmarks. With 804x1198 pixels they are reasonable big and we do not need the script to generate the images then.

@IldarKhayrutdinov IldarKhayrutdinov Jan 19, 2021 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the files is very big and takes too long. For the repository they are large, but big files are actually for tiff. It's such a compromise... I'll look Calliphora_x files

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the resolution here? I can still see the conditional in place (now unused)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah yes, this case used for local stress testing, what way can you suggest to correctly implement this?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets leave it as is then for now

}
}

[IterationSetup]

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the image bytes need to be loaded during GlobalSetup not in IterationSetup. Maybe do it the same way as for example DecodeFilteredPng.cs

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, definitely global.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is actually only loaded when needed: https://github.com/SixLabors/ImageSharp/pull/1496/files/d83f32704a669d3472685fdbb381c401240974f1#diff-3243ee1e2090c5162ac369f99493f7b1cccd702d463fdbc40880f44ced0474d0R81

Several files are used for testing, so that not all files are loaded into memory at once, only the current test file is loading.

using (var memoryStream = new MemoryStream())
{
this.tgaCore.SaveAsBmp(memoryStream);
this.tgaCore.SaveAsTga(memoryStream);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good spot: i thought i did already changed that in the past...

public class DecodeTiff : BenchmarkBase
{
private byte[] tiffBytes;
public class Clr : Config.ShortClr

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd much rather any configuration classes are kept together. If the column with is an issue make it global.

@IldarKhayrutdinov IldarKhayrutdinov Jan 19, 2021 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, yes, I think it would be useful to increase the column for global

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

return EncoderValue.CompressionCCITT3;

case TiffEncoderCompression.ModifiedHuffman:
return EncoderValue.CompressionRle;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@brianpopow Please check

@JimBobSquarePants

Copy link
Copy Markdown
Member

It'd be nice to see the actual results of the benchmarks in the ticket once we have them completed.

@IldarKhayrutdinov

Copy link
Copy Markdown
Contributor Author
Method Job Runtime TestImage Compression Mean Error StdDev Ratio RatioSD Gen 0 Gen 1 Gen 2 Allocated
'System.Drawing Tiff' Job-JLDWCC .NET 4.7.2 Tiff/rgb_uncompressed.tiff None 522.4 μs 207.39 μs 11.37 μs 1.00 0.00 249.0234 249.0234 249.0234 774.09 KB
'ImageSharp Tiff' Job-JLDWCC .NET 4.7.2 Tiff/rgb_uncompressed.tiff None 306.2 μs 296.36 μs 16.24 μs 0.59 0.03 90.8203 90.8203 90.8203 394.24 KB
'System.Drawing Tiff' Job-WGKTIW .NET Core 2.1 Tiff/rgb_uncompressed.tiff None 582.0 μs 254.63 μs 13.96 μs 1.00 0.00 249.0234 249.0234 249.0234 772.1 KB
'ImageSharp Tiff' Job-WGKTIW .NET Core 2.1 Tiff/rgb_uncompressed.tiff None 258.7 μs 91.20 μs 5.00 μs 0.44 0.00 90.8203 90.8203 90.8203 393.67 KB
'System.Drawing Tiff' Job-PWXKNG .NET Core 3.1 Tiff/rgb_uncompressed.tiff None 381.5 μs 83.16 μs 4.56 μs 1.00 0.00 181.6406 181.6406 181.6406 579.44 KB
'ImageSharp Tiff' Job-PWXKNG .NET Core 3.1 Tiff/rgb_uncompressed.tiff None 207.7 μs 24.74 μs 1.36 μs 0.54 0.01 90.8203 90.8203 90.8203 393.66 KB
'System.Drawing Tiff' Job-JLDWCC .NET 4.7.2 Tiff/rgb_uncompressed.tiff Lzw 2,342.2 μs 228.49 μs 12.52 μs 1.00 0.00 140.6250 140.6250 140.6250 516.21 KB
'ImageSharp Tiff' Job-JLDWCC .NET 4.7.2 Tiff/rgb_uncompressed.tiff Lzw 29,144.9 μs 2,716.01 μs 148.87 μs 12.44 0.09 281.2500 250.0000 250.0000 1032.41 KB
'System.Drawing Tiff' Job-WGKTIW .NET Core 2.1 Tiff/rgb_uncompressed.tiff Lzw 2,516.3 μs 309.03 μs 16.94 μs 1.00 0.00 156.2500 156.2500 156.2500 514.92 KB
'ImageSharp Tiff' Job-WGKTIW .NET Core 2.1 Tiff/rgb_uncompressed.tiff Lzw 14,471.4 μs 1,255.64 μs 68.83 μs 5.75 0.06 265.6250 265.6250 265.6250 1029.41 KB
'System.Drawing Tiff' Job-PWXKNG .NET Core 3.1 Tiff/rgb_uncompressed.tiff Lzw 2,578.5 μs 986.66 μs 54.08 μs 1.00 0.00 117.1875 117.1875 117.1875 386.54 KB
'ImageSharp Tiff' Job-PWXKNG .NET Core 3.1 Tiff/rgb_uncompressed.tiff Lzw 11,926.7 μs 2,236.56 μs 122.59 μs 4.63 0.06 265.6250 265.6250 265.6250 1029.39 KB
'System.Drawing Tiff' Job-JLDWCC .NET 4.7.2 Tiff/rgb_uncompressed.tiff CcittGroup3Fax 2,420.5 μs 216.07 μs 11.84 μs 1.00 0.00 23.4375 - - 78.88 KB
'ImageSharp Tiff' Job-JLDWCC .NET 4.7.2 Tiff/rgb_uncompressed.tiff CcittGroup3Fax 293.7 μs 111.38 μs 6.11 μs 0.12 0.00 90.8203 90.8203 90.8203 394.24 KB
'System.Drawing Tiff' Job-WGKTIW .NET Core 2.1 Tiff/rgb_uncompressed.tiff CcittGroup3Fax 2,550.2 μs 1,069.24 μs 58.61 μs 1.00 0.00 23.4375 - - 78.67 KB
'ImageSharp Tiff' Job-WGKTIW .NET Core 2.1 Tiff/rgb_uncompressed.tiff CcittGroup3Fax 265.6 μs 162.82 μs 8.92 μs 0.10 0.00 90.8203 90.8203 90.8203 393.67 KB
'System.Drawing Tiff' Job-PWXKNG .NET Core 3.1 Tiff/rgb_uncompressed.tiff CcittGroup3Fax 2,466.8 μs 1,093.85 μs 59.96 μs 1.00 0.00 15.6250 - - 59.26 KB
'ImageSharp Tiff' Job-PWXKNG .NET Core 3.1 Tiff/rgb_uncompressed.tiff CcittGroup3Fax 215.1 μs 34.49 μs 1.89 μs 0.09 0.00 90.8203 90.8203 90.8203 393.66 KB
'System.Drawing Tiff' Job-JLDWCC .NET 4.7.2 Tiff/rgb_uncompressed.tiff ModifiedHuffman 1,076.4 μs 298.37 μs 16.35 μs 1.00 0.00 248.0469 248.0469 248.0469 774.07 KB
'ImageSharp Tiff' Job-JLDWCC .NET 4.7.2 Tiff/rgb_uncompressed.tiff ModifiedHuffman 293.4 μs 86.00 μs 4.71 μs 0.27 0.00 90.8203 90.8203 90.8203 394.24 KB
'System.Drawing Tiff' Job-WGKTIW .NET Core 2.1 Tiff/rgb_uncompressed.tiff ModifiedHuffman 1,217.7 μs 601.68 μs 32.98 μs 1.00 0.00 248.0469 248.0469 248.0469 773.6 KB
'ImageSharp Tiff' Job-WGKTIW .NET Core 2.1 Tiff/rgb_uncompressed.tiff ModifiedHuffman 258.2 μs 169.54 μs 9.29 μs 0.21 0.01 90.8203 90.8203 90.8203 393.67 KB
'System.Drawing Tiff' Job-PWXKNG .NET Core 3.1 Tiff/rgb_uncompressed.tiff ModifiedHuffman 986.2 μs 508.86 μs 27.89 μs 1.00 0.00 181.6406 181.6406 181.6406 579.41 KB
'ImageSharp Tiff' Job-PWXKNG .NET Core 3.1 Tiff/rgb_uncompressed.tiff ModifiedHuffman 210.5 μs 19.28 μs 1.06 μs 0.21 0.01 90.8203 90.8203 90.8203 393.66 KB

@JimBobSquarePants JimBobSquarePants left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm happy for this to go in now in its current state. Very impressed by the benchmarks. Will have to profile the LZW ones to see why it's no much slower sometime though.

@JimBobSquarePants
JimBobSquarePants merged commit 56a7d5e into SixLabors:tiff-format Jan 26, 2021
@IldarKhayrutdinov
IldarKhayrutdinov deleted the tiff-format-benchmarks branch January 26, 2021 10:38
JimBobSquarePants added a commit that referenced this pull request Feb 17, 2021
JimBobSquarePants added a commit that referenced this pull request Feb 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants