Skip to content

Conversation

@nsajko
Copy link
Member

@nsajko nsajko commented Sep 2, 2025

The generic method size(::AbstractArray, ::Any) currently has:

  • method static parameters

  • an abstract type assert (::Integer) in the method body

PR #59442 aims to make this generic method be used for Array and Memory, by deleting the more specific methods.

It is my understanding that method static parameters and abstract type asserts can cause performance issues, when they're not optimized out, which happens when the argument types are not concretely inferred.

So I'm putting up this PR, which eliminates the method static parameters and the typeassert, to prevent any possible regressions from PR #59442.

Another thing that is necessary for preserving good abstract inference is to convert the index argument to Int before using it. This is correct as there can't be more than typemax(Int) dimensions anyway (the N type parameter to AbstractArray is an Int value).

@nsajko
Copy link
Member Author

nsajko commented Sep 2, 2025

Indeed, this PR is a prerequisite for PR #59442. Otherwise three of these effect inference tests fail:

let effects = Base.infer_effects(size, (Array,Int))
@test Compiler.is_consistent_if_inaccessiblememonly(effects)
@test Compiler.is_effect_free(effects)
@test !Compiler.is_nothrow(effects)
@test Compiler.is_terminates(effects)
end

@nsajko nsajko marked this pull request as ready for review September 2, 2025 17:47
@nsajko nsajko force-pushed the size_AbstractArray branch from 701c909 to 94abb7f Compare September 3, 2025 14:04
nsajko added a commit to nsajko/julia that referenced this pull request Sep 3, 2025
The generic method `size(::AbstractArray, ::Any)` currently has:

* method static parameters

* an abstract type assert (`::Integer`) in the method body

PR JuliaLang#59442 aims to make this generic method be used for `Array` and
`Memory`, by deleting the more specific methods.

It is my understanding that method static parameters and abstract type
asserts can cause performance issues, when they're not optimized out,
which happens when the argument types are not concretely inferred.

So I'm putting up this PR, which eliminates the method static
parameters and the `typeassert`, to prevent any possible regressions
from PR JuliaLang#59442.

Another thing that is necessary for preserving good abstract inference
is to convert the index to `Int` before using it. This is correct
it there can't be more than `typemax(Int)` dimensions anyway.

(cherry picked from PR JuliaLang#59465)
nsajko added a commit to nsajko/julia that referenced this pull request Sep 3, 2025
The generic method `size(::AbstractArray, ::Any)` currently has:

* method static parameters

* an abstract type assert (`::Integer`) in the method body

PR JuliaLang#59442 aims to make this generic method be used for `Array` and
`Memory`, by deleting the more specific methods.

It is my understanding that method static parameters and abstract type
asserts can cause performance issues, when they're not optimized out,
which happens when the argument types are not concretely inferred.

So I'm putting up this PR, which eliminates the method static
parameters and the `typeassert`, to prevent any possible regressions
from PR JuliaLang#59442.

Another thing that is necessary for preserving good abstract inference
is to convert the index to `Int` before using it. This is correct
it there can't be more than `typemax(Int)` dimensions anyway.

(cherry picked from PR JuliaLang#59465)
nsajko added a commit to nsajko/julia that referenced this pull request Sep 3, 2025
The generic method `size(::AbstractArray, ::Any)` currently has:

* method static parameters

* an abstract type assert (`::Integer`) in the method body

PR JuliaLang#59442 aims to make this generic method be used for `Array` and
`Memory`, by deleting the more specific methods.

It is my understanding that method static parameters and abstract type
asserts can cause performance issues, when they're not optimized out,
which happens when the argument types are not concretely inferred.

So I'm putting up this PR, which eliminates the method static
parameters and the `typeassert`, to prevent any possible regressions
from PR JuliaLang#59442.

Another thing that is necessary for preserving good abstract inference
is to convert the index to `Int` before using it. This is correct
it there can't be more than `typemax(Int)` dimensions anyway.

(cherry picked from PR JuliaLang#59465)
@nsajko nsajko force-pushed the size_AbstractArray branch from 8302694 to 4f3b8c2 Compare September 3, 2025 15:22
nsajko added a commit to nsajko/julia that referenced this pull request Sep 3, 2025
The generic method `size(::AbstractArray, ::Any)` currently has:

* method static parameters

* an abstract type assert (`::Integer`) in the method body

PR JuliaLang#59442 aims to make this generic method be used for `Array` and
`Memory`, by deleting the more specific methods.

It is my understanding that method static parameters and abstract type
asserts can cause performance issues, when they're not optimized out,
which happens when the argument types are not concretely inferred.

So I'm putting up this PR, which eliminates the method static
parameters and the `typeassert`, to prevent any possible regressions
from PR JuliaLang#59442.

Another thing that is necessary for preserving good abstract inference
is to convert the index to `Int` before using it. This is correct
it there can't be more than `typemax(Int)` dimensions anyway.

(cherry picked from PR JuliaLang#59465)
nsajko added a commit to nsajko/julia that referenced this pull request Sep 3, 2025
The generic method `size(::AbstractArray, ::Any)` currently has:

* method static parameters

* an abstract type assert (`::Integer`) in the method body

PR JuliaLang#59442 aims to make this generic method be used for `Array` and
`Memory`, by deleting the more specific methods.

It is my understanding that method static parameters and abstract type
asserts can cause performance issues, when they're not optimized out,
which happens when the argument types are not concretely inferred.

So I'm putting up this PR, which eliminates the method static
parameters and the `typeassert`, to prevent any possible regressions
from PR JuliaLang#59442.

Another thing that is necessary for preserving good abstract inference
is to convert the index to `Int` before using it. This is correct
it there can't be more than `typemax(Int)` dimensions anyway.

(cherry picked from PR JuliaLang#59465)
@nsajko
Copy link
Member Author

nsajko commented Sep 5, 2025

bump

@nsajko
Copy link
Member Author

nsajko commented Sep 9, 2025

ping

Copy link
Member

@vtjnash vtjnash left a comment

Choose a reason for hiding this comment

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

I don't like this. It changes clear code into a mess. Changing to simplified code like this would be okay though:

function size(t::AbstractArray, dim)
    d = Int(dim)::Int
    s = size(t)
    d <= length(s) ? s[d] : 1
end

@nsajko nsajko force-pushed the size_AbstractArray branch from a4f8310 to 4ae27ee Compare September 9, 2025 16:19
@nsajko
Copy link
Member Author

nsajko commented Sep 23, 2025

bump? or merge PR #59512?

nsajko and others added 3 commits September 23, 2025 15:40
The generic method `size(::AbstractArray, ::Any)` currently has:

* method static parameters

* an abstract type assert (`::Integer`) in the method body

PR JuliaLang#59442 aims to make this generic method be used for `Array` and
`Memory`, by deleting the more specific methods.

It is my understanding that method static parameters and abstract type
asserts can cause performance issues, when they're not optimized out,
which happens when the argument types are not concretely inferred.

So I'm putting up this PR, which eliminates the method static
parameters and the `typeassert`, to prevent any possible regressions
from PR JuliaLang#59442.

Another thing that is necessary for preserving good abstract inference
is to convert the index to `Int` before using it. This is correct
it there can't be more than `typemax(Int)` dimensions anyway.
Now this PR changes behavior: non-`Integer` values are allowed for the
second argument as long as they are convertible to `Int`.
Co-authored-by: Jeff Bezanson <jeff.bezanson@gmail.com>
@nsajko
Copy link
Member Author

nsajko commented Sep 26, 2025

@vtjnash your suggestion was implemented, however your negative review is still around. Also, there's now an approval. Can you take a look again?

@vtjnash vtjnash self-requested a review September 26, 2025 18:05
@vtjnash vtjnash merged commit 0551b2f into JuliaLang:master Sep 26, 2025
7 checks passed
@nsajko nsajko deleted the size_AbstractArray branch September 26, 2025 19:23
oscardssmith pushed a commit that referenced this pull request Sep 27, 2025
Changes:

* Eliminate some nongeneric `length` methods:

    * `GenericMemory`

    * `Slice`

    * `IdentityUnitRange`

    * `CartesianIndices`

    * `LogicalIndex`

    * `CodeUnits`

    * `UnsafeView` (from the `Random` stdlib)

* Eliminate some nongeneric two-argument `size` methods:

    *  `GenericMemory`

    * `Array`

    * `BitVector`

Depends on PR #59465 to prevent abstract inference regressions.
xal-0 pushed a commit to xal-0/julia that referenced this pull request Sep 30, 2025
…rt (JuliaLang#59465)

The generic method `size(::AbstractArray, ::Any)` currently has:

* method static parameters
* an abstract type assert (`::Integer`) in the method body

PR JuliaLang#59442 aims to make this generic method be used for `Array` and
`Memory`, by deleting the more specific methods.

It is my understanding that method static parameters and abstract type
asserts can cause performance issues, when they're not optimized out,
which happens when the argument types are not concretely inferred.

So I'm putting up this PR, which eliminates the method static parameters
and the `typeassert`, to prevent any possible regressions from PR
JuliaLang#59442.

Another thing that is necessary for preserving good abstract inference
is to convert the index argument to `Int` before using it. This is
correct as there can't be more than `typemax(Int)` dimensions anyway
(the `N` type parameter to `AbstractArray` is an `Int` value).
xal-0 pushed a commit to xal-0/julia that referenced this pull request Sep 30, 2025
…9442)

Changes:

* Eliminate some nongeneric `length` methods:

    * `GenericMemory`

    * `Slice`

    * `IdentityUnitRange`

    * `CartesianIndices`

    * `LogicalIndex`

    * `CodeUnits`

    * `UnsafeView` (from the `Random` stdlib)

* Eliminate some nongeneric two-argument `size` methods:

    *  `GenericMemory`

    * `Array`

    * `BitVector`

Depends on PR JuliaLang#59465 to prevent abstract inference regressions.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

arrays [a, r, r, a, y, s]

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants