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
Update L_segments to cache graphic parameters #10
Conversation
@@ -2247,8 +2247,9 @@ SEXP L_segments(SEXP x0, SEXP y0, SEXP x1, SEXP y1, SEXP arrow) | |||
int i, nx0, ny0, nx1, ny1, maxn; | |||
double vpWidthCM, vpHeightCM; | |||
double rotationAngle; | |||
int gpIsScalar[15] = {-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1}; |
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.
Might be good to introduce a const for '15' in grid.h (since this will be appearing in a few more places as well).
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.
That looks like a fairly straightforward change! Did we get something right the first time around ?
If this checks out ok in my build/test, we could probably do several of these in one go as the next stage (?)
Unfortunately, I am not seeing the same (relative) speed up ...
My test code is ...
Am I doing something stupid ? |
On the other hand, WITHOUT the patch, R-devel is noticeably worse ...
|
I can't really figure your setup out :-)... my way of testing is reinstalling grid in my standard installation, so that everything except grid is kept constant - this, of course, borkes my R installation somewhat but I can live with that for the moment. In that way I see a 2x speedup with the new segment implementation To answer the first question. Yes, I believe we got it right with points :-) It's a general solution that should require a minimal set of changes to all primitives. The reason we don't see the speed improvements that points gave is that point had additional changes to avoid converting the units for size more than once. Further, I suspect unit converting in general to be the main bottleneck right now and segments have twice the number of units than points so it might be masking some of the improvements... |
Yes, I'm beginning to think that my set up may not be ideal for benchmarking. This is such a small change (thanks to the previous patch) that I think it is reasonable to trust your timings (and even if they were wrong, we are not paying a big price in code complexity), so I have committed this patch now (r76245). It may seem a bit hypocritical to talk about deadlines, but the R 3.6.0 release is probably going to be late April, which suggests a late March/early April feature/code freeze. For simplicity/coherency, so that all primitives move to this caching mechanism in the same R release, would it be possible to get a patch for all or most of the other primitives within about a week ? Only if they are as straightforward as this one and only if (heaven forbid) you don't have other things with higher priority :) |
I'll begin to prepare a sweeping PR... I'm pretty sure that the only changes required are those done here, but will point out any additional if required. How likely are you to take a look at #1 before the feature freeze? It would be nice to get such big changes into a minor release rather than a patch release, so they'd have to wait a year if we skip next release (I think)... FWIW, I've made changes to minimise breaking changes due to implicit coercion of the unit vector (which incidentally have made it much faster to construct), so any breaking changes now should fully be due to package directly extracting attributes from the unit objects (which has never been safe anyway) |
Thanks for the cache primitives patch. I will try to start taking a proper look at #1 tomorrow. Yes, it would be great to get that into R 3.6.0 as well (sorry for not getting to it sooner!) |
This PR implements the same changes as done for points in #8
My own tests show that this change the performance from 6.75x to 3.14x relative to
segments()
@pmur002 will you take a look at this