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

fix low hanging fruits for render performance #4485

Merged
merged 8 commits into from
Nov 5, 2024
7 changes: 6 additions & 1 deletion GLMakie/src/rendering.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,12 @@ function render_frame(screen::Screen; resize_buffers=true)
ShaderAbstractions.switch_context!(nw)

function sortby(x)
return x[3][:model][][3, 4]
robj = x[3]
plot = screen.cache2plot[robj.id]
Copy link
Member Author

Choose a reason for hiding this comment

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

The plot lookup was the expensive bit here, so would be nice if we could avoid it!

Copy link
Collaborator

Choose a reason for hiding this comment

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

Dict lookups are O(1) and somewhere around 10ns. My benchmarks for the current solution only have 3% difference to the old one.
Using robj[:model] is also what made this pr fail, because lines with linestyles apply it on the CPU so it does not end up in uniforms. I would also expect this to subtly fail with f32 converts because those can change the model matrix (set it to I after applying it on the CPU)

# TODO, use actual boundingbox
# ~7% faster than calling zvalue2d doing the same thing?
return Makie.transformationmatrix(plot)[][3, 4]
# return Makie.zvalue2d(plot)
end

sort!(screen.renderlist; by=sortby)
Expand Down
5 changes: 3 additions & 2 deletions src/layouting/transformation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -536,5 +536,6 @@ end
# and this way we can use the z-value as a means to shift the drawing order
# by translating e.g. the axis spines forward so they are not obscured halfway
# by heatmaps or images
zvalue2d(x)::Float32 = Float32(Makie.translation(x)[][3] + zvalue2d(x.parent))
zvalue2d(::Nothing)::Float32 = 0f0
# zvalue2d(x)::Float32 = Float32(Makie.translation(x)[][3] + zvalue2d(x.parent))
@inline zvalue2d(x)::Float32 = Float32(transformationmatrix(x)[][3, 4])
@inline zvalue2d(::Nothing)::Float32 = 0f0
Loading