Optimize interpolated B field
This is my work on #384 (closed) . On my machine, a microbenchmark that hammers getField() in a loop goes from ~500ns/iteration to ~50ns/iteration with these changes. I think going beyond that would require more significant interface changes than I'm willing to commit to for now.
Quick summary of the work done:
- Replace dynamically allocated
std::set
s with lazy iterables that produce the same values. - Where heap allocation is useful, prefer
std::vector
overstd::set
- Avoid some unnecessary ping-poing between local and global grid coordinates
- Remove redundant array bound check
- Replace expensive trig functions with judicious use of trig identities (similar to earlier Jacobian work)
This reminds me that we really need some serious magnetic field benchmarks, I'll try to write a couple when I have more time.
Fixes #384 (closed) .
Edited by Hadrien Benjamin Grasland