From: John Stone (johns_at_ks.uiuc.edu)
Date: Fri Apr 03 2020 - 11:11:56 CDT

Hi FX,
  Good catch about centers.num(), this is indeed a flaw that would
cause more memory to be allocated than it should.

The new code is specifically intended to avoid append operations
(per your last two suggestions) specifically because they are very
costly when performed in these tight visualization loops.

This version of the code runs almost 3x faster than the original version
which did use append() methods, and the ResizeArray template is also
quite a bit faster than STL vector. These and several related changes
were made to allow VMD to reach interactive display rates for huge
tomograms with billions of voxels. There is still more to be done here.

Eliminating the per-voxel overheads associated with even simple
operations like append() is critical for achieving higher performance.
The extra code complexity (and ugliness) are worth it to achieve that
much of a speed increase (2x to 3x).

I'll address the flaw you pointed out w/ centers.num(), which was
indeed an unintentional bug, as that will save memory for sparse volumes.

Best,
  John

On Fri, Apr 03, 2020 at 05:26:17PM +0200, FX wrote:
> Hi John,
>
> > There was a bug that is fixed in the current src code. I'll get you
> > a new tarball shortly if you're not using CVS to stay in sync???
>
> OK thanks, I???ve browsed the cvsweb and found it. I confirm that it fixes the crash.
>
> Still, I believe the code logic is flawed. As I wrote in my original post, centers.num() is guaranteed to return zero in that code. So at the very least, the code is allocating overly large buffers (it???s allocating enough space for all possible points, regardless of the number of actual points).
>
> I see two ways to fix it:
>
> - instead of centers.num() add a new function to ResizeArray that returns the currently allocated size (private member sz)
> - instead of writing to the float buffer, append the points (the logic in ResizeArray should be enough to make this fast)
> - use a std::vector :)
>
> Cheers,
> FX

-- 
NIH Center for Macromolecular Modeling and Bioinformatics
Beckman Institute for Advanced Science and Technology
University of Illinois, 405 N. Mathews Ave, Urbana, IL 61801
http://www.ks.uiuc.edu/~johns/           Phone: 217-244-3349
http://www.ks.uiuc.edu/Research/vmd/