@tsteur opened this Issue on June 28th 2019 Member

@sgiehl how hard would it be to have a cache for say the top 20 or top 30 most commonly used user agents? Like an array say

$cache = array(
 'Mac Foo' => array('isBot' => false, 'OS' => 'Mac', ... ), 

We could every other month update the list of most commonly used user agents. This would avoid needing to parse and test a lot of regexp etc. We could then just test like if (isset($cache[$userAgent])). I think I looked up a while ago that the top 10 or top 30 user agents make up like 50% of the requests which means it would make them a lot faster.

We're sometimes seeing device detector can take 200-400ms "randomly" and maybe it would improve things. I'd be keen to move this to 3.11 if it's easy to do and we could have a look at it. If it's a bit more work, happy to move it into a different milestone.

fyi @mattab

@Findus23 commented on June 28th 2019 Member

It might be worth it to take a large set of user agents and see what the most common ones are and especially which fraction they make up.
I feel like (without having looked it up) it might be really low as apart from iPhones which are fairly uniform there are too many combinations of browser patch versions, brands, etc. to make an impact with exact matches.

@tsteur commented on June 28th 2019 Member


Looking at only a few requests this can become quickly worth it I would say. Especially considering Chrome's marketshare. Would just need to keep it up to date regularly. The top 6 or top 7 be enough already.

@mattab commented on July 3rd 2019 Member

Another idea, could the device detector algorithm itself be "optimised" to run faster for the most common code paths and therefore most common user agents like Chrome on windows, safari on iphone, etc. This way we wouldn't have to maintain the list the user agents and just the code would always be faster for those? maybe that's already implemented in this way somehow? or maybe it's not really possible to make the algorithm faster in this way?

@sgiehl commented on July 3rd 2019 Member

Unfortunately that doesn't work that easy. The detection for Chrome for example needs to be done very "late", as many other browsers rely on Chromium and also contain Chrome in the useragents together with their own identifier. Without changing the current structure it won't be possible to improve the speed much, besides caching full useragents and matching rules

@tsteur commented on July 17th 2019 Member

We could btw also extract a list of say 500 or 1000 user agents... and update this list regularly to ideally not need to run any regex for most user agents. We could then update this list say monthly (especially once there are new chrome/iOS versions).

Powered by GitHub Issue Mirror