Optimize Memory Usage and Add Cancellation Support in TesseractOcrEngine and ServiceConfiguration#1202
Open
DrHazemAli wants to merge 4 commits intomicrosoft:mainfrom
Open
Optimize Memory Usage and Add Cancellation Support in TesseractOcrEngine and ServiceConfiguration#1202DrHazemAli wants to merge 4 commits intomicrosoft:mainfrom
TesseractOcrEngine and ServiceConfiguration#1202DrHazemAli wants to merge 4 commits intomicrosoft:mainfrom
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
DrHazemAli
commented
Nov 6, 2024
Author
DrHazemAli
left a comment
There was a problem hiding this comment.
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.
Author
|
TesseractOcrEngine and ServiceConfigurationTesseractOcrEngine 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
Author
|
@dependabot rebase |
dluc
reviewed
Nov 13, 2024
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request introduces key optimizations and enhancements to improve memory handling and performance across two files:
shared/Ocr/Tesseract/TesseractOcrEngine.csandshared/ServiceConfiguration.cs.ExtractTextFromImageAsyncinTesseractOcrEngineto use buffered copying, minimizing memory spikes during large image processing. ImplementedIDisposableto ensure proper resource cleanup ofTesseractEngine.CancellationTokenhandling inExtractTextFromImageAsync, allowing for responsive task cancellation.GetServiceInstance<T>: Modified the service resolution approach inServiceConfiguration.csto avoid redundantIServiceCollectioncloning, 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.ExtractTextFromImageAsyncto handlecancellationTokenproperly by passing it intoCopyToAsyncand handlingOperationCanceledException.IDisposable: ImplementedIDisposableinTesseractOcrEngineto ensureTesseractEngineresources are disposed when the instance is no longer needed.GetServiceInstance<T>(shared/ServiceConfiguration.cs): Reduced memory footprint by avoiding redundantIServiceCollectioncloning and copying. Instead, services are configured within a scoped lifecycle to minimize memory overhead and prevent unnecessary duplication in dependency injection.Checklist
@dependabot rebase