Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use string concatenation instead of array.join for performance #9

Closed
wants to merge 2 commits into from

Conversation

billneff79
Copy link
Contributor

@billneff79 billneff79 commented Oct 24, 2016

String concatenation is significantly faster than array.join on almost every browser, and certainly in all of the modern ones (IE11, Chrome, FF, etc.)

JSPerf Performance Tests: https://jsperf.com/join-concat/2

Here is a a benchmark you can run of several different ways of executing the bezierCurveTo function. The one in this pull request is the fastest (click the Results tab and then click Run Bench):
ESBench: https://esbench.com/bench/580e55ee330ab09900a1a351

This pull request modifies path to use string concatenation to do the same thing instead of array joining for about a 2x performance improvement.

@@ -4,6 +4,7 @@ parserOptions:
env:
es6: true
browser: true
node: true
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just added this so we can lint the tests directory as well

@@ -86,7 +86,7 @@ tape("path.arc(x, y, radius, startAngle, endAngle) may append only an L command
tape("path.arc(x, y, radius, startAngle, endAngle) may append an M command if the path was empty", function(test) {
var p = path.path(); p.arc(100, 100, 50, 0, Math.PI * 2);
test.pathEqual(p, "M150,100A50,50,0,1,1,50,100A50,50,0,1,1,150,100");
var p = path.path(); p.arc(0, 50, 50, -Math.PI / 2, 0);
p = path.path(); p.arc(0, 50, 50, -Math.PI / 2, 0);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed linting error with duplicate variable declaration

@mbostock
Copy link
Member

I made some fixes and created PR #11. Seems reasonable, although it’s pretty hard to assess whether this is actually a performance improvement from a microbenchmark alone.

@mbostock mbostock closed this Nov 18, 2016
@billneff79 billneff79 deleted the stringConcat branch November 18, 2016 18:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants