From 0809c214900b06c917517b5024e23ebfaa0ed583 Mon Sep 17 00:00:00 2001 From: Nicholas Bauer Date: Fri, 27 Aug 2021 00:30:30 -0400 Subject: [PATCH] Cache axis args in a dictionary These axis arguments can be generated lots of times for large plots. We can save time by caching them in a dictionary. For my large map test plot: ``` Before: 1.075 s (3393429 allocations: 183.49 MiB) After: 959.024 ms (3393294 allocations: 181.64 MiB) - 10% improvement in speed, small decrease in allocations TTFP Before: 7.543192 seconds (26.79 M allocations: 1.544 GiB, 3.89% gc time, 0.06% compilation time) TTFP After: 6.886222 seconds (23.58 M allocations: 1.355 GiB, 3.63% gc time, 0.07% compilation time) - 8% improvement in speed, 12% fewer allocations, 12% lower allocation amount ``` The cost of this is, I think, just 3-4 kb. Is there a function to read out the size in memory of a dictionary? `sizeof` for the dictionary itself just returns 64. --- src/args.jl | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/args.jl b/src/args.jl index 461c07f1..e07bb3ba 100644 --- a/src/args.jl +++ b/src/args.jl @@ -1905,6 +1905,8 @@ function _update_axis( _update_axis_links(plt, axis, letter) return end + +axisattrcache = Dict{Symbol, Dict{Symbol, Symbol}}() function _update_axis( axis::Axis, @@ -1922,7 +1924,18 @@ function _update_axis( end # then get those args that were passed with a leading letter: `xlabel = "X"` - lk = Symbol(letter, k) + lt = if haskey(axisattrcache, letter) + axisattrcache[letter] + else + axisattrcache[letter] = Dict{Symbol, Symbol}() + end + + lk = if haskey(lt, k) + lt[k] + else + lt[k] = Symbol(letter, k) + end + if haskey(plotattributes_in, lk) kw[k] = slice_arg(plotattributes_in[lk], subplot_index) end