Skip to content

Avoid redundant result iterator restarts - #4601

Open
ilkecan wants to merge 1 commit into
tesseract-ocr:mainfrom
ilkecan:avoid-redundant-resultiterator-restarts
Open

Avoid redundant result iterator restarts#4601
ilkecan wants to merge 1 commit into
tesseract-ocr:mainfrom
ilkecan:avoid-redundant-resultiterator-restarts

Conversation

@ilkecan

@ilkecan ilkecan commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Summary

Avoid redundant paragraph and text-line restarts when a ResultIterator is already at the required physical start position.

The reading-order setup repeatedly copied iterators and restarted them even when PageIterator::Next() had just placed them at a paragraph or text-line start. On sparse layouts with many blocks, those no-op restarts become costly repeated scans.

Change

  • guards paragraph and row restarts with the physical PageIterator::IsAtBeginningOf() predicate
  • uses the same physical predicate to detect paragraph transitions after PageIterator::Next()
  • adds focused LTR and RTL coverage for block, paragraph, and text-line iteration, including logical versus physical starts and an interior word

Performance

GCC 15.2 RelWithDebInfo build, with OEM 3, PSM 11 and OMP_THREAD_LIMIT=1:

Input Before After
input-4267x3200.png 52.90 s 8.41 s
#4430 page.png >300 s 95.62 s

The minimal reproducer's OCR output is identical to the baseline from main.
The reproducer, input-4267x3200.png, is generated by repeating a 16x16 texture-only image across a 4267x3200 canvas.

input-4267x3200.png input-4267x3200
background-tile-16.png background-tile-16
Related to #4430.

Validation

  • Full CTest suite: 62/62 passed.

@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 7 complexity · 0 duplication

Metric Results
Complexity 7
Duplication 0

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Optimizes ResultIterator navigation by avoiding redundant scans when already at a physical paragraph or text-line start.

Changes:

  • Guards paragraph and row restarts with physical-position checks.
  • Uses physical starts to detect paragraph transitions.
  • Adds LTR and RTL iterator coverage.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/ccmain/resultiterator.cpp Avoids unnecessary iterator restarts and paragraph scans.
unittest/resultiterator_test.cc Tests logical and physical starts across iteration levels.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

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