Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: use lxml instead of bs4 to parse hOCR data #3960

Merged
merged 2 commits into from
Mar 18, 2025

Conversation

badGarnet
Copy link
Collaborator

@badGarnet badGarnet commented Mar 17, 2025

  • lxml is a much faster library than bs4 when the input data is regular
  • since the hOCR data is guaranteed to be regular (programmatically generated) we don't need bs4 here to parse the data
  • lxml improves parsing speed by about 10x

Example runtime profiling locally using the same hocr data from 1 page pdf, where agent.hocr_to_dataframe_bs4 is the current method on main and agent.hocr_to_dataframe is the PR's method.

Screenshot 2025-03-17 at 12 14 59 PM

- `lxml` is a much faster library when the input data is regular
- since the hOCR data is guaranteed to be regular (programmatically
  generated) we don't need `bs4` here to parse the data
- `lxml` improves parsing speed by about 10x

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
@badGarnet badGarnet marked this pull request as ready for review March 17, 2025 23:38
Copy link
Contributor

@ryannikolaidis ryannikolaidis left a comment

Choose a reason for hiding this comment

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

Amazing! Yes, please!

@badGarnet badGarnet added this pull request to the merge queue Mar 17, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Mar 18, 2025
@badGarnet badGarnet added this pull request to the merge queue Mar 18, 2025
Merged via the queue into main with commit 4e424ef Mar 18, 2025
43 checks passed
@badGarnet badGarnet deleted the feat/use-lxml-to-parse-hocr branch March 18, 2025 01:06
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.

None yet

2 participants