Repository navigation
Reuse one stream in codec benchmarks - #3272
Merged
Merged
Conversation
Each codec benchmark now reuses one MemoryStream for both libraries. Each call rewinds the stream, so the results measure the codec and not the growth of a new stream. EncodeTiff truncates the stream instead, because the GDI+ TIFF encoder fails on leftover bytes. Update the result tables from new runs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Prerequisites
Description
The codec benchmarks created a new
MemoryStreamin each benchmark call. The timing then included the growth and copies of that stream, and Gen2 collections for its large arrays. In production, a caller would use a recycled stream. This PR applies the change from the BMP benchmarks in #3271 to the other codec benchmarks.Each changed benchmark now uses one stream for both libraries:
MemoryStreamthat[GlobalSetup]creates. Each call setsPosition = 0.MemoryStreamover the input bytes. Each call setsPosition = 0.[GlobalCleanup]disposes the stream.The results now measure the codec, not the growth of a new stream.
Special cases:
EncodeTiffcallsSetLength(0)instead ofPosition = 0. With a rewound stream, the GDI+ TIFF encoder threwExternalException("A generic error occurred in GDI+.") forNoneandCcitt1D.DecodeJpeg_ImageSpecificgives Skia anSKManagedStream(stream, false).SKCodec.Create(Stream)disposes the stream together with the codec.DecodeTga, ImageMagick and ImageSharp read the shared stream. Pfim still reads the byte array.EncodeJxlused a new pooledChunkedMemoryStreamin each call. It now uses the sharedMemoryStream. I updatedCodecs/Jxl/README.mdto match.I ran each changed benchmark and replaced the result table in its comment.
IdentifyJpeg,EncodeJxl,EncodeIndexedPngandEncodeGif_CoarsePaletteEncoderget their first table. The old table ofDecodeJpegParseStreamOnlywas outside the class. The new table is inside the class.These benchmarks already reused their stream, so I did not change them:
DecodeEncodeGif,DecodeJpeg,EncodeJpegComparison,EncodeJpegFeatures,EncodeJpegIccandEncodeTiffIcc.This change touches only benchmark code, so it adds no tests.
Changed files in
tests/ImageSharp.Benchmarks/Codecs:Exr/DecodeExr.csGif/DecodeGif.csGif/EncodeGif.csHeif/DecodeHeif.csHeif/EncodeHeif.csJpeg/DecodeJpegParseStreamOnly.csJpeg/DecodeJpeg_ImageSpecific.csJpeg/IdentifyJpeg.csJxl/EncodeJxl.csJxl/README.mdPng/DecodePng.csPng/EncodeIndexedPng.csPng/EncodePng.csTga/DecodeTga.csTga/EncodeTga.csTiff/DecodeTiff.csTiff/DecodeTiffIcc.csTiff/EncodeTiff.csWebp/DecodeWebp.csWebp/EncodeWebp.cs