[Insight-users] Performance of ModifiedTime increments

Tom Vercauteren tom.vercauteren at m4x.org
Wed Mar 12 14:57:38 EDT 2008


Hi all,

I have been using ITK in a multi-threaded application and stumbled
onto a performance bottleneck.

I am using objects of type itk::VectorContainer. I had several loops
that were using the InsertElement and ElementAt functions. This caused
a major slow-down when running several threads. The problem was
originating from the mutex lock in itkTimeStamp.cxx:
void
TimeStamp
::Modified()
{
  /**
   * Initialize static member
   */
  static unsigned long itkTimeStampTime = 0;

  /** Used for mutex locking */
  static SimpleFastMutexLock TimeStampMutex;

  TimeStampMutex.Lock();
  m_ModifiedTime = ++itkTimeStampTime;
  TimeStampMutex.Unlock();
}

As a workaround I am now using the VectorContainers as STL vectors and
calling Modified at the end of the loop. However, as Modified() is
called very often in ITK, I think it would be worth optimizing the
piece of code above.

I saw that several other libraries (e.g. boost, QT, ..) are using
atomic operations for that purpose. It seems that this can be fairly
easily done at least on gcc by using the __atomic_add function in the
atomicity.h header file (see atomic_count.hpp in boost for a
cross-platform implementation).

Do you think it would be worth doing such an optimization for the
upcoming ITK release?

Best regards,
Tom Vercauteren


More information about the Insight-users mailing list