{"action":"created","issue":{"url":"https://api.github.com/repos/serbanghita/Mobile-Detect/issues/424","labels_url":"https://api.github.com/repos/serbanghita/Mobile-Detect/issues/424/labels{/name}","comments_url":"https://api.github.com/repos/serbanghita/Mobile-Detect/issues/424/comments","events_url":"https://api.github.com/repos/serbanghita/Mobile-Detect/issues/424/events","html_url":"https://github.com/serbanghita/Mobile-Detect/issues/424","id":92578741,"number":424,"title":"50% performance improvement","user":{"login":"FranBar","id":6294077,"avatar_url":"https://avatars.githubusercontent.com/u/6294077?v=3","gravatar_id":"","url":"https://api.github.com/users/FranBar","html_url":"https://github.com/FranBar","followers_url":"https://api.github.com/users/FranBar/followers","following_url":"https://api.github.com/users/FranBar/following{/other_user}","gists_url":"https://api.github.com/users/FranBar/gists{/gist_id}","starred_url":"https://api.github.com/users/FranBar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/FranBar/subscriptions","organizations_url":"https://api.github.com/users/FranBar/orgs","repos_url":"https://api.github.com/users/FranBar/repos","events_url":"https://api.github.com/users/FranBar/events{/privacy}","received_events_url":"https://api.github.com/users/FranBar/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/serbanghita/Mobile-Detect/labels/pending%20research","name":"pending research","color":"fbca04"}],"state":"open","locked":false,"assignee":{"login":"nicktacular","id":810546,"avatar_url":"https://avatars.githubusercontent.com/u/810546?v=3","gravatar_id":"","url":"https://api.github.com/users/nicktacular","html_url":"https://github.com/nicktacular","followers_url":"https://api.github.com/users/nicktacular/followers","following_url":"https://api.github.com/users/nicktacular/following{/other_user}","gists_url":"https://api.github.com/users/nicktacular/gists{/gist_id}","starred_url":"https://api.github.com/users/nicktacular/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nicktacular/subscriptions","organizations_url":"https://api.github.com/users/nicktacular/orgs","repos_url":"https://api.github.com/users/nicktacular/repos","events_url":"https://api.github.com/users/nicktacular/events{/privacy}","received_events_url":"https://api.github.com/users/nicktacular/received_events","type":"User","site_admin":false},"milestone":null,"comments":3,"created_at":"2015-07-02T08:17:34Z","updated_at":"2015-07-02T12:54:46Z","closed_at":null,"body":"Regular expressions consume more time in string long, the idea is to shorten the chain User Agent removed the irrelevant words:\r\n\r\n<pre>\r\n$userAgent1 = 'Mozilla/5.0 (Linux; U; Android 4.0.3; ko-kr; LG-L160L Build/IML74K) AppleWebkit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30';\r\n$userAgent2 = '(Android 4.0.3; ko-kr; LG-L160L Build/IML74K) AppleWebkit/534.30  Version/4.0 Mobile Safari/534.30';\r\n$userAgent3 = '(Android 4.0.3; LG-L160L Build/IML74K)  Version/4.0 Mobile Safari/534.30';\r\n$userAgent4 = 'Android 4.0.3; LG-L160L Build/IML74K)  Mobile';\r\n\r\n$detect = new Mobile_Detect(null, $userAgent1);\r\nfor ( $i = 0; $i < 100; $i++ ) {\r\n  $detect->isMobile();\r\n}\r\n...\r\nuserAgent1 267.6149 ms.\r\nuserAgent2 184.5591 ms.\r\nuserAgent3 139.5360 ms.\r\nuserAgent4  90.3389 ms.\r\n</pre>\r\n\r\nDevelopers can do preg_replace in the user agent in the constructor, but  require to know the code and deduce which are the relevant words. In addition to check if it is Tablet irrelevant words may vary from Mobile, or OS version...\r\n\r\nIn short, simply by doing this:\r\n<pre>\r\n$userAgent = preg_replace('/Mozilla|Linux/', '', $userAgent);\r\n</pre>\r\nGets a considerable improvement in performance.\r\n\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/serbanghita/Mobile-Detect/issues/comments/118023089","html_url":"https://github.com/serbanghita/Mobile-Detect/issues/424#issuecomment-118023089","issue_url":"https://api.github.com/repos/serbanghita/Mobile-Detect/issues/424","id":118023089,"user":{"login":"FranBar","id":6294077,"avatar_url":"https://avatars.githubusercontent.com/u/6294077?v=3","gravatar_id":"","url":"https://api.github.com/users/FranBar","html_url":"https://github.com/FranBar","followers_url":"https://api.github.com/users/FranBar/followers","following_url":"https://api.github.com/users/FranBar/following{/other_user}","gists_url":"https://api.github.com/users/FranBar/gists{/gist_id}","starred_url":"https://api.github.com/users/FranBar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/FranBar/subscriptions","organizations_url":"https://api.github.com/users/FranBar/orgs","repos_url":"https://api.github.com/users/FranBar/repos","events_url":"https://api.github.com/users/FranBar/events{/privacy}","received_events_url":"https://api.github.com/users/FranBar/received_events","type":"User","site_admin":false},"created_at":"2015-07-02T12:54:46Z","updated_at":"2015-07-02T12:54:46Z","body":"Honestly, I've been using another utility much worse only because the performance of this was poor.\r\n\r\nEvery day come new devices sometime the performance deteriorate completely.\r\n\r\nSo I thought maybe I can help with something in this sense, it is a great job that only need to improve performance.\r\n"}}