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

Improve performance of d3_selectionPrototype.attr #2686

Closed
wants to merge 1 commit into from
Closed

Improve performance of d3_selectionPrototype.attr #2686

wants to merge 1 commit into from

Conversation

vendethiel
Copy link

Current engines (tested on Firefox and Chrome) aren't that smart about arguments yet.
It is slow to assign to one while using the others, because they are bound: changing name also changes arguments[0], which hinders the engines' ability to optimize the code.

The second issue is using a non-local value (and a arguments one at that) as the topic of a for-in, which is suboptimal.
In Chrome's profil, it warns with: "Not optimized: ForInStatement with non-local each variable".

Current engines (tested on Firefox and Chrome) aren't *that* smart about `arguments` yet.
It is slow to assign to one while using the others, because they are bound: changing `name` also changes `arguments[0]`, which hinders the engines' ability to improve the code.

The second issue is using a non-local value (and a `arguments` one at that) as the topic of a `for`-`in`, which is suboptimal.
In Chrome's profil, it warns with: "Not optimized: ForInStatement with non-local each variable".
@mbostock mbostock added this to the 4.0 milestone Dec 16, 2015
@mbostock
Copy link
Member

Thanks for the suggestion. I suspect that this is not a noticeable performance improvement, but it’s probably worth adopting this type of change D3-wide regardless. I’m not sure I’m willing to find and fix all of these places in D3 3.x, but I’d be willing to survey the new d3 modules for 4.0 and adopt this optimization.

@vendethiel
Copy link
Author

It appeared in my profiler output, that's why I changed it in the first place. We call setAttribute (through attr) very extensively, it seems...

@mbostock
Copy link
Member

Yep, anything that touches the DOM is typically expensive; it should be much more expensive than re-assigning to an argument.

@vendethiel
Copy link
Author

Right, but at least it silences the chrome profiler warnings. The second thing I'm the most "sad" about is the array subclassing using proto, but I don't really have the time to "fork" and change everything for our codebase... Oh well, guess I'm stuck with this in the meantime.

Do you want me to close this PR, or are you interesting to take it on this repo?

@mbostock
Copy link
Member

The array subclassing is going away in 4.0; it’s not a backwards-compatible change so it has to wait until the next major release. See the d3-selection repo.

I don’t plan on merging this into 3.x, but I was going to keep this issue around as a reminder to go through the new 4.0 repositories and look for similar problems.

@vendethiel
Copy link
Author

Good news, thanks :)

@mbostock
Copy link
Member

mbostock commented Apr 6, 2016

The good news is that D3 4.0 is written in ES2015 modules and strict mode, thus this is no longer an optimization killer.

@mbostock mbostock closed this Apr 6, 2016
@vendethiel
Copy link
Author

Is this confirmed not to trigger perf. warnings in chrome?

@mbostock
Copy link
Member

mbostock commented Apr 6, 2016

@mbostock
Copy link
Member

mbostock commented Apr 6, 2016

Also, d3-selection generally avoids re-assigning to arguments. See the new selection.attr implementation, for example.

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