-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
2 draw optimization -- pre-parse colors, short-circuit path construction code #3393
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
Conversation
748a62a
to
32b932c
Compare
👍 from me. |
My only concern is that we have another set of PRs to remove assert statements. Other than that, looks good to me. If I am understanding this correctly, this:
|
I haven't looked at this PR yet, but one concern I have with messing around On Mon, Aug 25, 2014 at 1:26 PM, Thomas A Caswell [email protected]
|
As far as I know all internal color representation should be rgba tuples, "none" or "auto". I wasn't sure how to know that I got all of them, but I did some verifications that the expensive "to_rgba" wasn't called during the draw phase in various cases. I feel like the latter two are mildly odd special cases, but I think they make sense as specific indirections which aren't encoded by the rgba tuple. I'm not attached to the asserts although they were useful to me to put my mind at ease that the rest of the code was behaving as I thought. (In general, I think it is distressing that most Pythoners seem to avoid asserts -- but that's a personal opinion. I think you should be compiling to .pyo as Guido intended if you want asserts not there at runtime :). ) |
Oh, I should specify that the "none" and "auto" cases only are possible in the markeredgecolor, markerfacecolor, and markerfacecoloralt properties in lines.py. |
self._rgb = colors.colorConverter.to_rgba(fg, self._alpha) | ||
elif isRGBA: | ||
self._rgb = fg | ||
else: | ||
self._rgb = colors.colorConverter.to_rgba(fg) | ||
self._orig_color = self._rgb |
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.
This seems like a change in behaviour to me. Previously, _orig_color
stored the un-alphaified value, now it is stored after the application of alpha.
That said, I don't see why we need self._orig_color
. This file is the only place it occurs, I think we can just drop it and use (the now badly named) self._rgb
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.
@tacaswell , I agree that _orig_color should be deleted, but I say that with some trepidation since the relationships of _alpha, _forced_alpha, _rgb, _orig_color are scary to me in the code before this patch. Whether or not all 4 are geniunely needed, I don't know, but I'm sure they are named very sub-optimally. For instance, "_rgb" should really be "_rgba" as you note.
I'm going to investigate this point further right now.
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.
I would advise writing a lot of unit tests.
Thinking about this on the train this morning what I suspect happened (and it might be worth doing some code forensics to check) is that originally mpl only did RGB and the alpha was added by setting RGB -> RGB * A rather than carrying around RGBA values (I have read a bit of the math behind how alpha blending works, but have not internalized it yet, but both schemes give the same result, but are more/less annoying to work with is different cases, or something...). So the naming _rgb
is a hold over from that, as is _orig_color
, which you need if you are doing self._rgb = self._rgb * alpha
.
Sorry for this languishing. Please ping me if you push to this branch. |
@jbmohler It is starting to look like the color optimization is turning into a major re-write of undetermined scope (at a minimum this is going to involve a lot of unit tests). If you are willing to take this on, awsome and it should probably get it's own PR so we can get the line-related optimizations (or move those to their own PR). This sort of thing is the rather boring and feels thankless, but we need it. |
See #3681 which is the Path related change in this PR. |
Profiling has revealed two small but noticeable hits in drawing performance. These are addressed by this PR. Each commit represents about a 4% improvement at draw-time and they add to 8%. I'm not sure if this passes tests so this is a travis-ci probe as well as a request for comment.
My timings were done like so: