-
-
Notifications
You must be signed in to change notification settings - Fork 425
Use the ArrayPool API in .NET Standard 2.1 or later to reduce the creation of LOH objects. #1812
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
Conversation
…前的读取一次创建80MB的LOH对象减少到读取一次只创建16MB的LOH对象。目前仅在net8编译。
Thanks for your pull request and detailed explanation. I am right now traveling so it might take a while before I have time to review this. |
Okay, wish you a pleasant journey~ |
I have allowed the build a while back and it looks like your changes failed to build. Can you take a look at that? |
Feel free to reach out if you need more help with this PR. |
My apologies — I’ve been too caught up in gaming recently and haven’t checked GitHub or emails. I’ll review them as soon as possible. Thank you for your patience!😂😂 |
Take all the time that you need, just wanted to make sure you have read my message. And make sure you also delete that unused test image. |
Thanks for the reminder! I've deleted the test photos and submitted the updated code. It’s 4 AM here — calling it a day. Wishing you a wonderful day ahead! 🌞 |
Good afternoon! I’ve submitted the code modifications and removed the test images as discussed. Is there anything else I need to address? This is my first time contributing to a public repository, so please let me know if I’ve missed any steps or requirements. 😊 |
I’ve reviewed the feedback and will work on addressing the reported issues in the coming days. Thank you for the thorough review! 😄 |
After reviewing the building.md documentation, I re-ran localized tests on my code. The issue lies in the TheFeaturesProperty.ContainsExpectedFeatures method: when I locally retrieve MagickNET.Features, the value does not include 'Debug'. After removing 'Debug' from the expected values, all tests passed. However, I couldn’t reproduce the GitHub CI failure locally. Could you please investigate this? I’ve uploaded the test log file for reference. |
I suspect that your branch is not up to to date with the |
Oh! Didn’t realize that — I’ve already synced my branch with the latest main branch. Thanks for the heads-up! 😄 |
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.
Thanks for making this change. I finally had some time to do a proper review. Feel free to ask for more information when my question or comment is not clear for you.
# Conflicts: # src/Magick.NET/Helpers/ByteArrayWrapper.cs
2:将GetBytes方法重写后支持多次重复调用方法并返回正确的值。顺带减少了对象的分配。
I have modified the code according to your comments and verified the issues you raised — they were indeed correct. Additionally, I noticed that the original GetBytes method can be called repeatedly on the same instance without losing its internal _bytes data, whereas my implementation causes the _bytes within the instance to potentially be overwritten by other instances. Therefore, I removed the _pool.Return method and delegated the _pool.Return logic to the finalizer. I’m unsure if this approach is correct. If you have a better solution, please advise. Thank you! |
After a day of consideration, I decided to add it back. Currently, this class is not reused in the program. Therefore, it can be understood that GetBytes is called only once, and we'll address any future issues later. |
Hi, I'm a programmer from China. The text below is translated using AI, as my English isn't proficient enough for direct conversation, though I'm actively working to improve.
I'm developing a personal web application using Magick.NET. During development, I noticed that converting RAW photo files to JPG generates a significant number of LOH (Large Object Heap) objects. After reviewing the source code, I traced the issue to the ResizeBytes method in the ByteArrayWrapper class. This method reallocates byte arrays based on the length returned by localized code, causing unused arrays to accumulate in the LOH. To address this, I implemented the ArrayPool API to reduce LOH allocations. After the modifications, the program now generates only a small number of LOH objects per run, drastically reducing LOH allocation.
My environment uses .NET 8, and the ArrayPool API is only available in .NET Standard 2.1 or later, meaning it cannot compile in versions prior to .NET Standard 2.0 (e.g., .NET Framework 4.6.1).
Below are screenshots of how my interface uses Magick.NET and the memory monitoring. Each LOH change in the screenshots corresponds to one program execution.
Before:





After:
Here are my test photos, captured using a Nikon Z8 in uncompressed RAW format.
https://github.com/Wak1Z2/Magick.NET/tree/main/testImage
Thank you for reviewing my code! This is my first attempt at contributing to an open-source library.