julia> ccall(:printf, Cint, (Ptr{Cchar}, Cint), "aiai %d", 10);
aiai 10
julia> ccall(:printf, Cint, (Ptr{Cchar}, Cdouble), "aiai %f", 10.99);
aiai 0.000000
The context for this is to reduce invalidations that cause latency.
using SnoopCompile
precompile(plot, (Array{Float64,2},));
tinf = @snoopi tmin=0.01 plot([0.0 0; 1.1 1])
5-element Vector{Tuple{Float64, Core.MethodInstance}}:
(0.015999794006347656, MethodInstance for GMT.check_caller(::Dict{Symbol, Any}, ::String, ::String, ::String, ::String, ::Nothing, ::Bool))
(0.03399991989135742, MethodInstance for hvcat(::Tuple{Int64, Int64}, ::Float64, ::Vararg{Number, N} where N))
(0.0409998893737793, MethodInstance for Printf.format(::Vector{UInt8}, ::Int64, ::Printf.Format{Base.CodeUnits{UInt8, String}, NTuple{4, Printf.Spec{Val{'g'}}}}, ::Float64, ::Vararg{Float64, N} where N))
(0.07500004768371582, MethodInstance for GMT.add_opt(::Dict{Symbol, Any}, ::String, ::Char, ::Matrix{Symbol}, ::Symbol, ::Vector{Union{Nothing, Matrix{Float64}}}, ::NamedTuple{(:outline, :fill), Tuple{String, String}}))
(0.24000000953674316, MethodInstance for Printf.format(::Printf.Format{Base.CodeUnits{UInt8, String}, NTuple{4, Printf.Spec{Val{'g'}}}}, ::Float64, ::Float64, ::Float64, ::Vararg{Float64, N} where N))
So Printf is responsible for some non-negligible invalidation. The above happens in a line with
opt_R = @sprintf(" -R%.12g/%.12g/%.12g/%.12g", info[1].data[1], info[1].data[2],
info[1].data[3], info[1].data[4])
I checked that because if I replace the above with a opt_R = " -R1/2/3/4"
the recompilation goes away. So my idea was to try to access the libc
sprintf
directly but I can’t make it work for floats. only for ints.