Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
String concat speed #40
In the Strings section the standard is:
I understand the clarity of code - but the performance is 80-100% worse. jsPerf
The need for such long strings is debatable anyway, but isn't this kind of a steep performance penalty for code style?
Hi Rafi, thanks for the checking out the style guide and including a jsPerf.
We think that if you are fine-tuning your app and you find that the bottleneck is string concatenation, then by all means move to a single line and leave a comment saying "this was slowing down the app, moved to a single line" kind of thing.
Ideally, we would avoid this mess all together and keep really long strings out of our apps, but sometimes it comes up.
My gut feeling is there will be many other things to optimize for performance before you get down to long string concatenation, but I haven't come across this problem before.
I'll leave this issue open for now and hopefully some other folks will chime in with an opinion and we can correct it if necessary.
I think concatenation is much more readable for the sole fact that you can keep the correct level of indentation. As I noted in my previous comment, I think concatenation of static strings should be removed by build tools so performance should not really ever be an issue.
referenced this issue
Aug 4, 2016
Not quite a moot point.... basically, referencing variables inside of a template literal is still much slower than string concatenation, however without referencing a variable (and simply using a template literal for line breaks) seems to have no performance impact... https://jsperf.com/es6-string-literals-vs-string-concatenation/4