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

PERF: reduce startup overhead from cmap registration #4538

Closed
wants to merge 2 commits into from

Conversation

neutrinoceros
Copy link
Member

PR Summary

another, maybe more aggressive attempt at minimising startup overhead from colormaps registration (2nd take following #4520)

@neutrinoceros neutrinoceros added performance enhancement Making something better labels Jun 25, 2023
@neutrinoceros neutrinoceros added the deprecation deprecate features or remove deprecated ones label Jun 25, 2023
@neutrinoceros neutrinoceros force-pushed the faster_cmaps branch 2 times, most recently from 2b5153e to 24ad119 Compare June 26, 2023 08:19
from matplotlib.colors import LinearSegmentedColormap

issue_deprecation_warning(
"yt.visualization.color_maps.add_colormap is deprecated",
Copy link
Member

Choose a reason for hiding this comment

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

what is it being replaced with?

Copy link
Member Author

Choose a reason for hiding this comment

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

nothing, it's not strictly needed !

try:
add_colormap(k, cdict)
mpl.colormaps.register(ListedColormap(v, name=k, N=256))
Copy link
Member

Choose a reason for hiding this comment

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

I mean, this is slightly flatter, but I don't think it's a big deal, either.

Copy link
Member Author

Choose a reason for hiding this comment

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

yeah, this PR yields disappointing results, but just in case, I want to clarify that the gain here is not expected to come from the inlining, but from instantiating ListedColormap instead of LinearSegmentedColormap, which saves a conversion from the format we actually define our maps in.

Copy link
Member Author

Choose a reason for hiding this comment

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

any way #4538 and #4517 are both much more efficient at reducing the startup time, I really don't mind if we end up just closing this one.

cmap.name = hist_name
mpl.colormaps.register(cmap)
mpl.colormaps.register(cmap.reversed())
cmap = mpl.colormaps[alias]
Copy link
Member Author

Choose a reason for hiding this comment

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

note for later that this even if we close this PR, this line change is worth using if only because mpl.colormaps.__getitem__ already returns copies, so the current implementation of this line is unjustified.

@neutrinoceros
Copy link
Member Author

I'll drop this (again) because it's far too big a patch for such a small gain. I'll reopen a much smaller PR with just the simplest avoid-double-copies patch (which impacts 2 lines)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
deprecation deprecate features or remove deprecated ones enhancement Making something better performance
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants