New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor SofQWNormalisedPolygon for performance #12584
Comments
@martyngigg (2015-05-26T09:17:23): I think this will probably split into 2 tickets as the it will be worth reprofiling after the exception changes to see whta difference the Vertex2D changes can make. A lot of that code was borrowed from another place that implemented the algorithm. |
The points are now stored in a container rather than a custom linked-list. This will cut down on the the operations required to insert a new node. Refs #12584
This is just a simple forward iterator that doesn't implement the full iterator interface. Refs #12584
PoylgonIntersection uses new style of creating polygons. Refs #12584
Initial tests suggest this has given a factor of 2 improvement in speed. Refs #12584
Clang and MSVC both require the full definition to be able to use it as a member variable. Refs #12584
This issue was originally TRAC 11746
Running the script below seemed very slow so I profiled the execution.
Valgrind indicates that 30% of the execution time is being spent handling thrown exceptions. This comes from the call in
SofQNormalisedPolygon::exec
toRebin2D::rebinToFractionalOutput
which callsintersectionByLaszlow
in a tight loop.intersectionByLaszlow
returns either aConvexPolygon
representing the intersection, or throws an exception. We're throwing a huge number of exceptions in a tight loop, which is very bad for performance.Instead
intersectionByLaszlow
should accept an additional non-const ConvexPolygon reference that will be used for output, and then return a bool indicating whether an overlap exists. This should reduce the execution time by 30%.In addition, there is a strongly suspected secondary performance problem: Vertex2D. Vertex2D is a V2D like class that implements its own linked list. It's used by ConvexPolygon to represents the polygon's vertices. During the execution of the algorithm we allocate and deallocate thousands of Vertex2Ds on the heap, which cannot be good for the algorithm's performance. We should strongly consider removing Vertex2D from Mantid in totality, and in this case use
std::vector
`` instead.Overall this ought to improve performance by 40%, if not more. A performance test should be created before refactoring work begins, to allow measuring any performance improvements made.
Keywords: maintenance
The text was updated successfully, but these errors were encountered: