-
Notifications
You must be signed in to change notification settings - Fork 218
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
tab.find_elements() performance is 150x worse than JS #460
Comments
UpdateI created a minimum viable test case: use std::time::Instant;
use headless_chrome::Browser;
#[tokio::main]
async fn main() -> Result<(), anyhow::Error>{
let browser = Browser::default()?;
let tab = browser.new_tab()?;
tab.navigate_to("https://en.wikipedia.org")?;
tab.wait_until_navigated()?;
let start = Instant::now();
let _es = tab.find_elements("[href]")?;
let duration = start.elapsed();
println!("Time elapsed in find_elements() is: {:?}", duration);
Ok(())
} Compiling it with debug symbols and running perf/flamegraph I get the following: Which suggests that the majority of the time is spent in chrome. I'm not sure why chrome would take so long, and I'm running against a production build of chromium (so no debug symbols...). Will continue to investigate. |
Did you ever end up getting further in your investigation? |
Any improvements on this? |
Issue
Running
tab.find_elements()
takes >150 times as long as runningdocument.querySelectorAll()
in Javascript.I'm not sure if I'm doing something wrong or if this the expected performance, but this performance is prohibitive for my use case. Are there performance tricks I don't know about? The code seems to delegate to the browser's
document.querySelectorAll()
so I'm not sure where the time is being spent.On the same url:
Rust
Output
JS
Output
Investigations
Looking at the
headless_chrome
source leads me tobrowser::transport::Transport.call_method()
, but it's not clear where the time is being spent. I'm still starting on my rust journey, so I'm not familiar with the profiler tooling at this time to understand the details of this performance issue.The text was updated successfully, but these errors were encountered: