⚡️ Speed up method PPTParser.convert_ppt_to_pptx by 126%
#272
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.
📄 126% (1.26x) speedup for
PPTParser.convert_ppt_to_pptxinbackend/python/app/modules/parsers/pptx/ppt_parser.py⏱️ Runtime :
2.94 milliseconds→1.30 milliseconds(best of190runs)📝 Explanation and details
The optimization introduces caching for LibreOffice availability checking using a class-level attribute
_libreoffice_found. This eliminates the repeatedsubprocess.run(["which", "libreoffice"])call that was executed on every method invocation.Key changes:
self.__class__._libreoffice_foundpptx_contentand return file content directlyPerformance impact:
The line profiler shows the LibreOffice check (
subprocess.run) takes ~3.7ms and represents 78-93% of total execution time. By caching this check, subsequent calls skip this expensive operation entirely. The optimization is most effective for:The 125% speedup (2.94ms → 1.30ms) demonstrates significant improvement, particularly valuable in production environments where PPT conversion happens repeatedly with the same parser instance.
✅ Correctness verification report:
🌀 Generated Regression Tests and Runtime
To edit these changes
git checkout codeflash/optimize-PPTParser.convert_ppt_to_pptx-mhcus5aland push.