Repository navigation
perf(odt): index automatic styles for style lookups (1.6x-3.2x on Word-exported ODT) - #4881
Conversation
Signed-off-by: Afonso Ribeiro <afonso.diamantino2@gmail.com>
|
✅ DCO Check Passed Thanks @deadstrobe5, all your commits are properly signed off. 🎉 |
Merge Protections🟢 Merge protection satisfied — ready to merge. Show 1 satisfied protection🟢 Enforce conventional commitMake sure that we follow https://www.conventionalcommits.org/en/v1.0.0/
|
AI triage (advisory)Checked commit The PR adds a lazy index of the automatic styles in Topic labels added: CI safety: no concern found. A maintainer must still approve CI. The |
There was a problem hiding this comment.
AI first review (advisory): no blocker found
This review covers the full diff at 7d7a54ca9a. It read the code and did not run it.
The index and cache are logically sound. The monkey-patching order is correct: get_element is cached before _build() can run. All three backends (ODT, ODS, ODP) receive the change through _OdfBaseBackend. The existing tests use LibreOffice-authored files with few automatic styles; they pass through the new code but do not exercise the high-automatic-style path that triggers the fix. No wrong behavior is visible in the diff. The human reviewer should confirm that the behavior on a Word-exported ODT with many automatic styles is covered by at least one test, or accept that the benchmark numbers in the PR description are sufficient evidence.
A maintainer makes the merge decision. This review never approves the pull request.
|
One more step towards a faster docling ! |
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Follow-up to #4867, where @ExtReMLapin asked whether the ODF backend could use the same treatment. I first assumed the per-run text-style property reads were the cost, but caching those did nothing measurable on real files. Most of the time went into style lookups.
get_styleis already cached per (family, name), but each miss still goes through odfdo, which runs//office:font-face-declsand//office:automatic-stylesover the whole content.xml and then scans every automatic style for a match. ODT files exported from Word carry several hundred to over a thousand automatic styles, so conversion ends up quadratic in practice.This adds a small index over the content.xml automatic styles (built lazily on the first lookup, first match in document order, same as odfdo) for the families the backend asks for, and caches
get_elementon the content and styles parts so the container queries run once. Anything outside the index falls back to the original odfdo call.CPU time per conversion, A/B in one process, 9 interleaved rounds with alternating order, median [min-max] in ms:
LibreOffice-authored files with few automatic styles are roughly unchanged (the repo's own test files are within noise), and image-heavy ones stay dominated by PNG encoding in docling-core.
Checklist:
Review evidence:
Output is unchanged:
export_to_dict()JSON andexport_to_markdown()are byte-identical before and after on 51 files (all ODT/ODS/ODP sources undertests/data/odf/sources, larger synthetic copies of them, 5 LibreOffice Writer Guide chapters and 40 ODTs from gov.uk). No reference data changed.pytest tests/test_backend_opendocument.pypasses (61 tests), andprek run --files docling/backend/opendocument_backend.pypasses (ruff, ty, tach, max lines).