acts icon indicating copy to clipboard operation
acts copied to clipboard

refactor!: Surface returns transform by value

Open asalzburger opened this issue 1 year ago • 9 comments

This PR tests how much performance loss we would experience when changing the return object of Surface objects from

const Transform& transform(const GeometryContext& gctx) const;

to

Transform transform(const GeometryContext& gctx) const;

This change would allow us to create surfaces on the fly, (or at least their transforms) for e.g. Drift straws, etc.

Initial tests - running the propagation test only, which is relatively highly effected by this - shows.

Propagation test

without this change

09:57:30    Sequencer      INFO      Average time per event: 19.184849 ms/event

with this change

09:56:55    Sequencer      INFO      Average time per event: 20.279401 ms/event

It indicates a 5% penalty in this workflow.

Truth Tracking

14:07:33    Sequencer      INFO      Average time per event: 44.465655 ms/event

vs.

14:07:42    Sequencer      INFO      Average time per event: 45.216276 ms/event

So, closer to 2 % effect there, already interesting, I will do a full chain run as well.

asalzburger avatar Oct 11 '23 08:10 asalzburger

We probably want to run some workflows a number of times to characterize the performance. 5% seems non-negligible.

paulgessinger avatar Oct 11 '23 08:10 paulgessinger

We probably want to run some workflows a number of times to characterize the performance. 5% seems non-negligible.

Yes, completely agree. I will run a full chain workflow later to see where we stand on that.

asalzburger avatar Oct 11 '23 08:10 asalzburger

Codecov Report

Attention: Patch coverage is 5.00000% with 19 lines in your changes are missing coverage. Please review.

Project coverage is 49.74%. Comparing base (4f33d42) to head (a5264dd). Report is 163 commits behind head on main.

:exclamation: Current head a5264dd differs from pull request most recent head a4063e0

Please upload reports for the commit a4063e0 to get more accurate results.

Files Patch % Lines
Core/src/Surfaces/CylinderSurface.cpp 0.00% 1 Missing and 4 partials :warning:
Core/src/Surfaces/ConeSurface.cpp 0.00% 1 Missing and 2 partials :warning:
.../src/Detector/detail/CylindricalDetectorHelper.cpp 0.00% 0 Missing and 2 partials :warning:
Core/src/Surfaces/DiscSurface.cpp 0.00% 0 Missing and 2 partials :warning:
Core/src/Surfaces/Surface.cpp 33.33% 0 Missing and 2 partials :warning:
...ore/src/Geometry/KDTreeTrackingGeometryBuilder.cpp 0.00% 0 Missing and 1 partial :warning:
Core/src/Geometry/PlaneLayer.cpp 0.00% 0 Missing and 1 partial :warning:
Core/src/Surfaces/PerigeeSurface.cpp 0.00% 1 Missing :warning:
Core/src/Surfaces/PlaneSurface.cpp 0.00% 0 Missing and 1 partial :warning:
Core/src/Surfaces/StrawSurface.cpp 0.00% 0 Missing and 1 partial :warning:
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2527      +/-   ##
==========================================
+ Coverage   48.82%   49.74%   +0.91%     
==========================================
  Files         491      466      -25     
  Lines       28886    26310    -2576     
  Branches    13705    12104    -1601     
==========================================
- Hits        14104    13087    -1017     
+ Misses       4954     4616     -338     
+ Partials     9828     8607    -1221     

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

codecov[bot] avatar Oct 11 '23 08:10 codecov[bot]

Probably we should then also change this in DetectorElementBase.

paulgessinger avatar Oct 11 '23 10:10 paulgessinger

alternatively we could cache the transform in a unique_ptr or in a pool to avoid recomputation. but that would also be up for measurements if that actually happens a lot and if it makes a difference

andiwand avatar Oct 11 '23 10:10 andiwand

Good news though everything seems to run through ...

asalzburger avatar Oct 11 '23 11:10 asalzburger

alternatively we could cache the transform in a unique_ptr or in a pool to avoid recomputation. but that would also be up for measurements if that actually happens a lot and if it makes a difference

I am not sure we should go for some lazy initialisation - I hope we can stick to a clean design: either object and copy or pre-construct and return by const ref.

asalzburger avatar Oct 11 '23 12:10 asalzburger

We could consider using an atomic pointer to model lazy initialization and caching of the transform.

Anyway, should we move forward with this, or close it for now?

paulgessinger avatar Jun 21 '24 06:06 paulgessinger

archiving this due to inactivity for now

andiwand avatar Aug 31 '24 07:08 andiwand