-
-
Notifications
You must be signed in to change notification settings - Fork 850
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
OilPaintingProcessor memory usage improvements #1068
OilPaintingProcessor memory usage improvements #1068
Conversation
@JimBobSquarePants Don't merge this one just yet even if it passes the tests, I have another minor optimization done in another commit but I'll wait before pushing that one so that you'll have the CI free for your work 👍🏻 |
Codecov Report
@@ Coverage Diff @@
## master #1068 +/- ##
==========================================
- Coverage 89.83% 81.46% -8.37%
==========================================
Files 1200 704 -496
Lines 53010 29342 -23668
Branches 3847 3290 -557
==========================================
- Hits 47621 23904 -23717
- Misses 4561 4745 +184
+ Partials 828 693 -135
Continue to review full report at Codecov.
|
@JimBobSquarePants I've pushed my other commit now, though all the tests are failing in the CI for some reasons, I suspect it's just the CI itself that's acting up as before. cc. @antonfirsov in case you want to review the changes in this PR, as you're the optimization guru 😄 |
@Sergio0694 I don't think it's all CI issues. Maybe try running your tests locally in 32bit mode. https://ci.appveyor.com/project/six-labors/imagesharp/builds/29921783 |
@JimBobSquarePants Ok, this is weird - I've cloned Same issue in the branch for this PR in my for - I might be missing something but I don't think those errors are caused by changes I made in my branch, since What's more, the error seems to be with the checks in the |
Hi Sergio, i have tried to reproduce your issue, but on the current master all tests are working fine. Also in the current master, i only see 4 oil paint tests: |
@brianpopow Mmh... I had literally just cloned the entire repo into a new folder before running those tests, and I'm seeing the same results in my fork too. I have to say I'm very confused at this point 🤔 |
@JimBobSquarePants I'm not really sure about what's going on here - I've merged the latest changes from Now I only see those 4 that @brianpopow mentioned, and they pass just fine for me here. |
So, I've merged all the changes from But, I can't seem to be able to figure out what's wrong with the tests. I've tried to clone The fact that I should add though that at least the "full image" tests run fine in this PR, it's just some of the "in box" ones that file. Just like with the ones in I have to say I'm a bit confused, I wouldn't mind someone taking a look here 😅 |
@brianpopow Ah, I forgot they had already given the green light to C# 8 features in Why did you revert 692c35b though? 🤔 |
@Sergio0694 hi Sergio. I was able to reproduce the issue with your current branch. The error was introduced with the commit 692c35b (I hope its ok that i reverted it). It seems that the memory was corrupt. This needs to be reviewed again, i could not spot the exact error, but im sure this is how it was introduced. |
Hey @brianpopow - ah, sure, if that commit was the culprit then that's perfectly ok! 👍 Anyway, thank you so much for taking the time to look into this, I appreciate it! 😊 |
@Sergio0694 if I revert @brianpopow's revert commit, the memory corruption is even worse on my PC:
I wonder how should we proceed. Maybe merge it as-is for now, and try adding furter fixes later? |
@antonfirsov Yup, that's what I was thinking about, I'll give that a try! Also, I think it'd be best to wait until all the issues have been fixed, I'm a bit worried that there might still be some incorrect indexing going on that's just not being picked up by the tests by chance. EDIT: tried the EDIT 2: I think I've found the issue with that commit 👍 EDIT 3: yes, I failed again, but this time I know what's going on 🙈 EDIT 4: victory at last! 🎉 |
@antonfirsov Managed to fix all the issues and added some more minor optimizations, I'm pretty happy about the implementation right now. I've added you as a reviewer, let me know what you think! 😊 @JimBobSquarePants As promised, the PR is ready to merge now! 🚀 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not familiar with the underlying algorithm, so I have limited understanding here, but the refactor seems OK, and I trust the tests enough to assume that the changes are correct.
@antonfirsov I'll be honest, I really have no clue about the details of the underlying algorithms either, I've just focused on doing some general memory optimizations, trusting the tests as well 😅 |
@Sergio0694 been there so many times with jpeg! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice, just some minor stylistic issues.
src/ImageSharp/Processing/Processors/Effects/OilPaintingProcessor{TPixel}.cs
Outdated
Show resolved
Hide resolved
src/ImageSharp/Processing/Processors/Effects/OilPaintingProcessor{TPixel}.cs
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Very much appreciated! 👍
Yeah! The RC1 is one tiny step closer! 🚀🍻 |
Prerequisites
Description
The
OilPaintingProcessor
was allocating 4 arrays for each single pixel being processed. I've switched to a single, sharedfloat[]
array rented from the used configuration, and I'm using that as temporary data for all the 4 processing bins. In doing so, I've also switched toUnsafe.Add
for all the read/write operations to the 4 bins, for that extra micro-optimization breeze 🙌Just noticed those 4 throwaway arrays while working on my other pull request and I couldn't resist 🤣