Skip to content

Performance: Improve Field Lookup

Simon Spannagel requested to merge perf_detfield into master

The field lookup code necessarily contains quite some coordinate transformations to cover for the different types of field mappings and field types. This MR simplifies the code path:

  • field types are tested from simple to complex, and calculations are only performed when necessary. This means e.g. first checking if a field is linear before calculating any x/y offsets
  • a (slightly) new field type is introduced, called FieldType::CUSTOM1D which is to be used when a custom field function is configured but it does not depend on the x or y coordinate. Also here we can save some calculations
  • now the z position (and possible extrapolations) are checked before anything else, so we can directly return in case we are outside the thickness domain of the field
  • Some cleanup for more concise code: the get_field_from_grid method should not care about things like z extrapolation of flipping of vector components. Both is to be done in the calling method.

Performance measurements are hard, but using test_performance/test_03-multithreading in single-threaded mode for better repeatability, I get roughly 20% speedup. Other scenarios (especially when also querying doping concentrations) should profit even stronger.

Please review with care - technical depth, very central code.

Merge request reports