Notes
Performance
Access of attributes (e.g., by vattr
) should be "statically typed" to avoid dynamic dispatch. The Attributes) section provides hints:
- Access attributes early and pass attributes (not attribute names) to methods.
- Use
Val(:x)
for name literals or use helpers such as provided forGeometry
.
This is effective for attribute lists that are represented as NamedTuple
(see also PMeshAttributes
). For "dynamic" representations, e.g., based on Dict
, you may require additional type assertions.
Many avoidable runtime penalties stem from dynamic dispatch (slower) vs "static dispatch" (fast).
Use BenchmarkTools to test for performance regressions.
Example
#
# Dynamic vs static dispatch
#
function f(mesh, attibute)
# ...
end
using Traceur
@trace f(mesh, :name)
using JET
@report_opt f(mesh, :name)
# - Try again with passing Val(:name) or
# attribute a (where a = vattr(mesh, Val(:name)))
# - Conduct benchmarks (see below)
using Cthuluh
@descend f(mesh, :name)
#
# Benchmark excluding setup time
#
b = @benchmark flip!(mesh, HHnd(1000)) setup=(mesh = clone(SOME_MESH)) evals=1
show(io, MIME("text/plain"), b)