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

Webp improvements #1846

Merged
merged 13 commits into from
Nov 23, 2021
Merged

Webp improvements #1846

merged 13 commits into from
Nov 23, 2021

Conversation

brianpopow
Copy link
Collaborator

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 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

This PR changes the following:

  • Change hashchain to use the memoryAllocator (OffsetLength array is as big as the pixel count)
  • Change huffman code and HTreeGroup to a struct
  • Avoid allocating too many CostInterval objects by pooling a small amount of them. The number of CostInterval objects can easily get into 100k+ for an 1 megapixel image.
  • CostsManager now uses MemoryAllocator
  • Remove not needed DeepClone of HuffmanTree (while it was changed to a struct, the DeepClone was not removed and is responible for alot of allocations)
  • Change PixOrCopyMode, HistoIx and EntropyIx enums to be of byte type

Related to #1786

Allocations master:

Allocations_master

Allocations PR:

Allocations_pr

Test was done with lossless encoding of Calliphora image.

@codecov
Copy link

codecov bot commented Nov 21, 2021

Codecov Report

Merging #1846 (1450849) into master (2c5c9f1) will increase coverage by 0%.
The diff coverage is 100%.

Impacted file tree graph

@@          Coverage Diff           @@
##           master   #1846   +/-   ##
======================================
  Coverage      87%     87%           
======================================
  Files         937     937           
  Lines       48423   48438   +15     
  Branches     6056    6057    +1     
======================================
+ Hits        42225   42317   +92     
+ Misses       5192    5114   -78     
- Partials     1006    1007    +1     
Flag Coverage Δ
unittests 87% <100%> (+<1%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...rc/ImageSharp/Formats/Webp/Lossless/HuffmanCode.cs 100% <ø> (ø)
...rc/ImageSharp/Formats/Webp/Lossless/HuffmanTree.cs 64% <ø> (-36%) ⬇️
src/ImageSharp/Formats/Webp/Lossless/PixOrCopy.cs 100% <ø> (ø)
.../Formats/Webp/Lossless/BackwardReferenceEncoder.cs 92% <100%> (+<1%) ⬆️
...rc/ImageSharp/Formats/Webp/Lossless/CostManager.cs 98% <100%> (+<1%) ⬆️
src/ImageSharp/Formats/Webp/Lossless/HTreeGroup.cs 100% <100%> (ø)
...c/ImageSharp/Formats/Webp/Lossless/HuffmanUtils.cs 96% <100%> (-1%) ⬇️
...ageSharp/Formats/Webp/Lossless/Vp8LBackwardRefs.cs 100% <100%> (ø)
...rc/ImageSharp/Formats/Webp/Lossless/Vp8LEncoder.cs 97% <100%> (+<1%) ⬆️
.../ImageSharp/Formats/Webp/Lossless/Vp8LHashChain.cs 96% <100%> (+<1%) ⬆️
... and 9 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2c5c9f1...1450849. Read the comment docs.

public void Dispose()
{
this.Dispose(disposing: true);
GC.SuppressFinalize(this);
Copy link
Member

Choose a reason for hiding this comment

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

If your types can be sealed I would do so and avoid SuppressFinalize where it is not necessary.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah I think the Dispose(bool disposing) pattern is only favorable when we actually have a finalizer or expect subclasses to have a finalizer.

Copy link
Member

@JimBobSquarePants JimBobSquarePants left a comment

Choose a reason for hiding this comment

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

Nice job 👍

@brianpopow brianpopow merged commit 05c3f2b into master Nov 23, 2021
@brianpopow brianpopow deleted the bp/webpimprovements branch November 23, 2021 15:10
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