Skip to content

Commit

Permalink
Improve precompiles (#1634)
Browse files Browse the repository at this point in the history
* Small inferrability improvement

* Improve the precompiles

This gets away from the gensymmed functions and instead
executes code to force compilation.

Co-authored-by: Simon <[email protected]>
  • Loading branch information
timholy and SimonDanisch authored Feb 14, 2022
1 parent 76f25f6 commit bfabbaf
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 37 deletions.
14 changes: 7 additions & 7 deletions GLMakie/src/drawing_primitives.jl
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ end
function draw_atomic(screen::GLScreen, scene::Scene,
x::Text{<:Tuple{<:Union{<:Makie.GlyphCollection, <:AbstractVector{<:Makie.GlyphCollection}}}})

robj = cached_robj!(screen, scene, x) do gl_attributes
return cached_robj!(screen, scene, x) do gl_attributes
glyphcollection = x[1]


Expand Down Expand Up @@ -344,17 +344,17 @@ function draw_atomic(screen::GLScreen, scene::Scene,
gl_attributes[:uv_offset_width] = uv_offset_width
gl_attributes[:distancefield] = get_texture!(atlas)
gl_attributes[:visible] = x.visible
robj = GLVisualize.draw_scatter((DISTANCEFIELD, positions), gl_attributes)
# Avoid julia#15276
_robj = GLVisualize.draw_scatter((DISTANCEFIELD, positions), gl_attributes)
# Draw text in screenspace
if x.space[] == :screen
robj[:view] = Observable(Mat4f(I))
robj[:projection] = scene.camera.pixel_space
robj[:projectionview] = scene.camera.pixel_space
_robj[:view] = Observable(Mat4f(I))
_robj[:projection] = scene.camera.pixel_space
_robj[:projectionview] = scene.camera.pixel_space
end

return robj
return _robj
end
return robj
end

# el32convert doesn't copy for array of Float32
Expand Down
50 changes: 25 additions & 25 deletions GLMakie/src/precompile.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,29 @@ function _precompile_()
ccall(:jl_generating_output, Cint, ()) == 1 || return nothing
precompile(Makie.backend_display, (GLBackend, Scene))

# These are awful and will go stale as gensyms change (check by putting `@assert` in front of each one).
# It would be far better to fix the inference problems.
isdefined(GLMakie, Symbol("#89#90")) && Base.precompile(Tuple{getfield(GLMakie, Symbol("#89#90")),Text{Tuple{String}}}) # time: 1.7054044
isdefined(GLMakie, Symbol("#72#78")) && Base.precompile(Tuple{getfield(GLMakie, Symbol("#72#78")),SMatrix{4, 4, Float32, 16},SMatrix{4, 4, Float32, 16}}) # time: 0.18958463
isdefined(GLMakie, Symbol("#44#46")) && Base.precompile(Tuple{getfield(GLMakie, Symbol("#44#46")),GLFW.Window}) # time: 0.098638594
isdefined(GLMakie, Symbol("#81#82")) && Base.precompile(Tuple{getfield(GLMakie, Symbol("#81#82")),Symbol}) # time: 0.07212781
Base.precompile(Tuple{typeof(draw_atomic),Screen,Scene,Union{Scatter{ArgType} where ArgType, MeshScatter{ArgType} where ArgType}}) # time: 0.06695828
isdefined(GLMakie, Symbol("#89#90")) && Base.precompile(Tuple{getfield(GLMakie, Symbol("#89#90")),LineSegments{Tuple{Vector{Point{2, Float32}}}}}) # time: 0.050924074
isdefined(GLMakie, Symbol("#104#109")) && Base.precompile(Tuple{getfield(GLMakie, Symbol("#104#109")),String,Vector{Point{3, Float32}},Vector{Float32},Vector{FTFont},Vec{2, Float32},Vector{Quaternionf},SMatrix{4, 4, Float32, 16},Float64,Float64}) # time: 0.038516257
isdefined(GLMakie, Symbol("#81#82")) && Base.precompile(Tuple{getfield(GLMakie, Symbol("#81#82")),Bool}) # time: 0.030008739
isdefined(GLMakie, Symbol("#101#102")) && Base.precompile(Tuple{getfield(GLMakie, Symbol("#101#102")),Int64,Point{3, Float32},Float32,FTFont,Vec{2, Float32}}) # time: 0.029477166
isdefined(GLMakie, Symbol("#81#82")) && Base.precompile(Tuple{getfield(GLMakie, Symbol("#81#82")),Symbol}) # time: 0.019217245
isdefined(GLMakie, Symbol("#81#82")) && Base.precompile(Tuple{getfield(GLMakie, Symbol("#81#82")),Billboard}) # time: 0.016408404
isdefined(GLMakie, Symbol("#81#82")) && Base.precompile(Tuple{getfield(GLMakie, Symbol("#81#82")),Type}) # time: 0.006553374
Base.precompile(Tuple{typeof(renderloop),Screen}) # time: 0.005448615
isdefined(GLMakie, Symbol("#81#82")) && Base.precompile(Tuple{getfield(GLMakie, Symbol("#81#82")),RGBA{N0f8}}) # time: 0.004190753
Base.precompile(Tuple{typeof(push!),Screen,Scene,RenderObject{GLMakie.GLAbstraction.StandardPrerender}}) # time: 0.002534885
isdefined(GLMakie, Symbol("#81#82")) && Base.precompile(Tuple{getfield(GLMakie, Symbol("#81#82")),Any}) # time: 0.002144091
isdefined(GLMakie, Symbol("#81#82")) && Base.precompile(Tuple{getfield(GLMakie, Symbol("#81#82")),Any}) # time: 0.001724354
isdefined(GLMakie, Symbol("#12#20")) && Base.precompile(Tuple{getfield(GLMakie, Symbol("#12#20"))}) # time: 0.00144086
isdefined(GLMakie, Symbol("#81#82")) && Base.precompile(Tuple{getfield(GLMakie, Symbol("#81#82")),Vector{RGBA{Float32}}}) # time: 0.001202468
Base.precompile(Tuple{typeof(draw_atomic),Screen,Scene,Lines{ArgType} where ArgType}) # time: 0.001200726
isdefined(GLMakie, Symbol("#81#82")) && Base.precompile(Tuple{getfield(GLMakie, Symbol("#81#82")),Tuple{Symbol, Float64}}) # time: 0.001081687
isdefined(GLMakie, Symbol("#81#82")) && Base.precompile(Tuple{getfield(GLMakie, Symbol("#81#82")),Vector{Float32}}) # time: 0.001065034
isdefined(GLMakie, Symbol("#89#90")) && Base.precompile(Tuple{getfield(GLMakie, Symbol("#89#90")),Annotations{Tuple{Vector{Tuple{String, Point{2, Float32}}}}}}) # time: 0.001031033
activate!()
precompile(refreshwindowcb, (GLFW.Window, Screen))
p = plot(rand(10))
# Mimic `display(p)` without actually creating a display
function insertplotstype(scene)
for elem in scene.plots
inserttype(scene, elem)
end
foreach(s-> insertplotstype(s), scene.children)
end
function inserttype(scene, @nospecialize(x))
if isa(x, Combined)
if isempty(x.plots)
precompile(insert!, (Screen, typeof(scene), typeof(x)))
else
foreach(x.plots) do x
inserttype(scene, x)
end
end
else
precompile(insert!, (Screen, typeof(scene), typeof(x)))
end
end
scene = p.figure.scene
insertplotstype(scene)
end
11 changes: 6 additions & 5 deletions GLMakie/src/screen.jl
Original file line number Diff line number Diff line change
Expand Up @@ -375,11 +375,7 @@ function Screen(;
Dict{UInt32, AbstractPlot}(),
)

GLFW.SetWindowRefreshCallback(window, window -> begin
screen.render_tick[] = nothing
render_frame(screen)
GLFW.SwapBuffers(window)
end)
GLFW.SetWindowRefreshCallback(window, window -> refreshwindowcb(window, screen))

screen.rendertask[] = @async((WINDOW_CONFIG.renderloop[])(screen))
# display window if visible!
Expand Down Expand Up @@ -415,6 +411,11 @@ function global_gl_screen(resolution::Tuple, visibility::Bool, tries = 1)
screen
end

function refreshwindowcb(window, screen)
screen.render_tick[] = nothing
render_frame(screen)
return GLFW.SwapBuffers(window)
end

#################################################################################
### Point picking
Expand Down

0 comments on commit bfabbaf

Please sign in to comment.