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

Faster svg pan #2623

Merged
merged 4 commits into from
May 10, 2018
Merged

Faster svg pan #2623

merged 4 commits into from
May 10, 2018

Conversation

etpinard
Copy link
Contributor

@etpinard etpinard commented May 9, 2018

resolves #2548 (there's still room for improvement, but it's enough to close that ticket for now I think).

In brief this PR:

  • makes pan/scroll go through the "inverse scale" per-point loop only when needed. This loop updates the transform attr of every point on every mousemove to counteract the scale of trace group during pan/scroll. It turns out that can be extremely costly on graphs with many pts and even more costly for text nodes.
  • stashes "hot" svg selections that are used during pan and scrolled to update the view w/o going through a relayout. Note that plots/cartersian/dragbox.js is now free of (potentially) slow selectAll calls!
  • updates optimization flags hasSVG, hasScattergl and friends only on mousedown instead of on every mousemove.

Taking https://plot.ly/~jackp/18395.embed to benchmark things:

before each mousedown interval took around 30-40ms:

peek 2018-05-09 16-52

off this branch we're down in around 1ms :

peek 2018-05-09 16-54

Note that this PR improves scroll performance a little as stashing shaves about 5ms per scroll interval, but is still pretty slow (we might have to wait for scattergl text there #2501).

cc @alexcjohnson @jackparmer

etpinard added 4 commits May 9, 2018 16:32
- (x|y) -> (x|y)Scale to match Drawing.setTextPointsScale
- pull out regex from function scope into module scope
- do not return the scale (it is not used anywhere)
... as opposed to on every mousemove.
... and apply inverse scale on pts only when needed!

- stash selections on the subplot plotinfo object
- stash 'old' (x|y) scale factor to determine if we need to update
  all the pts and text nodes
- rename 'draggedPts' category -> 'zoomScale'
- make Drawing.hideOutsideRangePoints handle bar vs scatter differences
  internally.

selection.each(function() {
// Get the transform:
t = (this.getAttribute('transform') || '').replace(re, '');
var t = (this.getAttribute('transform') || '').replace(SCALE_RE, '');
t += scale;
t = t.trim();
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't know whether the string manipulations here are a meaningful contribution to the performance... but this could all be simplified a bit (indexOf & .substr instead of a regex & .replace, no .trim) if we could omit the space before the word scale. It seems to work fine in my browsers, though in principle it's not supposed to be allowed: "The individual transform definitions are separated by whitespace and/or a comma."

Alternatively, we could imagine stashing the pre-scaled transform as perhaps a data-initialtransform attribute on each element and avoid all this processing...

Not necessary, just a possibility if you think there would be a benefit.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I haven't benchmarked this particular block yet, but I know that Drawing.setTextPointsScale is 4-5 times slower than this routine here Drawing.setPointGroupScale.

Spending time on making these routines faster would help improve scroll performance. So yeah, thanks for writing this down. I just opened a new ticket about this -> #2625

@alexcjohnson
Copy link
Collaborator

@etpinard looks great! Just the one nonblocking comment, lets do it. 💃

@etpinard etpinard merged commit a132b85 into master May 10, 2018
@etpinard etpinard deleted the stash-svg-pts branch May 10, 2018 14:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Stash SVG points selections for faster pan
2 participants