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

Performance bottleneck in prune_unwanted_nodes causing 200ms per call #750

Open
thsunkid opened this issue Nov 23, 2024 · 1 comment
Open
Labels
question Further information is requested

Comments

@thsunkid
Copy link

When profiling trafilatura.bare_extraction method for some pages that took us a while to parse, I found that significant performance issues in extract_content method.

Root cause: Too many calls to prune_unwanted_node with each call taking upto ~200ms.

Steps to reproduce:

  1. Run python with cProfile profiler on bare_extraction
  2. Try to scrape and parse this page https://nlewo.github.io/nixos-manual-sphinx/generated/options-db.xml.html
  3. Observe prune_unwanted_node timing

Questions

  1. Are there existing configuration options or alternative methods in trafilatura to bypass/optimize this operation?
  2. Could we leverage Rust/C++ based HTML parsing libraries (like lxml-rs or html5ever) to accelerate node pruning?
  3. Could we leverage caching to reduce latency?
@adbar adbar added the question Further information is requested label Nov 25, 2024
@adbar
Copy link
Owner

adbar commented Nov 25, 2024

Hi @thsunkid, thanks for the detailed report and the example. We're talking about a web page which is very large (> 8Mb) and contains a lot of similar elements. This is not a representative example as it is fairly exceptional, so it doesn't seem worth it to chang the pipeline just for such cases.

You can adapt the function's arguments to your use case, see optimizing for speed section of the docs.
You can also have a look at the list of cleaned elements in settings.py if you want to speed up things a bit but everything takes more time since the web page is unusually large.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants