-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Reduce panel parameter setup in facetted plots #5431
Conversation
@clauswilke Do you happen to know if there is any case that |
If every panel uses the same projection and the same scales then the graticule should be identical. I'm only moderately confident in this statement though, haven't thought it through that carefully. |
Thanks Claus! I'll take your 'moderately confident' over my 'I guess so' anytime. |
How will this affect extension packages with new facets? Do they need updating? |
I expect they don't need any updates. The compression is within each step but between each step the full, expanded panel parameters are available, so this shouldn't affect anything outside the methods affected. |
I just realised that this would affect extensions where a RNG is used in any of the affected methods, but I expect this not to be a typical case as most plots are deterministic. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Merge branch 'main' into coord_redundancy # Conflicts: # R/facet-grid-.R # R/facet-wrap.R
I didn't see it at the time writing this PR, but it conflicts with #4467. |
Asking @thomasp85 to see if his approval still holds with the coord-level optimisation only. |
I'm going to assume the approval still holds and go ahead with merge. |
This PR aims to fix #5427.
Briefly, it determines unique combinations of x/y scales and (1) only sets up panel parameters and guides and (2) renders axes for these unique combinations. These are then repeated for the duplicated combinations.
In theory, the panel's x parameters and y parameters could be setup independently to further reduce the amount of setup is performed, but the
Guide$transform
method should have access to both at the same time.Below is a reprex from the issue that shows that the x-axis is only trained and drawn once:
Created on 2023-09-21 with reprex v2.0.2
This mostly will affect plots that have many facets but no/few unique scales. Benchmark below is for an optimal case (100 panels all sharing all scales) using this PR. All the panel param setup and drawing happens after
ggplot_build()
, so I'm testing theggplot_table()
performance.Created on 2023-09-21 with reprex v2.0.2
Compared to the same benchmark for the current main branch:
To me this is a clear performance benefit in this optimal case.