-
Notifications
You must be signed in to change notification settings - Fork 702
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
Optimize Memory Usage and Add Cancellation Support in TesseractOcrEngine
and ServiceConfiguration
#1202
base: main
Are you sure you want to change the base?
Conversation
This fix minimizes memory usage by avoiding the duplication of services and using scoped resolution, which is ideal for transient, one-time configurations. Additionally, this approach leverages DI lifecycle management to ensure services are automatically cleaned up.
Reduce memory usage during CopyToAsync
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.
This PR improves memory handling and resource management across the TesseractOcrEngine and ServiceConfiguration components. Key optimizations include buffered copying for large image processing, enhanced cancellation support, efficient disposal of resources, and optimized service instance resolution. These changes contribute to more efficient memory usage, better responsiveness, and improved dependency injection practices.
|
TesseractOcrEngine
and ServiceConfiguration
TesseractOcrEngine
and ServiceConfiguration
[enhancement][memory][.net]
TesseractOcrEngine
and ServiceConfiguration
[enhancement][memory][.net]TesseractOcrEngine
and ServiceConfiguration
[enhancement] [memory] [.net]
TesseractOcrEngine
and ServiceConfiguration
[enhancement] [memory] [.net]TesseractOcrEngine
and ServiceConfiguration
@dependabot rebase |
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.
Reviewed
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.
Rechecked ✅
This pull request introduces key optimizations and enhancements to improve memory handling and performance across two files:
shared/Ocr/Tesseract/TesseractOcrEngine.cs
andshared/ServiceConfiguration.cs
.ExtractTextFromImageAsync
inTesseractOcrEngine
to use buffered copying, minimizing memory spikes during large image processing. ImplementedIDisposable
to ensure proper resource cleanup ofTesseractEngine
.CancellationToken
handling inExtractTextFromImageAsync
, allowing for responsive task cancellation.GetServiceInstance<T>
: Modified the service resolution approach inServiceConfiguration.cs
to avoid redundantIServiceCollection
cloning, instead configuring services within a scoped lifecycle. This reduces memory usage by minimizing instance duplication and leverages dependency injection more efficiently.Motivation and Context
TesseractOcrEngine
, and optimizes service resolution inGetServiceInstance<T>
.Description
ExtractTextFromImageAsync
(shared/Ocr/Tesseract/TesseractOcrEngine.cs): Introduced buffered copy to handle large images more efficiently, minimizing memory usage during image processing.ExtractTextFromImageAsync
to handlecancellationToken
properly by passing it intoCopyToAsync
and handlingOperationCanceledException
.IDisposable
: ImplementedIDisposable
inTesseractOcrEngine
to ensureTesseractEngine
resources are disposed when the instance is no longer needed.GetServiceInstance<T>
(shared/ServiceConfiguration.cs): Reduced memory footprint by avoiding redundantIServiceCollection
cloning and copying. Instead, services are configured within a scoped lifecycle to minimize memory overhead and prevent unnecessary duplication in dependency injection.Checklist
@dependabot rebase