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

method findElements extremely slow #65

Closed
lklonowski opened this issue Nov 24, 2017 · 4 comments
Closed

method findElements extremely slow #65

lklonowski opened this issue Nov 24, 2017 · 4 comments

Comments

@lklonowski
Copy link

As mentioned in #49, execution time has extremely slowed down between version 2.23.2 and 2.28.1.
I was able to track it down and found out that the method findElements is significantly slower now.

Here is a little test page I used:

<html>
<head/>
<body>
<input type="text" id="textId100"/>
<input type="text" id="textId200"/>
<input type="text" id="textId300"/>
<input type="text" id="textId400"/>
<input type="text" id="textId500"/>
<input type="text" id="textId600"/>
<input type="text" id="textId700"/>
<input type="text" id="textId800"/>
<input type="text" id="textId900"/>
<input type="text" id="textId1000"/>
</body>
</html>

And this is the code I executed:

HtmlUnitDriver driver = new HtmlUnitDriver(false);
driver.get("file://path/to/test.html");
long start = System.currentTimeMillis();
for (int i = 1; i <= 1000; i++) {
	String id = "textId" + i;
	List<WebElement> webElements = driver.findElements(By.id(id));
	if (!webElements.isEmpty()) {
		System.out.println("Found element with ID " + id);
	}
}
long stop = System.currentTimeMillis();
System.out.println("Duration in ms: " + (stop - start));

Both times, the output for the found elements is correct, but the last output line differs dramatically:
version 2.23.2: Duration in ms: 890
version 2.28.1: Duration in ms: 200728

@rbri
Copy link
Collaborator

rbri commented Nov 24, 2017

Thanks for the sample code.
Will have a look at this.
Have you done your measurements with the sysout in every loop?

@lklonowski
Copy link
Author

I added measurements for each loop:

HtmlUnitDriver driver = new HtmlUnitDriver();
driver.get("file://C:/Users/lklonowski/Desktop/test.html");
long start = System.currentTimeMillis();
for (int i = 1; i <= 1000; i++) {
	String id = "textId" + i;
	long innerStart = System.currentTimeMillis();
	List<WebElement> webElements = driver.findElements(By.id(id));
	long innerStop = System.currentTimeMillis();
	System.out.println("Duration of loop " + i + " in ms: " + (innerStop - innerStart));
	if (!webElements.isEmpty()) {
		System.out.println("Found element with ID " + id);
	}
}
long stop = System.currentTimeMillis();
System.out.println("Duration in ms: " + (stop - start));

It looks like the method takes a lot more time when the element cannot be found (even with this small sample page):

...
Duration of loop 898 in ms: 203
Duration of loop 899 in ms: 203
Duration of loop 900 in ms: 0
Found element with ID textId900
Duration of loop 901 in ms: 204
Duration of loop 902 in ms: 202
Duration of loop 903 in ms: 203
...

@rbri
Copy link
Collaborator

rbri commented Nov 25, 2017

You are right in all points, really nice finding. There was some useless wait code called in your situation.
This is fixed now. Will make a new version available.

@rbri rbri closed this as completed Nov 25, 2017
@lklonowski
Copy link
Author

Thanks for the new version with the quick fix.
The simple test case from the first comment now only took 9ms which even is 100 times faster than the old reference version.
I ran some longer and parallel tests and could not find any further problems. The overall performance is quite good.

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

No branches or pull requests

2 participants