Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Consider avoiding string copy on substring for ~20% url matching performance improvement #571
It turns out that Android Java does create a new String copy for String.substring():
I'd naively assumed that wasn't the case, and our UrlMatcher calls substring() a lot. We already wrap Java's String in FocusString to avoid copies when reversing Strings - we could consider avoiding String.substring() by storing our own String offsets in FocusString. (Note: Java 6 used offsets, Java 7 switched during a point release, based on reading https://dzone.com/articles/changes-stringsubstring-java-7 ).
Doing that leads to a ~20% performance improvement in UrlMatcher.matches(), based on my testing on an N6P with Android 7.1.2 (default blocklist settings, ie. ad/analytic/social trackers blocked).
Average time for matcher.matches:
Note: I already have a local patch doing this, I just need to write some more tests to make sure FocusString really is bulletproof.
I don't think this is super important (we already are quite a bit faster than focus-iOS's matching algorithm), but the changes are fairly simple.
added a commit
May 8, 2017
I noticed that the performance numbers were a lot worse than 1 month ago: it turns out we now use