{"action":"created","issue":{"url":"https://api.github.com/repos/symfony/symfony/issues/13658","labels_url":"https://api.github.com/repos/symfony/symfony/issues/13658/labels{/name}","comments_url":"https://api.github.com/repos/symfony/symfony/issues/13658/comments","events_url":"https://api.github.com/repos/symfony/symfony/issues/13658/events","html_url":"https://github.com/symfony/symfony/issues/13658","id":57318096,"number":13658,"title":"[Router] Optimization: use strncmp insteadof strpos","user":{"login":"backbone87","id":1196313,"avatar_url":"https://avatars.githubusercontent.com/u/1196313?v=3","gravatar_id":"","url":"https://api.github.com/users/backbone87","html_url":"https://github.com/backbone87","followers_url":"https://api.github.com/users/backbone87/followers","following_url":"https://api.github.com/users/backbone87/following{/other_user}","gists_url":"https://api.github.com/users/backbone87/gists{/gist_id}","starred_url":"https://api.github.com/users/backbone87/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/backbone87/subscriptions","organizations_url":"https://api.github.com/users/backbone87/orgs","repos_url":"https://api.github.com/users/backbone87/repos","events_url":"https://api.github.com/users/backbone87/events{/privacy}","received_events_url":"https://api.github.com/users/backbone87/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":6,"created_at":"2015-02-11T13:53:40Z","updated_at":"2015-02-11T16:58:49Z","closed_at":"2015-02-11T13:57:57Z","body":"strpos === 0 is used in the dumped router files to match static initial parts of a route.\r\nShouldnt be strncmp === 0 be faster than strpos === 0?\r\n\r\nAlso another nice followup optimization can be done, since strncmp returns -1 for \"smaller\" strings and 1 for \"larger\" strings:\r\n```php\r\n$c = strncmp($request, $route, $length);\r\nif($c < 0) {\r\n  // only routes that have a \"smaller\" initial part need to be checked\r\n} elseif($c == 0) {\r\n  // initial part matches, match the next part\r\n} else {\r\n  // only routes that have a \"larger\" initial part need to be checked\r\n} \r\n```\r\n\r\nI didnt run any performance tests for this, so its just an idea."},"comment":{"url":"https://api.github.com/repos/symfony/symfony/issues/comments/73918185","html_url":"https://github.com/symfony/symfony/issues/13658#issuecomment-73918185","issue_url":"https://api.github.com/repos/symfony/symfony/issues/13658","id":73918185,"user":{"login":"stof","id":439401,"avatar_url":"https://avatars.githubusercontent.com/u/439401?v=3","gravatar_id":"","url":"https://api.github.com/users/stof","html_url":"https://github.com/stof","followers_url":"https://api.github.com/users/stof/followers","following_url":"https://api.github.com/users/stof/following{/other_user}","gists_url":"https://api.github.com/users/stof/gists{/gist_id}","starred_url":"https://api.github.com/users/stof/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stof/subscriptions","organizations_url":"https://api.github.com/users/stof/orgs","repos_url":"https://api.github.com/users/stof/repos","events_url":"https://api.github.com/users/stof/events{/privacy}","received_events_url":"https://api.github.com/users/stof/received_events","type":"User","site_admin":false},"created_at":"2015-02-11T16:58:48Z","updated_at":"2015-02-11T16:58:48Z","body":"@backbone87 but this would make the dumper code insane IMO, given that the order of routes is meaningful. Doing a division based on the first route is not always possible depending of how other routes are looking like"}}