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

Speed up replace and canonicalize by improving type stability #2613

Merged
merged 9 commits into from
Apr 17, 2024

Conversation

SebastianM-C
Copy link
Contributor

@SebastianM-C SebastianM-C commented Apr 4, 2024

Checklist

  • Appropriate tests were added
  • Any code changes were done in a way that does not break public API
  • All documentation related to code changes were updated
  • The new code follows the
    contributor guidelines, in particular the SciML Style Guide and
    COLPRAC.
  • Any new documentation only uses public API

Additional context

This PR attempts to fix #2608 by avoiding boxing and runtime dispatch. So far this works for the case of homogeneous parameters, but for heterogeneous ones, we end up iterating over a tuple of different types, which is unstable.

@SebastianM-C SebastianM-C changed the title [WIP] Speed up replace and canonicalize by improving type stability Speed up replace and canonicalize by improving type stability Apr 16, 2024
@SebastianM-C
Copy link
Contributor Author

I fixed a few more cases and added tests with JET and @inferred for replace/replace!. For canonicalize there are some cases which can't be inferred due to storing things in vectors, but that could potentially be addressed in the future with a vector type that stores its size in the type domain. I was a bit surprised that replace avoids the issue, but I think that the main factor is that we're effectively unrolling the iterations at compile time.

I think that this should not increase compile times as the tuples are used for the number of types, so we don't expect a ridiculous number of types in the portions.

Copy link
Member

@AayushSabharwal AayushSabharwal left a comment

Choose a reason for hiding this comment

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

LGTM!

@ChrisRackauckas ChrisRackauckas merged commit 335c7ba into SciML:master Apr 17, 2024
17 of 24 checks passed
@SebastianM-C SebastianM-C deleted the speed branch April 17, 2024 19:14
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.

Make replace of MTKParameters type-stable
3 participants