Hello,
As the TTFX has become significant in one of my projects,
I tried to implement PrecompileTools to reduce it.
However, there was no significant reduction in the TTFX.
Below is a MNWE representing how I attempted to implement
PrecompileTools:
# test_PrecompileTools.jl
using PrecompileTools
include("test_PC_math_operations.jl")
using .MathOperations: scale_and_sum
function main()
println("Data initialization")
println("")
scalar_1 = 10.0
scalar_2 = 1.0
vctr = rand(Float64, 10_000_000)
# First execution
print("First call:")
@time result_1 = scale_and_sum(scalar_1, scalar_2, vctr)
println("Result: ", result_1)
println("")
# Second execution
print("Second call:")
@time result_2 = scale_and_sum(scalar_1, scalar_2, vctr)
println("Result: ", result_2)
end
begin
main()
end
which calls
# test_PC_math_operations.jl
module MathOperations
using PrecompileTools
PrecompileTools.verbose[] = true
export scale_and_sum
function scale_and_sum(scalar_1::Float64, scalar_2::Float64, vctr::Vector{Float64})
result = 0.0
for val in vctr
result += val * scalar_1 + scalar_2
end
return result
end
# PrecompileTools block
@setup_workload begin
dummy_scalar_1 = 1.0
dummy_scalar_2 = 1.0
dummy_vector = rand(Float64, 10)
@compile_workload begin
scale_and_sum(dummy_scalar_1, dummy_scalar_2, dummy_vector)
end
end
end # module MathOperations
In VS Code, I first use Ctrl P to clear the compiled Julia modules and functions.
I then start Julia and execute the scripts.
First run output:
julia> include("test_PrecompileTools.jl")
MethodInstance for scale_and_sum(::Float64, ::Float64, ::Vector{Float64})
MethodInstance for PrecompileTools.tag_newly_inferred_disable()
Data initialization
First call: 0.011713 seconds
Result: 6.000131988730281e7
Second call: 0.012140 seconds
Result: 6.000131988730281e7
No difference in the execution time between the First and Second call.
When I execute the scripts a second time:
Julia> include("test_PrecompileTools.jl")
MethodInstance for scale_and_sum(::Float64, ::Float64, ::Vector{Float64})
MethodInstance for PrecompileTools.tag_newly_inferred_disable()
MethodInstance for scale_and_sum(::Float64, ::Float64, ::Vector{Float64})
WARNING: ignoring conflicting import of MathOperations.scale_and_sum into Main
Data initialization
First call: 0.011959 seconds
Result: 5.9982883771461785e7
Second call: 0.012122 seconds
Result: 5.9982883771461785e7
WARNING: ignoring conflicting import of MathOperations.scale_and_sum into Main
is generated.
My understanding is the precompiled files should be stored in
~/.julia/compiled/v1.13
However, when I look in this directory, no MathOperations
subdirectory has been created.
Check the location of the primary depot path
joinpath(DEPOT_PATH\[1\], "compiled")
~/.julia/compiled
System:
Julia v1.13.3
PrecompileTools v1.4.0
Revise v3.18.0
WSL2
WSL version: 3.0.5.0
Kernel version: 6.18.58.1-1
WSLg version: 1.0.79
Ubuntu 26.04.1 LTS
Any advance as to what I am missing would be appreciated.