Skip to content

Refactor resizeImage function for better resource handling#218

Merged
psiddh merged 2 commits intometa-pytorch:mainfrom
psiddh:main
Feb 25, 2026
Merged

Refactor resizeImage function for better resource handling#218
psiddh merged 2 commits intometa-pytorch:mainfrom
psiddh:main

Conversation

@psiddh
Copy link
Contributor

@psiddh psiddh commented Feb 24, 2026

Refactor image resizing to use input stream safely and improve bitmap scaling.

This fix saves ~47 MB of memory per image and prevents an OOM kill, but has zero impact on latency or throughput.
More of stability fix, not a performance fix.

Refactor image resizing to use input stream safely and improve bitmap scaling.
@meta-cla meta-cla bot added the CLA Signed This label is managed by the Meta Open Source bot. label Feb 24, 2026
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR refactors the resizeImage function in the ETImage class to improve resource handling and reduce memory consumption by approximately 47 MB per image, preventing out-of-memory errors in Android image processing.

Changes:

  • Fixed typo in error message ("input streams" → "input stream")
  • Wrapped input stream handling with Kotlin's .use extension for automatic resource cleanup
  • Added bitmap recycling for the original bitmap after scaling
  • Changed bitmap scaling filter from false to true to enable bilinear filtering

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@psiddh psiddh merged commit 42cc1e5 into meta-pytorch:main Feb 25, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants