Skip to content

Libdl: Improve inference for string(::LazyLibraryPath) #57721

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

Merged
merged 1 commit into from
Mar 11, 2025

Conversation

topolarity
Copy link
Member

Make this function --trim compatible.

Make this function `--trim` compatible.
@topolarity topolarity added stdlib Julia's standard library trimming Issues with trimming functionality or PR's relevant to its performance/functionality backport 1.12 Change should be backported to release-1.12 labels Mar 11, 2025
@@ -334,7 +334,7 @@ struct LazyLibraryPath
LazyLibraryPath(pieces::Vector) = new(pieces)
end
LazyLibraryPath(args...) = LazyLibraryPath(collect(args))
Base.string(llp::LazyLibraryPath) = joinpath(string.(llp.pieces)...)::String
Base.string(llp::LazyLibraryPath) = joinpath(String[string(p) for p in llp.pieces])
Copy link
Contributor

Choose a reason for hiding this comment

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

Arguably prettier, ignore if you don't agree:

Suggested change
Base.string(llp::LazyLibraryPath) = joinpath(String[string(p) for p in llp.pieces])
Base.string(llp::LazyLibraryPath) = joinpath(collect(String, Iterators.map(string, llp.pieces)))

@nsajko
Copy link
Contributor

nsajko commented Mar 11, 2025

This PR makes the sysimage less vulnerable to invalidation! In particular, comparing with master at a97137e, the change decreases the invalidation count on running struct I <: Integer end; Base.Int(::I) = 7 from 505 to 482 🚀

Some of the fixed invalidations
{
    "method_instance": {
        "method": "restart_copyto_nonleaf!(newdest, dest, bc, val, I, iter, state, count) @ Base.Broadcast broadcast.jl:1089",
        "method_instance": "MethodInstance for Base.Broadcast.restart_copyto_nonleaf!(::Array, ::BitArray, ::Base.Broadcast.Broadcasted, ::Any, ::Int64, ::Base.OneTo, ::Int64, ::Int64)"
    },
    "children": [
        {
            "method_instance": {
                "method": "copyto_nonleaf!(dest, bc::Base.Broadcast.Broadcasted, iter, state, count) @ Base.Broadcast broadcast.jl:1098",
                "method_instance": "MethodInstance for Base.Broadcast.copyto_nonleaf!(::BitVector, ::Base.Broadcast.Broadcasted{Base.Broadcast.DefaultArrayStyle{1}, Tuple{Base.OneTo{Int64}}, typeof(string), <:Tuple{Base.Broadcast.Extruded{T, Tuple{Bool}, Tuple{Int64}} where T<:(Vector)}}, ::Base.OneTo{Int64}, ::Int64, ::Int64)"
            },
            "children": [
                {
                    "method_instance": {
                        "method": "copy(bc::Base.Broadcast.Broadcasted) @ Base.Broadcast broadcast.jl:915",
                        "method_instance": "MethodInstance for copy(::Base.Broadcast.Broadcasted{Base.Broadcast.DefaultArrayStyle{1}, Tuple{Base.OneTo{Int64}}, typeof(string), <:Tuple{Vector}})"
                    },
                    "children": [
                        {
                            "method_instance": {
                                "method": "materialize(bc::Base.Broadcast.Broadcasted) @ Base.Broadcast broadcast.jl:894",
                                "method_instance": "MethodInstance for Base.Broadcast.materialize(::Base.Broadcast.Broadcasted{Base.Broadcast.DefaultArrayStyle{1}, Nothing, typeof(string), <:Tuple{Vector}})"
                            },
                            "children": [
                                {
                                    "method_instance": {
                                        "method": "string(llp::Base.Libc.Libdl.LazyLibraryPath) @ Base.Libc.Libdl libdl.jl:337",
                                        "method_instance": "MethodInstance for string(::Base.Libc.Libdl.LazyLibraryPath)"
                                    },
                                    "children": [
                                    ]
                                }
                            ]
                        }
                    ]
                },
                {
                    "method_instance": {
                        "method": "restart_copyto_nonleaf!(newdest, dest, bc, val, I, iter, state, count) @ Base.Broadcast broadcast.jl:1089",
                        "method_instance": "MethodInstance for Base.Broadcast.restart_copyto_nonleaf!(::BitVector, ::BitVector, ::Base.Broadcast.Broadcasted{Base.Broadcast.DefaultArrayStyle{1}, Tuple{Base.OneTo{Int64}}, typeof(string), <:Tuple{Base.Broadcast.Extruded{T, Tuple{Bool}, Tuple{Int64}} where T<:(Vector)}}, ::Any, ::Int64, ::Base.OneTo{Int64}, ::Int64, ::Int64)"
                    },
                    "children": [
                        {
                            "method_instance": {
                                "method": "copyto_nonleaf!(dest, bc::Base.Broadcast.Broadcasted, iter, state, count) @ Base.Broadcast broadcast.jl:1098",
                                "method_instance": "MethodInstance for Base.Broadcast.copyto_nonleaf!(::BitVector, ::Base.Broadcast.Broadcasted{Base.Broadcast.DefaultArrayStyle{1}, Tuple{Base.OneTo{Int64}}, typeof(string), <:Tuple{Base.Broadcast.Extruded{T, Tuple{Bool}, Tuple{Int64}} where T<:(Vector)}}, ::Base.OneTo{Int64}, ::Int64, ::Int64)"
                            },
                            "children": [
                            ]
                        }
                    ]
                }
            ]
        }
    ]
}
{
    "method_instance": {
        "method": "_broadcast_getindex_evalf(f::Tf, args::Vararg{Any, N}) where {Tf, N} @ Base.Broadcast broadcast.jl:699",
        "method_instance": "MethodInstance for Base.Broadcast._broadcast_getindex_evalf(::typeof(Base.wrap_string), ::AbstractString, ::UInt32)"
    },
    "children": [
        {
            "method_instance": {
                "method": "_broadcast_getindex(bc::Base.Broadcast.Broadcasted{<:Any, <:Any, <:Any, <:Any}, I) @ Base.Broadcast broadcast.jl:670",
                "method_instance": "MethodInstance for Base.Broadcast._broadcast_getindex(::Base.Broadcast.Broadcasted{Base.Broadcast.DefaultArrayStyle{0}, Nothing, typeof(Base.wrap_string), <:Tuple{Tuple{AbstractString}, Base.RefValue{UInt32}}}, ::CartesianIndex{0})"
            },
            "children": [
                {
                    "method_instance": {
                        "method": "_getindex(::IndexStyle, bc, I) @ Base.Broadcast broadcast.jl:618",
                        "method_instance": "MethodInstance for Base.Broadcast._getindex(::IndexCartesian, ::Base.Broadcast.Broadcasted{Base.Broadcast.DefaultArrayStyle{0}, Nothing, typeof(Base.wrap_string), <:Tuple{Tuple{AbstractString}, Base.RefValue{UInt32}}}, ::CartesianIndex{0})"
                    },
                    "children": [
                        {
                            "method_instance": {
                                "method": "getindex(bc::Base.Broadcast.Broadcasted, Is::Vararg{Union{Integer, CartesianIndex}, N}) where N @ Base.Broadcast broadcast.jl:614",
                                "method_instance": "MethodInstance for getindex(::Base.Broadcast.Broadcasted{Base.Broadcast.DefaultArrayStyle{0}, Nothing, typeof(Base.wrap_string), <:Tuple{Tuple{AbstractString}, Base.RefValue{UInt32}}}, ::CartesianIndex{0})"
                            },
                            "children": [
                                {
                                    "method_instance": {
                                        "method": "copy(bc::Base.Broadcast.Broadcasted{<:Base.Broadcast.AbstractArrayStyle{0}}) @ Base.Broadcast broadcast.jl:909",
                                        "method_instance": "MethodInstance for copy(::Base.Broadcast.Broadcasted{Base.Broadcast.DefaultArrayStyle{0}, Nothing, typeof(Base.wrap_string), <:Tuple{Tuple{AbstractString}, Base.RefValue{UInt32}}})"
                                    },
                                    "children": [
                                        {
                                            "method_instance": {
                                                "method": "materialize(bc::Base.Broadcast.Broadcasted) @ Base.Broadcast broadcast.jl:894",
                                                "method_instance": "MethodInstance for Base.Broadcast.materialize(::Base.Broadcast.Broadcasted{Base.Broadcast.DefaultArrayStyle{0}, Nothing, typeof(Base.wrap_string), <:Tuple{Tuple{AbstractString}, Base.RefValue{UInt32}}})"
                                            },
                                            "children": [
                                                {
                                                    "method_instance": {
                                                        "method": "*(r1::Union{Regex, AbstractChar, AbstractString}, rs::Union{Regex, AbstractChar, AbstractString}...) @ Base regex.jl:840",
                                                        "method_instance": "MethodInstance for *(::Union{Regex, AbstractChar, AbstractString}, ::AbstractString)"
                                                    },
                                                    "children": [
                                                        {
                                                            "method_instance": {
                                                                "method": "joinpath(paths::Union{Tuple, AbstractVector}) @ Base.Filesystem path.jl:324",
                                                                "method_instance": "MethodInstance for joinpath(::Union{Tuple, AbstractVector})"
                                                            },
                                                            "children": [
                                                            ]
                                                        }
                                                    ]
                                                }
                                            ]
                                        }
                                    ]
                                }
                            ]
                        }
                    ]
                }
            ]
        },
        {
            "method_instance": {
                "method": "_broadcast_getindex(bc::Base.Broadcast.Broadcasted{<:Any, <:Any, <:Any, <:Any}, I) @ Base.Broadcast broadcast.jl:670",
                "method_instance": "MethodInstance for Base.Broadcast._broadcast_getindex(::Base.Broadcast.Broadcasted{Base.Broadcast.Style{Tuple}, Nothing, typeof(Base.wrap_string), <:Tuple{Tuple{AbstractString}, Base.RefValue{UInt32}}}, ::Int64)"
            },
            "children": [
                {
                    "method_instance": {
                        "method": "(::Base.Broadcast.var\"#copy##0#copy##1\")(k) @ Base.Broadcast broadcast.jl:1124",
                        "method_instance": "MethodInstance for (::Base.Broadcast.var\"#copy##0#copy##1\"{Base.Broadcast.Broadcasted{Base.Broadcast.Style{Tuple}, Nothing, typeof(Base.wrap_string), var\"#s179\"}} where var\"#s179\"<:Tuple{Tuple{AbstractString}, Base.RefValue{UInt32}})(::Int64)"
                    },
                    "children": [
                        {
                            "method_instance": {
                                "method": "ntuple(f, ::Val{1}) @ Base ntuple.jl:50",
                                "method_instance": "MethodInstance for ntuple(::Base.Broadcast.var\"#copy##0#copy##1\"{Base.Broadcast.Broadcasted{Base.Broadcast.Style{Tuple}, Nothing, typeof(Base.wrap_string), var\"#s179\"}} where var\"#s179\"<:Tuple{Tuple{AbstractString}, Base.RefValue{UInt32}}, ::Val{1})"
                            },
                            "children": [
                                {
                                    "method_instance": {
                                        "method": "copy(bc::Base.Broadcast.Broadcasted{Base.Broadcast.Style{Tuple}}) @ Base.Broadcast broadcast.jl:1120",
                                        "method_instance": "MethodInstance for copy(::Base.Broadcast.Broadcasted{Base.Broadcast.Style{Tuple}, Nothing, typeof(Base.wrap_string), <:Tuple{Tuple{AbstractString}, Base.RefValue{UInt32}}})"
                                    },
                                    "children": [
                                        {
                                            "method_instance": {
                                                "method": "materialize(bc::Base.Broadcast.Broadcasted) @ Base.Broadcast broadcast.jl:894",
                                                "method_instance": "MethodInstance for Base.Broadcast.materialize(::Base.Broadcast.Broadcasted{Base.Broadcast.Style{Tuple}, Nothing, typeof(Base.wrap_string), <:Tuple{Tuple{AbstractString}, Base.RefValue{UInt32}}})"
                                            },
                                            "children": [
                                                {
                                                    "method_instance": {
                                                        "method": "*(r1::Union{Regex, AbstractChar, AbstractString}, rs::Union{Regex, AbstractChar, AbstractString}...) @ Base regex.jl:840",
                                                        "method_instance": "MethodInstance for *(::Union{Regex, AbstractChar, AbstractString}, ::AbstractString)"
                                                    },
                                                    "children": [
                                                    ]
                                                }
                                            ]
                                        }
                                    ]
                                }
                            ]
                        }
                    ]
                }
            ]
        }
    ]
}

@nsajko nsajko added the backport 1.11 Change should be backported to release-1.11 label Mar 11, 2025
@nsajko
Copy link
Contributor

nsajko commented Mar 11, 2025

It'd be nice if this could be backported to v1.11, too, to prevent the invalidation.

@topolarity topolarity merged commit 8edc2b3 into JuliaLang:master Mar 11, 2025
12 checks passed
KristofferC pushed a commit that referenced this pull request Mar 20, 2025
Make this function `--trim` compatible.

(cherry picked from commit 8edc2b3)
@KristofferC KristofferC removed the backport 1.12 Change should be backported to release-1.12 label Mar 24, 2025
KristofferC pushed a commit that referenced this pull request Mar 31, 2025
Make this function `--trim` compatible.

(cherry picked from commit 8edc2b3)
@KristofferC KristofferC mentioned this pull request Mar 31, 2025
71 tasks
@KristofferC KristofferC removed the backport 1.11 Change should be backported to release-1.11 label Apr 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
invalidations stdlib Julia's standard library trimming Issues with trimming functionality or PR's relevant to its performance/functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants