fix: avoid O(n^2) value lookups in PPTX chart conversion - #2227
Merged
Conversation
Contributor
Author
|
@microsoft-github-policy-service agree |
Member
|
This looks quite sensible! Thanks for the fix. |
S1MS4
added a commit
to S1MS4/markitdown
that referenced
this pull request
Jul 21, 2026
fix: avoid O(n^2) value lookups in PPTX chart conversion (microsoft#2227)
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.
Problem
Converting a PPTX that contains a large chart is extremely slow and can appear to hang. A real-world deck with a 1097-point, 3-series chart spent ~2.7s just reading the chart values, and larger charts effectively froze the conversion.
Root cause
PptxConverter._convert_chart_to_markdownaccessedseries.values[idx]inside the nested (category × series) loop. In python-pptx,series.valuesrescans the cached data points via XPath on every access (O(n) per lookup), so the code was O(n²) per series and rebuilt the entire values tuple once per category — O(n³) overall.Fix
Materialize each series' values once before the loop, reducing the lookups to O(n). The generated Markdown is unchanged.
Benchmark (3 series, varying category count; identical output verified)
Tests
Added
test_pptx_chart_multi_series_conversion, which builds a multi-series chart with many categories and verifies the resulting Markdown table (series headers, first/last categories, and a representative data row).