Skip to content

fix: avoid O(n^2) value lookups in PPTX chart conversion - #2227

Merged
afourney merged 1 commit into
microsoft:mainfrom
kz-000:fix/pptx-chart-perf
Jul 21, 2026
Merged

fix: avoid O(n^2) value lookups in PPTX chart conversion#2227
afourney merged 1 commit into
microsoft:mainfrom
kz-000:fix/pptx-chart-perf

Conversation

@kz-000

@kz-000 kz-000 commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

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_markdown accessed series.values[idx] inside the nested (category × series) loop. In python-pptx, series.values rescans 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)

categories before after speedup
50 0.48s 0.01s 47×
100 3.12s 0.03s 99×
200 22.4s 0.11s 205×
400 164s 0.40s 407×

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).

@kz-000

kz-000 commented Jul 21, 2026

Copy link
Copy Markdown
Contributor Author

@microsoft-github-policy-service agree

@afourney

Copy link
Copy Markdown
Member

This looks quite sensible! Thanks for the fix.

@afourney
afourney merged commit 9247794 into microsoft:main Jul 21, 2026
3 checks passed
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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants