[vtk-developers] vtkDataArray performance; vtkErrorMacro semantics

David Lonie david.lonie at kitware.com
Tue Apr 26 15:26:32 EDT 2016


On Tue, Apr 26, 2016 at 2:58 PM, Sean McBride <sean at rogue-research.com>
wrote:

> Hi all,
>
> So we're continuing to profile our app to improve the performance of
> something, and I have another vtkDataArray question.  This method:
>
> void vtkDataArray::SetTuple(vtkIdType dstTupleIdx, vtkIdType srcTupleIdx,
>                             vtkAbstractArray *source)
>
> starts with 3 checks.  If they fail, it uses vtkErrorMacro and bails.
>
> First, what are the semantics of hitting vtkErrorMacro?  Is it meant to be
> like an assertion, ie something that should be impossible, and therefore
> useful in debug but discardable in release?
>

I've often wondered this myself, I'm not aware of an 'official'
interpretation of these. From context, it seems to usually be used to
enforce a documented/logical constraint. I often use them as non-fatal
asserts.

I know the dashboards are configured to treat any output coming from
vtkErrorMacro as a test failure.


> We've added assert(0) in the three branches, and our code never hits them
> and no VTK unit test does either.
>

Not surprising -- the method does nothing (and tests will fail) if it hits
them :)


> The 3 checks are individually fast, but the method is called so very very
> often that removing the 3 checks entirely gives us a full 20% runtime
> speedup of Render(), so I'm hoping it would be acceptable to wrap them in
> #ifndef NDEBUG, or otherwise remove them from release builds.


+1 to the idea. I'd love to see this wrapped up in a vtkAssertMacro or
similar, as well as some clarification on the semantics of
Warning/ErrorMacro. I think there was some discussion started by Kyle Lutz
a few years back about whether or not to just use asserts in these
situations, and there was some controversy around the idea and he abandoned
the proposal in the end. I can't remember or imagine why people objected at
the moment, but the thread should be in the archives.

I'd actually prefer to remove that (and similar) methods completely (settle
down folks, I'm not actually proposing this! I've learned to just accept
these warts and not try to fix problematic APIs in VTK). They have
performance problems beyond the sanity checks, the repeated dispatch calls
add up, too. It's too fine-grained an action for the expense it occurs. It
used to be worse, actually -- back when I was profiling some of these
functions the vast majority of CPU time was spent in strcmp, because
SafeDownCast was being used to test if the source arrays was a data array.
I believe it was actually this method that made me add the
vtkAbstractArray::FastDownCast system.

Dave
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtk-developers/attachments/20160426/103a9f37/attachment.html>


More information about the vtk-developers mailing list