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

Add statistics to VoxelPrimitive #12463

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open

Add statistics to VoxelPrimitive #12463

wants to merge 9 commits into from

Conversation

lukemckinstry
Copy link
Contributor

@lukemckinstry lukemckinstry commented Feb 5, 2025

For performance & profiling purposes, add additional statistics from Cesium3DTilesetStatistics to be tracked in VoxelPrimitive as they are in Cesium3DTileset.

  • textureByteLength
  • visited
  • numberOfTilesWithContentReady

Based on my understanding of voxels it seems that selected and numberOfTilesWithContentReady mean the same thing in the voxel context, so I just implemented numberOfTilesWithContentReady.

Issue number and link

#12297
Follow up to PR #12430

Testing plan

  • The VoxelPrimitive.statistics are not exposed in the public api. A good way to test is to set debug statements and look at a sandcastle with voxels (either generated or loaded).
  • In VoxelTraversal.postPassesUpdate, console.log statistics.visited, statistics.numberOfTilesWithContentReady, statistics.textureByteLength after line 800. The first 2 stats are identical to the existing values for LOADED and TOTAL in the debug message, which can be turned on by setting VoxelTraversal._debugPrint = true. textureByteLength should roughly be a multiple of LOADED.

Author checklist

  • I have submitted a Contributor License Agreement
  • I have added my name to CONTRIBUTORS.md
  • I have updated CHANGES.md with a short summary of my change
  • I have added or updated unit tests to ensure consistent code coverage
  • I have updated the inline documentation, and included code examples where relevant
  • I have performed a self-review of my code

Copy link

github-actions bot commented Feb 5, 2025

Thank you for the pull request, @lukemckinstry!

✅ We can confirm we have a CLA on file for you.

@lukemckinstry
Copy link
Contributor Author

ready now for review @ggetz @jjhembd

@@ -170,7 +170,6 @@ Cesium3DTilesetStatistics.clone = function (statistics, result) {
result.selected = statistics.selected;
result.visited = statistics.visited;
result.numberOfCommands = statistics.numberOfCommands;
result.selected = statistics.selected;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

removing a duplicate line, not directly related to this PR

@ggetz
Copy link
Contributor

ggetz commented Feb 6, 2025

Thanks @lukemckinstry, I will take a pass soon! Could you please update the testing plan and CHANGES.md to help with review?

@lukemckinstry
Copy link
Contributor Author

@ggetz updated change log and test instructions, ready for review

@ggetz
Copy link
Contributor

ggetz commented Feb 10, 2025

I had one comment on the inline documentation, but this is looking good to me! Over to @jjhembd for review and merge.

improve inline docs

Co-authored-by: Gabby Getz <gabby@cesium.com>
Copy link
Contributor

@jjhembd jjhembd left a comment

Choose a reason for hiding this comment

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

Thanks @lukemckinstry! This is looking good overall. I have a couple minor comments, and also some input on how textureByteLength is computed.

primitive.allTilesLoaded.numberOfListeners > 0 ||
primitive.initialTilesLoaded.numberOfListeners > 0;
if (!that._debugPrint && !checkEventListeners) {
return;
Copy link
Contributor

Choose a reason for hiding this comment

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

If there are no event listeners, can we exit before calling traverseRecursive? recursive traversal is not cheap.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The way I have it set up now, statistics.numberOfTilesWithContentReady and statistics.visited rely on the stats gathered in the traversal. Perhaps these stats could be gathered another way during the loadAndUnload function?

Copy link
Contributor Author

@lukemckinstry lukemckinstry Feb 10, 2025

Choose a reason for hiding this comment

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

And unlike events where we can check if events have listeners subscribed we do not really know if anybody is seeking these stats, unless perhaps we had a flag to turn off/on collection of this data.

scratchDimensions,
);
primitive.statistics.textureByteLength =
VoxelTraversal.getApproximateTextureMemoryByteLength(
Copy link
Contributor

Choose a reason for hiding this comment

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

The texture memory size is set once in the Megatexture constructor. We might want to expose the actual size (something like (textureDimension * channelCount * componentByteLength) ** 2) in that class, rather than re-computing the "approximate" size.

Once the Texture is constructed, its size doesn't change. The occupiedCount number indicates how much of the texture is filled with useful data. But even if we haven't loaded anything yet, the texture has already been allocated and is using its full amount of memory.

I think the textureByteLength is mainly used to get an idea of how much memory has been allocated.

We also need to keep track of how many megatextures have been allocated. This is based on how many metadata fields the voxel dataset contains. See the new Megatexture() calls in the VoxelTraversal constructor.

@@ -83,6 +83,9 @@ describe(
});
expect(spyUpdate1.calls.count()).toEqual(1);
expect(spyUpdate2.calls.count()).toEqual(1);
expect(primitive.statistics.numberOfTilesWithContentReady).toEqual(1);
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we update the name/description of this spec to indicate that we are checking more than just "initial tiles loaded and all tiles loaded events" ?

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.

3 participants