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

--trace-compile incorrectly reports only-inferred methods as being re-compiled #56155

Open
topolarity opened this issue Oct 14, 2024 · 2 comments
Labels
bug Indicates an unexpected problem or unintended behavior observability metrics, timing, understandability, reflection, logging, ...
Milestone

Comments

@topolarity
Copy link
Member

topolarity commented Oct 14, 2024

There are times (such as when inlining) when Julia will create a CodeInstance that has no code associated with it.

For example:

using Base.Filesystem: contractuser
mi = methods(contractuser, (String,))[1].specializations::Base.MethodInstance

println("world range: ", (mi.cache.min_world, mi.cache.max_world))
println("invoke, specptr: ", (mi.cache.invoke, mi.cache.specptr))
println("next?: ", (isdefined(mi.cache, :next)))

println(contractuser("")) # trigger compilation

println("world range: ", (mi.cache.min_world, mi.cache.max_world))
println("invoke, specptr: ", (mi.cache.invoke, mi.cache.specptr))
println("next?: ", (isdefined(mi.cache, :next)))

This outputs:

world range: (0x0000000000003f84, 0xffffffffffffffff)
invoke, specptr: (Ptr{Nothing}(0x0000000000000000), Ptr{Nothing}(0x0000000000000000))
next?: false

world range: (0x0000000000003f84, 0xffffffffffffffff)
invoke, specptr: (Ptr{Nothing}(0x00007f6f10b09680), Ptr{Nothing}(0x00007f6f10b09590))
next?: false

which shows that contractuser(::String) was never invalidated (and in fact only has one CodeInstance). It just never had any code associated with it because it was only inferred and then inlined.

However if you run with --trace-compile=compile.log you'll see:

...
precompile(Tuple{typeof(Base.Filesystem.contractuser), String}) # recompile
...

You can see we reported precompile(Tuple{typeof(Base.Filesystem.contractuser), String}) # recompile

@topolarity topolarity added the bug Indicates an unexpected problem or unintended behavior label Oct 14, 2024
@topolarity
Copy link
Member Author

This also affects the "% re-compilation" metric reported in @timed etc.

@nsajko nsajko added the observability metrics, timing, understandability, reflection, logging, ... label Oct 14, 2024
@vtjnash
Copy link
Member

vtjnash commented Oct 16, 2024

Yes, this is an implementation issue that "recompiled" is basically meaningless right now, since is_recompile never actually checks if it was compiled before (invoke is set)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Indicates an unexpected problem or unintended behavior observability metrics, timing, understandability, reflection, logging, ...
Projects
None yet
Development

No branches or pull requests

4 participants