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.
This commit is contained in:
Nicholas Bauer 2021-08-27 00:30:30 -04:00 committed by GitHub
parent 22651e8728
commit 0809c21490
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1906,6 +1906,8 @@ function _update_axis(
return
end
axisattrcache = Dict{Symbol, Dict{Symbol, Symbol}}()
function _update_axis(
axis::Axis,
plotattributes_in::AKW,
@ -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