Skip to content

Micro-optimize _to_rgba_no_colorcycle. #30020

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

Merged
merged 1 commit into from
May 8, 2025
Merged

Conversation

anntzer
Copy link
Contributor

@anntzer anntzer commented May 6, 2025

This patch speeds up conversions of #rgba-type formats by between 25% and 40% (while shortening the implementation), although real benefits should be limited because of caching in to_rgba.

PR summary

PR checklist

@tacaswell tacaswell added this to the v3.11.0 milestone May 6, 2025
@anntzer anntzer force-pushed the trnc branch 2 times, most recently from f3f2c44 to 9dc9749 Compare May 7, 2025 06:26
return (*[n / 0xff for n in bytes.fromhex(c[1:])],
alpha if alpha is not None else 1.)
elif len(c) == 4: # #rgb hex format, shorthand for #rrggbb.
return (*[int(n, 16) * 0x11 / 0xff for n in c[1:]],
Copy link
Member

Choose a reason for hiding this comment

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

This is just ?

Suggested change
return (*[int(n, 16) * 0x11 / 0xff for n in c[1:]],
return (*[int(n, 16) / 0xf for n in c[1:]],

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ah indeed, even better.

This patch speeds up conversions of `#rgba`-type formats by between 25%
and 40% (while shortening the implementation), although real benefits
should be limited because of caching in to_rgba.
@tacaswell
Copy link
Member

@story645 Did you mean to close this?

@tacaswell tacaswell reopened this May 7, 2025
@story645
Copy link
Member

story645 commented May 8, 2025

@story645 Did you mean to close this?

No sorry, my phone's been a little broken and I was probably looking at this on the app and accidentally closed it w/o noticing ☹️

@QuLogic QuLogic merged commit 6dcfa9d into matplotlib:main May 8, 2025
55 of 64 checks passed
@anntzer anntzer deleted the trnc branch May 8, 2025 19:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants