mattermost / mattermost-redux

Redux for Mattermost

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[perf] localeCompare is slow & proposed fix

koxen opened this issue · comments

Summary

String.localeCompare function is very very slow.
Do V8 devs know about it?
Yes, it's been at their bugtracker for a long time, they won't 'fix' it.

It's used here to sort the channels, which happens very often, for example when switching channels.
I 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.
(40 navbar items)

It's hard for me to get the exact numbers, but I guarantee it's not less than 10% of channel switch time.
I 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.
Maybe even a for-each-char loop that checks if the char is within ASCII range.
If not, only then use localeCompare.

This 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.

Would that be fine?

For now I injected this piece of code to my mattermost-webapp and enjoyed better channel switch time:

String.prototype.localeCompare = function(b) { var a = this;   return (a < b ? -1 : (a > b ? 1 : 0));}

Environment Information

  • Webapp or React Native app:
  • Mattermost Server Version:

Steps to reproduce

How can we reproduce the issue?
Have lots of channels in navbar and switch channel.

Expected behavior

Describe your issue in detail.
Channel switching is fast.

Observed behavior

What did you see happen? Please include relevant error messages and/or screenshots.
Channel switching is slower than it could be.

Possible fixes

If you can, link to the line of code that might be responsible for the problem.
If two strings are within ASCII range use a simple compare and not localeCompare.

Closing this one due to inactivity and age.