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

PR: Performance improvements to colour.SpectralDistribution.wavelengths property and various definitions in colour.utilities.array module. #1067

Merged
merged 6 commits into from Nov 17, 2022

Conversation

tjdcs
Copy link
Contributor

@tjdcs tjdcs commented Nov 14, 2022

Summary

This PR makes small changes to improve the performance of several critical paths that are found throughout the code base. For example, tsplit and tstack are called very often. Additionally, the shape getter of SpectralDistribution is called very often in code that is manipulating spectral data. In one example calculating color rendering simulations, calling the .shape getter was responsible for around 10% of total execution time, but is now responsible for less than 0.1%

The particular examples that found these critical paths are not expected to be representative of all performance cases, none the less nearly all applications of colour-science should see some benefit.

Preflight

Code Style and Quality

  • Unit tests have been implemented and passed.
  • Mypy static checking has been run and passed.
  • Pre-commit hooks have been run and passed.
  • [N/A] New transformations have been added to the Automatic Colour Conversion Graph.
  • [N/A] New transformations have been exported to the relevant namespaces, e.g. colour, colour.models.

Documentation

  • [N/A] New features are documented along with examples if relevant.
  • [N/A] The documentation is Sphinx and numpydoc compliant.

.shape gets called a lot, and computing the min is slow
np.diff was slower. This is 250% than previous (timeit, default spectral shape)
@tjdcs tjdcs requested a review from KelSolaar November 14, 2022 02:11
@tjdcs tjdcs changed the title Performance/spectralditribution.shape Performance improvements to core SpectralDisribution and array.py Nov 14, 2022
@KelSolaar KelSolaar changed the title Performance improvements to core SpectralDisribution and array.py PR: Performance improvements to colour.SpectralDistribution.wavelengths property and various definitions in colour.utilities.array module. Nov 14, 2022
Copy link
Member

@KelSolaar KelSolaar left a comment

Choose a reason for hiding this comment

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

Thank you! I left a few minor notes but LGTM otherwise!

colour/utilities/array.py Show resolved Hide resolved
colour/utilities/array.py Show resolved Hide resolved
colour/utilities/array.py Show resolved Hide resolved
colour/utilities/array.py Show resolved Hide resolved
colour/colorimetry/spectrum.py Outdated Show resolved Hide resolved
colour/colorimetry/spectrum.py Outdated Show resolved Hide resolved
@tjdcs tjdcs requested a review from KelSolaar November 16, 2022 19:22
@KelSolaar KelSolaar merged commit ea51d7b into develop Nov 17, 2022
@KelSolaar KelSolaar added this to the v0.4.2 milestone Nov 18, 2022
@KelSolaar KelSolaar deleted the performance/spectralditribution.shape branch November 19, 2022 18:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants