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
PERF: Let SpatialObject directly access m_ObjectToWorldTransformInverse #4435
PERF: Let SpatialObject directly access m_ObjectToWorldTransformInverse #4435
Conversation
Not ideal.
How about instead still creating a function call to access it, but eliminate the test for mtimes in that function. The function name should make it obvious that the variable is being assumed to be valid. Perhaps GetLastValidObjectToWorldTransformInverse() or GetObjectToWorldTransformInverseWithoutVerification() or such. |
@dzenanz - what is the recommended pattern for this situation? |
Ah - I see this is all within the base class - not derived. So my comment on derived class isn't valid, but it still holds that the inverse might not be valid without the mtime test. s |
Thanks for your feedback, @aylward ITK/Modules/Core/SpatialObjects/include/itkSpatialObject.hxx Lines 525 to 530 in d4d7419
As well as by ITK/Modules/Core/SpatialObjects/include/itkSpatialObject.hxx Lines 500 to 509 in d4d7419
That's why I think |
My previous pull request proposes a different approach: One of the ideas behind PR #4434 is to take those relatively expensive So this PR (#4435) kind-of competes with my other PR, #4434 😃 If |
This is outstanding! I like the approach in #4434 - very nice! Perhaps just add a comment to those worldspace functions that they assume that the inverse is up to date. Then we'll cross our fingers and hope some third party hasn't done something that breaks. As you said, it should be up to date. Thanks! |
@aylward Thanks! If this PR passes the CI, I'll add a note to each of the four adjusted member functions (DerivativeAtInWorldSpace, IsInsideInWorldSpace, IsEvaluableAtInWorldSpace, ValueAtInWorldSpace) saying something like:
OK? |
Perfect! |
Replaced `this->GetObjectToWorldTransformInverse()` calls with direct access to m_ObjectToWorldTransformInverse. A performance improvement greater than 6% was observed, from more than 0.74 sec. down to less than 0.69 sec, when calling `IsInsideInWorldSpace` 2^25 times (as tested on VS2019 Release).
4b6ffe2
to
4fe1aa4
Compare
Replaced `SpatialObject::GetObjectToWorldTransformInverse()` calls within the implementation of SpatialObject with direct access to its own `m_ObjectToWorldTransform` data member. Follow-up to pull request InsightSoftwareConsortium#4435 commit 1e0475c "PERF: Let SpatialObject directly access m_ObjectToWorldTransformInverse" (However, in this case, no significant performance improvement is expected, so it's just a matter of style.)
Replaced `SpatialObject::GetObjectToWorldTransform()` calls within the implementation of SpatialObject with direct access to its own `m_ObjectToWorldTransform` data member. Follow-up to pull request InsightSoftwareConsortium#4435 commit 1e0475c "PERF: Let SpatialObject directly access m_ObjectToWorldTransformInverse" (However, in this case, no significant performance improvement is expected, so it's just a matter of style.)
Upgraded ITK on the CI to version 5.4rc03: https://github.com/InsightSoftwareConsortium/ITK/releases/tag/v5.4rc03 (commits from 2023-10-10 to 2024-04-04: InsightSoftwareConsortium/ITK@v5.4rc02...v5.4rc03) Including major performance improvements of `SpatialObject.IsInsideInWorldSpace(point)`: * InsightSoftwareConsortium/ITK#4435 "Let SpatialObject directly access m_ObjectToWorldTransformInverse" * InsightSoftwareConsortium/ITK#4440 "Add SpatialObject IsInsideInWorldSpace(const PointType &) overload" * InsightSoftwareConsortium/ITK#4441 "Make `m_ObjectToWorldTransformInverse->TransformPoint` non-virtual" * InsightSoftwareConsortium/ITK#4450 "Let `ImageSpatialObject` update the image regions of its base class, let `ImageMaskSpatialObject` use these image regions" Follow-up to pull request #982 commit 5f0940d
Upgraded ITK on the CI to version 5.4rc03: https://github.com/InsightSoftwareConsortium/ITK/releases/tag/v5.4rc03 (commits from 2023-10-10 to 2024-04-04: InsightSoftwareConsortium/ITK@v5.4rc02...v5.4rc03) Including major performance improvements of `SpatialObject.IsInsideInWorldSpace(point)`: * InsightSoftwareConsortium/ITK#4435 "Let SpatialObject directly access m_ObjectToWorldTransformInverse" * InsightSoftwareConsortium/ITK#4440 "Add SpatialObject IsInsideInWorldSpace(const PointType &) overload" * InsightSoftwareConsortium/ITK#4441 "Make `m_ObjectToWorldTransformInverse->TransformPoint` non-virtual" * InsightSoftwareConsortium/ITK#4450 "Let `ImageSpatialObject` update the image regions of its base class, let `ImageMaskSpatialObject` use these image regions" Follow-up to pull request #982 commit 5f0940d
Replaced
this->GetObjectToWorldTransformInverse()
calls with direct access to m_ObjectToWorldTransformInverse. A performance improvement greater than 6% was observed, from more than 0.74 sec. down to less than 0.69 sec, when callingIsInsideInWorldSpace
2^25 times (as tested on VS2019 Release).