From 814d8d5b19e742b9b2bc68ef41aa9724edcb19ca Mon Sep 17 00:00:00 2001 From: Julius Krumbiegel <22495855+jkrumbiegel@users.noreply.github.com> Date: Mon, 21 Oct 2024 19:40:52 +0200 Subject: [PATCH 1/2] Use polys for axis3 (#4463) * use poly for axis3 panels so that svgs aren't rasterized * add rasterization tests for Axis3 and PolarAxis * disable stroke * remove depth shift * Update CHANGELOG.md --------- Co-authored-by: Simon --- CHANGELOG.md | 1 + CairoMakie/test/svg_tests.jl | 2 ++ src/makielayout/blocks/axis3d.jl | 43 +++++++++++++++++++++----------- 3 files changed, 31 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8cf94ec24d8..9061fd1100a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ - Changed image, heatmap and surface picking indices to correctly index the relevant matrix arguments. [#4459](https://github.com/MakieOrg/Makie.jl/pull/4459) - Improved performance of `record` by avoiding unnecessary copying in common cases [#4475](https://github.com/MakieOrg/Makie.jl/pull/4475). - Fix usage of `AggMean()` and other aggregations operating on 3d data for `datashader` [#4346](https://github.com/MakieOrg/Makie.jl/pull/4346). +- Use polys for axis3 [#4463](https://github.com/MakieOrg/Makie.jl/pull/4463). - Changed default for `circular_rotation` in Camera3D to false, so that the camera doesn't change rotation direction anymore [4492](https://github.com/MakieOrg/Makie.jl/pull/4492) - Fixed `pick(scene, rect2)` in WGLMakie [#4488](https://github.com/MakieOrg/Makie.jl/pull/4488) diff --git a/CairoMakie/test/svg_tests.jl b/CairoMakie/test/svg_tests.jl index 5efb72c4baf..da30bba0948 100644 --- a/CairoMakie/test/svg_tests.jl +++ b/CairoMakie/test/svg_tests.jl @@ -13,6 +13,8 @@ end @testset "SVG rasterization" begin @test svg_isnt_rasterized(Scene()) @test svg_isnt_rasterized(begin f = Figure(); Axis(f[1, 1]); f end) + @test svg_isnt_rasterized(begin f = Figure(); Axis3(f[1, 1]); f end) + @test svg_isnt_rasterized(begin f = Figure(); PolarAxis(f[1, 1]); f end) @test svg_isnt_rasterized(scatter(1:3)) @test svg_isnt_rasterized(lines(1:3)) @test svg_isnt_rasterized(heatmap(rand(5, 5))) diff --git a/src/makielayout/blocks/axis3d.jl b/src/makielayout/blocks/axis3d.jl index ab3121fb487..a6b97462925 100644 --- a/src/makielayout/blocks/axis3d.jl +++ b/src/makielayout/blocks/axis3d.jl @@ -664,29 +664,42 @@ function add_panel!(scene, ax, dim1, dim2, dim3, limits, min3) string((:x, :y, :z)[dim2]) * string(sym)) attr(sym) = getproperty(ax, dimsym(sym)) - vertices = lift(limits, min3) do lims, mi3 - + rect = lift(limits) do lims mi = minimum(lims) ma = maximum(lims) + Polygon([ + Point2(mi[dim1], mi[dim2]), + Point2(ma[dim1], mi[dim2]), + Point2(ma[dim1], ma[dim2]), + Point2(mi[dim1], ma[dim2]) + ]) + end - v3 = if mi3 - mi[dim3] + 0.005 * (mi[dim3] - ma[dim3]) - else - ma[dim3] + 0.005 * (ma[dim3] - mi[dim3]) - end + plane_offset = lift(limits, min3) do lims, mi3 + mi = minimum(lims) + ma = maximum(lims) - p1 = dim3point(dim1, dim2, dim3, mi[dim1], mi[dim2], v3) - p2 = dim3point(dim1, dim2, dim3, mi[dim1], ma[dim2], v3) - p3 = dim3point(dim1, dim2, dim3, ma[dim1], ma[dim2], v3) - p4 = dim3point(dim1, dim2, dim3, ma[dim1], mi[dim2], v3) - [p1, p2, p3, p4] + mi3 ? mi[dim3] : ma[dim3] end - faces = [1 2 3; 3 4 1] + plane = Symbol((:x, :y, :z)[dim1], (:x, :y, :z)[dim2]) - panel = mesh!(scene, vertices, faces, shading = NoShading, inspectable = false, + panel = poly!(scene, rect, inspectable = false, xautolimits = false, yautolimits = false, zautolimits = false, - color = attr(:panelcolor), visible = attr(:panelvisible)) + color = attr(:panelcolor), visible = attr(:panelvisible), + strokecolor = :transparent, strokewidth = 0, + transformation = (plane, 0), + ) + + on(plane_offset) do offset + translate!( + panel, + dim3 == 1 ? offset : zero(offset), + dim3 == 2 ? offset : zero(offset), + dim3 == 3 ? offset : zero(offset), + ) + end + return panel end From 6b267799d179909ab59632e0b913b79e9f419086 Mon Sep 17 00:00:00 2001 From: Julius Krumbiegel <22495855+jkrumbiegel@users.noreply.github.com> Date: Mon, 21 Oct 2024 22:54:39 +0200 Subject: [PATCH 2/2] Benchmark simplification (#4493) * use poly for axis3 panels so that svgs aren't rasterized * add rasterization tests for Axis3 and PolarAxis * disable stroke * remove depth shift * don't use BenchmarkTools, just run 100 trials and store all results * interleave project runs * bump run number to 20 * change timing names * store results as artifact * collect gc times separately * only include previous 5 columns in comment to match old template * use median of timings to avoid outliers * store each json artifact separately * remove superfluous arrays --------- Co-authored-by: Simon --- .github/workflows/compilation-benchmark.yaml | 7 ++++- metrics/ttfp/benchmark-ttfp.jl | 32 ++++++++++++++++---- metrics/ttfp/run-benchmark.jl | 16 +++++++--- 3 files changed, 44 insertions(+), 11 deletions(-) diff --git a/.github/workflows/compilation-benchmark.yaml b/.github/workflows/compilation-benchmark.yaml index 6df32a3184f..17cb146fed4 100644 --- a/.github/workflows/compilation-benchmark.yaml +++ b/.github/workflows/compilation-benchmark.yaml @@ -37,4 +37,9 @@ jobs: GITHUB_TOKEN: ${{ secrets.BENCHMARK_KEY }} PR_NUMBER: ${{ github.event.number }} run: > - DISPLAY=:0 xvfb-run -s '-screen 0 1024x768x24' julia --project=./metrics/ttfp/ ./metrics/ttfp/run-benchmark.jl ${{ matrix.package }} 7 ${{ github.event.pull_request.base.ref }} + DISPLAY=:0 xvfb-run -s '-screen 0 1024x768x24' julia --project=./metrics/ttfp/ ./metrics/ttfp/run-benchmark.jl ${{ matrix.package }} 20 ${{ github.event.pull_request.base.ref }} + - name: Upload measurements as artifact + uses: actions/upload-artifact@v4 + with: + name: ${{ matrix.package }} + path: ./json diff --git a/metrics/ttfp/benchmark-ttfp.jl b/metrics/ttfp/benchmark-ttfp.jl index 274b1c3e38d..d44f016091d 100644 --- a/metrics/ttfp/benchmark-ttfp.jl +++ b/metrics/ttfp/benchmark-ttfp.jl @@ -20,9 +20,9 @@ set_theme!(size=(800, 600)) create_time = @ctime fig = scatter(1:4; color=1:4, colormap=:turbo, markersize=20, visible=true) display_time = @ctime colorbuffer(fig; px_per_unit=1) -using BenchmarkTools -using BenchmarkTools.JSON +using JSON using Pkg +using Statistics: median project_name = basename(dirname(Pkg.project().path)) @@ -31,13 +31,33 @@ old = isfile(result) ? JSON.parse(read(result, String)) : [[], [], [], [], []] @show [t_using, create_time, display_time] push!.(old[1:3], [t_using, create_time, display_time]) -b1 = @benchmark fig = scatter(1:4; color=1:4, colormap=:turbo, markersize=20, visible=true) -b2 = @benchmark colorbuffer(fig; px_per_unit=1) +macro simple_median_time(expr) + time_expr = quote + local elapsedtime = time_ns() + $expr + elapsedtime = time_ns() - elapsedtime + Float64(elapsedtime) + end + + quote + times = Float64[] + for i in 1:101 + t = Core.eval(Main, $(QuoteNode(time_expr))) + if i > 1 + push!(times, t) + end + end + median(times) + end +end +@time "creating figure" figure_time = @simple_median_time fig = scatter(1:4; color=1:4, colormap=:turbo, markersize=20, visible=true) +fig = scatter(1:4; color=1:4, colormap=:turbo, markersize=20, visible=true) +@time "colorbuffer" colorbuffer_time = @simple_median_time colorbuffer(fig; px_per_unit=1) using Statistics -push!(old[4], mean(b1.times)) -push!(old[5], mean(b2.times)) +push!(old[4], figure_time) +push!(old[5], colorbuffer_time) open(io-> JSON.print(io, old), result, "w") diff --git a/metrics/ttfp/run-benchmark.jl b/metrics/ttfp/run-benchmark.jl index 2d7d4602eca..84374eae260 100644 --- a/metrics/ttfp/run-benchmark.jl +++ b/metrics/ttfp/run-benchmark.jl @@ -182,9 +182,10 @@ using Random function run_benchmarks(projects; n=n_samples) benchmark_file = joinpath(@__DIR__, "benchmark-ttfp.jl") - for project in shuffle!(repeat(projects; outer=n)) + # go A, B, A, B, A, etc. + for project in repeat(projects, n) + println(basename(project)) run(`$(Base.julia_cmd()) --startup-file=no --project=$(project) $benchmark_file $Package`) - project_name = basename(project) end return end @@ -221,13 +222,13 @@ end pkgs = NamedTuple[(; path="./MakieCore"), (; path="."), (; path="./$Package")] # cd("dev/Makie") Pkg.develop(pkgs) -Pkg.add([(; name="BenchmarkTools")]) +Pkg.add([(; name="JSON")]) @time Pkg.precompile() project2 = make_project_folder(base_branch) Pkg.activate(project2) -pkgs = [(; rev=base_branch, name="MakieCore"), (; rev=base_branch, name="Makie"), (; rev=base_branch, name="$Package"), (;name="BenchmarkTools")] +pkgs = [(; rev=base_branch, name="MakieCore"), (; rev=base_branch, name="Makie"), (; rev=base_branch, name="$Package"), (;name="JSON")] Package == "WGLMakie" && push!(pkgs, (; name="Electron")) Pkg.add(pkgs) @time Pkg.precompile() @@ -249,3 +250,10 @@ else @info("Not commenting, no PR found") println(update_comment(COMMENT_TEMPLATE, Package, benchmark_rows)) end + +mkdir("json") +for p in [project1, project2] + name = basename(p) + file = "$name-benchmark.json" + mv(file, joinpath("json", file)) +end