Skip to content
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

Major performance issue TimeProbe, ResourceProbe constructor #350

Closed
N-Dekker opened this issue Dec 23, 2018 · 8 comments
Closed

Major performance issue TimeProbe, ResourceProbe constructor #350

N-Dekker opened this issue Dec 23, 2018 · 8 comments

Comments

@N-Dekker
Copy link
Contributor

Two weeks ago, Theo van Walsum (@tvanwalsum, Erasmus MC, Rotterdam) reported a major performance issue at discourse.itk.org:

I recently upgraded my elastix registration software, and simultaneously upgrading itk from 4.8 to the 4.13. This greatly affected the registration timings (3 to 4-fold slower). After some testing, I found it this problem starts with itk 4.9.

While Theo encountered the issue with ITK 4.8, using VS2013, it is still there with ITK 5 beta 3, using VS2017.

It appears that this performance issue is caused by an enhancement of itk::ResourceProbe, introduced with ITK 4.9. This enhancement includes calling GetSystemInformation() in the default-constructor of ResourceProbe: https://github.com/InsightSoftwareConsortium/ITK/blob/v4.9.0/Modules/Core/Common/include/itkResourceProbe.hxx#L51 Which causes a major performance drop of its derived classes, including itk::TimeProbe.

It can be reproduced by profiling the following example:

  double meanValues[263];

  for (auto&& meanValue : meanValues)
  {
    itk::TimeProbe timeProbe;
    timeProbe.Start();
    timeProbe.Stop();
    meanValue = timeProbe.GetMean();
  }

On Visual Studio 2017 Version 15.9.4 64-bit Release, I observed that this code takes more than 25 seconds. When I manually remove the GetSystemInformation() call from the default-constructor of ResourceProbe (at https://github.com/InsightSoftwareConsortium/ITK/blob/v5.0b03/Modules/Core/Common/include/itkResourceProbe.hxx#L52), the very same code takes less than 0.001 seconds!

@N-Dekker
Copy link
Contributor Author

@hyunjaeKang I think this issue is related to an ITK contribution of yours, right? Can you please have a look? Specifically, do you think it would be OK to remove the GetSystemInformation() call from the default-constructor of itk::ResourceProbe?

@N-Dekker
Copy link
Contributor Author

Update: I'm preparing a fix for this issue... please wait!

@N-Dekker N-Dekker changed the title Major performance issue TimeProbe, ResourceProbe default-constructor Major performance issue TimeProbe, ResourceProbe constructor Dec 24, 2018
hjmjohnson pushed a commit that referenced this issue Dec 26, 2018
ITK 4.9 added system info to `itk::ResourceProbe` (the base class of
`itk::TimeProbe` and `itk::MemoryProbe`), by calling `GetSystemInformation()`
in its constructor. This function call appeared very time consuming.
Using Visual Studio 2017 (Release configuration), it was observed that a single
`GetSystemInformation()` function call took more than 0.1 second.

This commit removes the `this->GetSystemInformation()` function call from
ResourceProbe, deprecates the member function, removes the related data
members, and only retrieves the system info when and where it is actually being
used: in `PrintSystemInformation` and `PrintJSONSystemInformation`.

Fixes issue #350, "Major performance issue TimeProbe, ResourceProbe
constructor", which was based on the analysis of an `elastix` example
case by Theo van Walsum (@tvanwalsum).
@N-Dekker
Copy link
Contributor Author

N-Dekker commented Dec 26, 2018

Thank you very much for approving and merging pull request #351 to the master branch, @hjmjohnson . I usually don't ask this but would it be possible to also apply this fix to ITK 4? @thewtex ? I feel this fix could also be of interest to those ITK users who cannot yet move forward to ITK5/C++11.

@dzenanz
Copy link
Member

dzenanz commented Dec 27, 2018

To do that, you should cherry-pick this patch on top of release-4.13 branch, resolve conflicts (if any), and make a PR to release-4.13 branch.

@N-Dekker
Copy link
Contributor Author

Thanks @dzenanz Are there still plans for another ITK 4 release?

@dzenanz
Copy link
Member

dzenanz commented Dec 27, 2018

Yes, there are plans for at last one more 4.13.x release.

@N-Dekker
Copy link
Contributor Author

@dzenanz Thanks, I'll ask around here at LUMC if people care about having this performance fix in ITK4.

thewtex pushed a commit to thewtex/ITK that referenced this issue Jan 5, 2019
…ightSoftwareConsortium#350

ITK 4.9 added system info to `itk::ResourceProbe` (the base class of
`itk::TimeProbe` and `itk::MemoryProbe`), by calling `GetSystemInformation()`
in its constructor. This function call appeared very time consuming.
Using Visual Studio 2017 (Release configuration), it was observed that a single
`GetSystemInformation()` function call took more than 0.1 second.

This commit removes the `this->GetSystemInformation()` function call from
ResourceProbe, deprecates the member function, removes the related data
members, and only retrieves the system info when and where it is actually being
used: in `PrintSystemInformation` and `PrintJSONSystemInformation`.

Fixes issue InsightSoftwareConsortium#350, "Major performance issue TimeProbe, ResourceProbe
constructor", which was based on the analysis of an `elastix` example
case by Theo van Walsum (@tvanwalsum).
@thewtex
Copy link
Member

thewtex commented Jan 5, 2019

Thanks for diving into this @N-Dekker !

Backported to release-4.13 here: #377

thewtex added a commit that referenced this issue Jan 6, 2019
PERF: Remove SystemInformation data from ResourceProbe, fix issue #350
@thewtex thewtex closed this as completed Jan 6, 2019
N-Dekker added a commit to N-Dekker/ITK that referenced this issue Jan 27, 2021
Follow-up to:
"PERF: Remove SystemInformation data from ResourceProbe, fix issue InsightSoftwareConsortium#350"
Pull request InsightSoftwareConsortium#351
Commit 747f3d1, 2018-12-24
hjmjohnson pushed a commit to hjmjohnson/ITK that referenced this issue Nov 7, 2021
Follow-up to:
"PERF: Remove SystemInformation data from ResourceProbe, fix issue InsightSoftwareConsortium#350"
Pull request InsightSoftwareConsortium#351
Commit 747f3d1, 2018-12-24
hjmjohnson pushed a commit to hjmjohnson/ITK that referenced this issue Dec 13, 2021
Follow-up to:
"PERF: Remove SystemInformation data from ResourceProbe, fix issue InsightSoftwareConsortium#350"
Pull request InsightSoftwareConsortium#351
Commit 747f3d1, 2018-12-24
N-Dekker added a commit to N-Dekker/ITK that referenced this issue Apr 28, 2023
Follow-up to:
"PERF: Remove SystemInformation data from ResourceProbe, fix issue InsightSoftwareConsortium#350"
Pull request InsightSoftwareConsortium#351
Commit 747f3d1, 2018-12-24
hjmjohnson pushed a commit that referenced this issue Apr 30, 2023
Follow-up to:
"PERF: Remove SystemInformation data from ResourceProbe, fix issue #350"
Pull request #351
Commit 747f3d1, 2018-12-24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants