{"action":"opened","issue":{"url":"https://api.github.com/repos/mattermost/mattermost-redux/issues/409","repository_url":"https://api.github.com/repos/mattermost/mattermost-redux","labels_url":"https://api.github.com/repos/mattermost/mattermost-redux/issues/409/labels{/name}","comments_url":"https://api.github.com/repos/mattermost/mattermost-redux/issues/409/comments","events_url":"https://api.github.com/repos/mattermost/mattermost-redux/issues/409/events","html_url":"https://github.com/mattermost/mattermost-redux/issues/409","id":298718802,"number":409,"title":"[perf] localeCompare is slow & proposed fix","user":{"login":"koxen","id":11347747,"avatar_url":"https://avatars1.githubusercontent.com/u/11347747?v=4","gravatar_id":"","url":"https://api.github.com/users/koxen","html_url":"https://github.com/koxen","followers_url":"https://api.github.com/users/koxen/followers","following_url":"https://api.github.com/users/koxen/following{/other_user}","gists_url":"https://api.github.com/users/koxen/gists{/gist_id}","starred_url":"https://api.github.com/users/koxen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/koxen/subscriptions","organizations_url":"https://api.github.com/users/koxen/orgs","repos_url":"https://api.github.com/users/koxen/repos","events_url":"https://api.github.com/users/koxen/events{/privacy}","received_events_url":"https://api.github.com/users/koxen/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-02-20T19:28:54Z","updated_at":"2018-02-20T19:28:54Z","closed_at":null,"author_association":"NONE","body":"#### Summary\r\n\r\nString.localeCompare function is very very slow.\r\nDo V8 devs know about it?\r\nYes, it's been at their bugtracker for a long time, they won't 'fix' it.\r\n\r\nIt's used here to sort the channels, which happens very often, for example when switching channels.\r\nI personally have a lot of channels, mainly as archive, but since they are private channels I can't quit them like public channels so they get off the navbar.\r\n(40 navbar items)\r\n\r\nIt's hard for me to get the exact numbers, but I guarantee it's not less than 10% of channel switch time.\r\nI understand it's there to support Chineese and sorting non-latin stuff but we can at least use a fast regex before calling localeCompare like [a-zA-Z0-9!@#$^&*()] something close to that.\r\nMaybe even a for-each-char loop that checks if the char is within ASCII range.\r\nIf not, only then use localeCompare.\r\n\r\nThis could also be a visible improvement on the mobile app channel switching and I am curious to know this, if you guys have good tooling to check.\r\n\r\nWould that be fine?\r\n\r\nFor now I injected this piece of code to my mattermost-webapp and enjoyed better channel switch time:\r\n```\r\nString.prototype.localeCompare = function(b) { var a = this;   return (a < b ? -1 : (a > b ? 1 : 0));}\r\n```\r\n\r\n#### Environment Information\r\n\r\n- Webapp or React Native app: \r\n- Mattermost Server Version:\r\n\r\n#### Steps to reproduce\r\nHow can we reproduce the issue?\r\nHave lots of channels in navbar and switch channel.\r\n\r\n#### Expected behavior\r\nDescribe your issue in detail.\r\nChannel switching is fast.\r\n\r\n#### Observed behavior\r\nWhat did you see happen? Please include relevant error messages and/or screenshots.\r\nChannel switching is slower than it could be.\r\n\r\n#### Possible fixes\r\nIf you can, link to the line of code that might be responsible for the problem.\r\nIf two strings are within ASCII range use a simple compare and not localeCompare.\r\n"}}
{"actor":{"display_login":"koxen"}}