Skip to content

Memory Improvements#90

Merged
mbkrispy merged 4 commits intodevelopfrom
use-Span
Feb 9, 2024
Merged

Memory Improvements#90
mbkrispy merged 4 commits intodevelopfrom
use-Span

Conversation

@djrecipe
Copy link
Copy Markdown
Contributor

@djrecipe djrecipe commented Jan 22, 2024

Memory Improvements

  • Add AnyBitmap.FromSpan() and new AnyBitmap constructor both which take ReadOnlySpan<byte>
  • Add console application project for easy testing (feel free to omit this)
  • Reduces amount of copying done with loading tiffs (don't clone the images, rather just mutate the existing images)
  • Use Image.DetectFormat() to avoid trying to load Tiffs (saves some time and memory)

Span is a bit slower but uses much less memory. It's optional.

ReadOnlySpan Gains
devenv_crWylrUHYM

devenv_g9lJ8i0NIu

Tiff Gains
olde

newe

Type of change

Please select the relevant option by placing an 'x' inside the brackets, like this: [x].

  • 🐛 Bug fix (non-breaking change which fixes an issue)
  • ✨ New feature (non-breaking change which adds functionality)
  • 💥 Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • 🏗️ Internal/structural update (non-breaking change that improves code quality, organization, or performance)
  • 📚 This change requires a documentation update
  • 🚀 DevOps build chain modification for release
  • 🤖 DevOps build chain modification for CI

How Has This Been Tested?

Locally, see above images

Checklist:

Please run through the checklist as much as possible and mark the items completed by placing an 'x' inside the brackets, like this: [x].

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • I have successfully run all unit tests on Windows
  • I have successfully run all unit tests on Linux

@djrecipe djrecipe requested review from artem-iron, jacob-mellor and mee-ironsoftware and removed request for artem-iron and mee-ironsoftware January 22, 2024 08:31
Copy link
Copy Markdown
Contributor

@artem-iron artem-iron left a comment

Choose a reason for hiding this comment

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

See comment below

/// Create a new Bitmap from a a Byte Span.
/// </summary>
/// <param name="span">A Byte Span of image data in any common format.</param>
public static AnyBitmap FromSpan(ReadOnlySpan<byte> span)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I can say "Wow" every time I see the word Span<T> in managed code :D

@djrecipe
Copy link
Copy Markdown
Contributor Author

added tiff improvements; removed detrimental in keywords (I thought it caused them to be passed by ref but now I understand the use)

@djrecipe djrecipe changed the title Add Support for ReadOnlySpan Memory Improvements Jan 30, 2024
add console app for easy perf testing
add support for ReadOnlySpan; use Image.DetectFormat(); reduce copying when resizing tiffs
Copy link
Copy Markdown
Member

@mee-ironsoftware mee-ironsoftware left a comment

Choose a reason for hiding this comment

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

Awesome 💯

@@ -0,0 +1,12 @@
// See https://aka.ms/new-console-template for more information
Copy link
Copy Markdown
Contributor

@wasin-ironsoftware wasin-ironsoftware Feb 2, 2024

Choose a reason for hiding this comment

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

Good that we have test!

Alternatively, I think we could get away by grabbing memory usage information from either GC or System.Diagnostics, and validate if it doesn't reach higher than what rough goal we set. Because I think having a separate console app, very less chance others will know or will test against it.

@jordi-ironsoftware
Copy link
Copy Markdown
Contributor

This is related to #57

@mbkrispy mbkrispy merged commit 6efff42 into develop Feb 9, 2024
@mbkrispy mbkrispy deleted the use-Span branch February 9, 2024 03:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants