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

Overallocate geomBuffer. #941

Merged
merged 2 commits into from
Oct 30, 2018
Merged

Overallocate geomBuffer. #941

merged 2 commits into from
Oct 30, 2018

Conversation

manthey
Copy link
Contributor

@manthey manthey commented Oct 18, 2018

When reusing an existing buffer for webGL, permit it to be larger than strictly necessary. If reallocating an existing buffer, allocate some extra space. For dynamic data sets, this avoids reallocating buffers on every geometry update, substantially reducing garbage collection.

In one examples with ~35,000 lines containing a total of ~1,000,000 vertices where the number of vertices changes periodically, this reduced geometry update time by ~200 ms.

@manthey manthey force-pushed the overallocate-geometry-buffers branch from 46a0f23 to bd5abc6 Compare October 18, 2018 12:16
* Add an extra factor of allocateLarger, but if a power-of-two is between
* the specified size and the larger permitted size, perfer the power-of-
* two. */
var allocate = len;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we care for power of two?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might not. In general, many memory allocation schemes have different pools that change when a power-of-two boundary is crossed. I don't actually know if Firefox or Chrome do (they used to, but they may no longer do so). By choosing a power-of-two when convenient, it is possible that we will use the memory pool for smaller objects in preference to the larger. The optimization is a guess -- if the buffer gets reallocated bigger, then the smaller size is wasted. If it doesn't get bigger, then we might gain an efficiency.

I can take it out if you'd prefer.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can take it out if you'd prefer.

I have a slight preference to take it out since this behavior is not documents in the 'user documentation' plus it complicates things further without clear benefit.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do.

When reusing an existing buffer for webGL, permit it to be larger than
strictly necessary.  If reallocating an existing buffer, allocate some
extra space.  For dynamic data sets, this avoids reallocating buffers on
every geometry update, substantially reducing garbage collection.

In one examples with ~35,000 lines containing a total of ~1,000,000
vertices where the number of vertices changes periodically, this reduced
geometry update time by ~200 ms.
@manthey manthey force-pushed the overallocate-geometry-buffers branch from bd5abc6 to 0a9172d Compare October 30, 2018 12:52
@manthey manthey merged commit 7c100bb into master Oct 30, 2018
@manthey manthey deleted the overallocate-geometry-buffers branch October 30, 2018 15:27
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

Successfully merging this pull request may close these issues.

2 participants