-
-
Notifications
You must be signed in to change notification settings - Fork 853
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
Substantial Jpeg performance degradation on master branch as of 09.12.2021 #1884
Comments
Thanks for spotting! This is something we should definitely look into. I won't have time before next week, if you have an easy way to obtain perf profile before/after, don't hesitate to share, but no worries if not. |
Not sure I understand what you meant by that. Some sort of a flame graph or full capture from PerfView (don't have a Rider)? |
I have done some profiling with dotTrace before and after #1730 merged with masterbefore:Profiling results as a zip: |
@brianpopow thanks! Looks like all codecs are affected by this, should I rename the issue? |
Lets wait with renaming until @antonfirsov confirms that |
Thanks @brianpopow! This all makes sense, in the new |
I assumed it just wasn't required anymore when reviewing. Whoops! |
Makes sense why progressive jpeg wasn't affected by this as it does not get span that often. |
There's a lot of work going on in internal API of the memory code. Consider this somewhat of a small draft proposal. We should separate internal API and public API, i.e. provide unsafe check-free api for internal code with debug checks just for the sake of fool-proofness and public API with full amount of checks. For example, this method has 6 if checks which are basically useless for the Jpeg codec because higher level code ensures all them to be true. ImageSharp/src/ImageSharp/Memory/DiscontiguousBuffers/MemoryGroupExtensions.cs Lines 32 to 58 in d81c511
Yes, branch predictor most likely will eliminate miss overhead but it's still a check and it still may screw up prediction history - we can't rely on hardware implementation and/or predictor history buffer. A lot less important, uniform group buffer has redundant operations during span fetching in a First, it converts
Then it converts this offset to the
While all of this might not be that performance heavy, thing is, screws are so tight for jpeg right now that even such small optimizations can gain percents of performance. |
Cant look at code right now, but if I remember correctly The hard part is to find a consistent design. I'm thinking of adding separate virtual methods to MemoryGroup for Span and Memory dispatch, and |
I'll write down some notes with fresh thoughts so you you'll have a full picture when you'll have time to look at this.
Jpeg spectral data buffers (which are the main bottnecks in this conversation about slow ImageSharp/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegComponent.cs Lines 133 to 145 in 424d4f9
Which allocates 2D buffer with ImageSharp/src/ImageSharp/Memory/MemoryAllocatorExtensions.cs Lines 59 to 65 in ee83e99
So we can safely use |
@antonfirsov sorry for being intrusive but any chance for an ETA? :) |
You are probably reading minds, because I just started looking at this :) A PR will hopefully land next week. |
Nice, thanks! |
Description
Looks like it was caused by Memory Allocator PR but I'm not sure, just spotted it @antonfirsov @JimBobSquarePants
Master before allocator PR
Current master
What is strange is that progressive code wasn't really affected as baseline decoder.
Master before allocator PR
Current master
The text was updated successfully, but these errors were encountered: