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

bpart: Track whether any binding replacement has happened in image modules #57433

Merged
merged 1 commit into from
Feb 17, 2025

Conversation

Keno
Copy link
Member

@Keno Keno commented Feb 17, 2025

This implements the optimization proposed in #57426 by keeping track of whether any bindings were replaced in image modules (excluding Main as facilitated by #57426). In addition, we augment serialization to keep track of whether a method body contains any GlobalRefs that point to a loaded (system or package) image. If both of these flags are true, we can skip scanning the body of the method, since we know that we neither need to add any additional backedges nor were any of the referenced bindings invalidated. The performance impact on end-to-end load time is small, but measurable. Overall @time using ModelingToolkit consistently improves about 5% using this PR. However, I should note that using time is still about 40% slower than 1.11. This is not necessarily an Apples-to-Apples comparison as there were substantial other changes on 1.12 (as well as current load-time-tunings targeting older versions), but I wanted to put the number context.

…dules

This implements the optimization proposed in #57426 by keeping track of whether
any bindings were replaced in image modules (excluding `Main` as facilitated by #57426).
In addition, we augment serialization to keep track of whether a method body contains
any GlobalRefs that point to a loaded (system or package) image. If both of these
flags are true, we can skip scanning the body of the method, since we know that we
neither need to add any additional backedges nor were any of the referenced bindings
invalidated. The performance impact on end-to-end load time is small, but measurable.
Overall `@time using ModelingToolkit` consistently improves about 5% using this PR.
However, I should note that using time is still about 40% slower than 1.11. This
is not necessarily an Apples-to-Apples comparison as there were substantial other
changes on 1.12 (as well as current load-time-tunings targeting older versions),
but I wanted to put the number context.
@Keno Keno merged commit f6e2b98 into master Feb 17, 2025
7 checks passed
@Keno Keno deleted the kf/partitionoptload branch February 17, 2025 06:24
@KristofferC KristofferC added the backport 1.12 Change should be backported to release-1.12 label Feb 17, 2025
KristofferC pushed a commit that referenced this pull request Feb 17, 2025
…dules (#57433)

This implements the optimization proposed in #57426 by keeping track of
whether any bindings were replaced in image modules (excluding `Main` as
facilitated by #57426). In addition, we augment serialization to keep
track of whether a method body contains any GlobalRefs that point to a
loaded (system or package) image. If both of these flags are true, we
can skip scanning the body of the method, since we know that we neither
need to add any additional backedges nor were any of the referenced
bindings invalidated. The performance impact on end-to-end load time is
small, but measurable. Overall `@time using ModelingToolkit`
consistently improves about 5% using this PR. However, I should note
that using time is still about 40% slower than 1.11. This is not
necessarily an Apples-to-Apples comparison as there were substantial
other changes on 1.12 (as well as current load-time-tunings targeting
older versions), but I wanted to put the number context.

(cherry picked from commit f6e2b98)
@KristofferC KristofferC mentioned this pull request Feb 17, 2025
15 tasks
@@ -25,7 +25,8 @@ end
function insert_backedges(edges::Vector{Any}, ext_ci_list::Union{Nothing,Vector{Any}}, extext_methods::Vector{Any}, internal_methods::Vector{Any})
# determine which CodeInstance objects are still valid in our image
# to enable any applicable new codes
methods_with_invalidated_source = Base.scan_new_methods(extext_methods, internal_methods)
backedges_only = unsafe_load(cglobal(:jl_first_image_replacement_world, UInt)) == typemax(UInt)
Copy link
Member

Choose a reason for hiding this comment

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

unsafe_load requires an atomic ordering specifier to access mutable data (this can be strong UB here without it, as we define unsafe_load to be a memcpy and not a unordered load)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport 1.12 Change should be backported to release-1.12
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants