Skip to content

avoid method proliferation for Tuple functions#59421

Open
nsajko wants to merge 14 commits intoJuliaLang:masterfrom
nsajko:avoid_method_proliferation_for_Tuple_functions
Open

avoid method proliferation for Tuple functions#59421
nsajko wants to merge 14 commits intoJuliaLang:masterfrom
nsajko:avoid_method_proliferation_for_Tuple_functions

Conversation

@nsajko
Copy link
Copy Markdown
Member

@nsajko nsajko commented Aug 28, 2025

Motivation:

  • Introducing new types and methods for a callable can invalidate already compiled method instances of a function for which world-splitting is enabled (max_methods).

  • Invalidation of sysimage or package precompiled code worsens latency due to requiring recompilation.

  • Lowering the max_methods setting for a function often causes inference issues for existing code that is not completely type-stable (which is a lot of code). In many cases this is easy to fix by avoiding method proliferation, such as by merging some methods and introducing branching into the merged method.

This PR aims to fix the latter issue for some Tuple-related methods of some functions where decreasing max_methods might be interesting.

This PR is a prerequisite for PRs which try to decrease max_methods for select functions, such as PR:

@nsajko nsajko force-pushed the avoid_method_proliferation_for_Tuple_functions branch 7 times, most recently from 89ebaa7 to 32f6824 Compare August 28, 2025 16:51
@nsajko nsajko marked this pull request as ready for review August 30, 2025 13:46
@nsajko nsajko marked this pull request as draft January 25, 2026 10:31
* Introducing new types and methods for a callable can invalidate
  already compiled method instances of a function for which
  world-splitting is enabled (`max_methods`).

* Invalidation of sysimage or package precompiled code worsens latency
  due to requiring recompilation.

* Lowering the `max_methods` setting for a function often causes
  inference issues for existing code that is not completely
  type-stable (which is a lot of code). In many cases this is easy to
  fix by avoiding method proliferation, such as by merging some methods
  and introducing branching into the merged method.

This PR aims to fix the latter issue for some `Tuple`-related methods
of some functions where decreasing `max_methods` might be interesting.

Seeing as branching was deliberately avoided in the bodies of many of
these methods, I opted for the approach of introducing local functions
which preserve the dispatch logic as before, without branching. Thus
there should be no regressions, except perhaps because of changed
inlining costs.

This PR is a prerequisite for PRs which try to decrease `max_methods`
for select functions, such as PR:

* JuliaLang#59377
@nsajko nsajko force-pushed the avoid_method_proliferation_for_Tuple_functions branch from 56b2887 to 0b1bc8d Compare January 25, 2026 10:34
@nsajko nsajko marked this pull request as ready for review January 25, 2026 12:56
@nsajko
Copy link
Copy Markdown
Member Author

nsajko commented Jan 25, 2026

Changed the PR to rely on branching more, as suggested.

nsajko added a commit to nsajko/julia that referenced this pull request Jan 29, 2026
nsajko added a commit to nsajko/julia that referenced this pull request Jan 30, 2026
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.

4 participants