From 269d638b071fd21ea3d988ea06e732fa638d7bec Mon Sep 17 00:00:00 2001 From: Anshul Singhvi Date: Fri, 9 Aug 2024 22:02:12 -0400 Subject: [PATCH 1/4] Remove splats in draw_mesh2d inner loop This also restores parity in the loop body with `draw_mesh3d`. --- CairoMakie/src/primitives.jl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/CairoMakie/src/primitives.jl b/CairoMakie/src/primitives.jl index 3524b696e06..07db4a96276 100644 --- a/CairoMakie/src/primitives.jl +++ b/CairoMakie/src/primitives.jl @@ -951,9 +951,9 @@ function draw_mesh2D(screen, per_face_cols, vs::Vector{<: Point2}, fs::Vector{GL Cairo.mesh_pattern_begin_patch(pattern) - Cairo.mesh_pattern_move_to(pattern, t1...) - Cairo.mesh_pattern_line_to(pattern, t2...) - Cairo.mesh_pattern_line_to(pattern, t3...) + Cairo.mesh_pattern_move_to(pattern, t1[1], t1[2]) + Cairo.mesh_pattern_line_to(pattern, t2[1], t2[2]) + Cairo.mesh_pattern_line_to(pattern, t3[1], t3[2]) mesh_pattern_set_corner_color(pattern, 0, c1) mesh_pattern_set_corner_color(pattern, 1, c2) From 511555c6cabe485302911197304d62b8b79544fe Mon Sep 17 00:00:00 2001 From: Anshul Singhvi Date: Fri, 9 Aug 2024 22:13:24 -0400 Subject: [PATCH 2/4] Squash point type instability in project_position This shaves ~20% runtime from mesh2d --- CairoMakie/src/primitives.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CairoMakie/src/primitives.jl b/CairoMakie/src/primitives.jl index 07db4a96276..4c2d6c37b6c 100644 --- a/CairoMakie/src/primitives.jl +++ b/CairoMakie/src/primitives.jl @@ -920,7 +920,7 @@ function draw_mesh2D(scene, screen, @nospecialize(plot), @nospecialize(mesh)) space = to_value(get(plot, :space, :data))::Symbol transform_func = Makie.transform_func(plot) model = plot.model[]::Mat4d - vs = project_position(scene, transform_func, space, decompose(Point, mesh), model) + vs = project_position(scene, transform_func, space, GeometryBasics.metafree(GeometryBasics.coordinates(mesh)), model)::Vector{Point2f} fs = decompose(GLTriangleFace, mesh)::Vector{GLTriangleFace} uv = decompose_uv(mesh)::Union{Nothing, Vector{Vec2f}} # Note: This assume the function is only called from mesh plots From 56bd7aa07d87ca32731f1de41466023d69c5351c Mon Sep 17 00:00:00 2001 From: Anshul Singhvi Date: Fri, 9 Aug 2024 22:28:07 -0400 Subject: [PATCH 3/4] Fix types in function signature --- CairoMakie/src/primitives.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CairoMakie/src/primitives.jl b/CairoMakie/src/primitives.jl index 4c2d6c37b6c..c558eda0ec8 100644 --- a/CairoMakie/src/primitives.jl +++ b/CairoMakie/src/primitives.jl @@ -916,7 +916,7 @@ function draw_atomic(scene::Scene, screen::Screen, @nospecialize(primitive::Maki return nothing end -function draw_mesh2D(scene, screen, @nospecialize(plot), @nospecialize(mesh)) +function draw_mesh2D(scene, screen, @nospecialize(plot::Makie.Mesh), @nospecialize(mesh::GeometryBasics.Mesh)) space = to_value(get(plot, :space, :data))::Symbol transform_func = Makie.transform_func(plot) model = plot.model[]::Mat4d From db4fe09e7ff01d5b8912ac3650494f4316d6b287 Mon Sep 17 00:00:00 2001 From: Anshul Singhvi Date: Thu, 10 Oct 2024 07:58:18 -0700 Subject: [PATCH 4/4] Add changelog entry --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2ef871fb1f7..6c712e5c03d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,8 @@ ## [Unreleased] - Fix relocatability of GLMakie [#4461](https://github.com/MakieOrg/Makie.jl/pull/4461). - +- Improved CairoMakie's 2D mesh drawing performance by ~30% [#4132](https://github.com/MakieOrg/Makie.jl/pull/4132). + ## [0.21.13] - 2024-10-07 - Optimize SpecApi, re-use Blocks better and add API to access the created block objects [#4354](https://github.com/MakieOrg/Makie.jl/pull/4354).