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

Destroy out of range scene entities #2808

Draft
wants to merge 2 commits into
base: dev
Choose a base branch
from
Draft

Conversation

AnsisMalins
Copy link
Collaborator

What does this PR change?

This change reduces memory and CPU usage of PartitionSceneEntitiesSystem and ResolveVisualSceneStateSystem.

fix: #2694

How to test the changes?

  1. Launch the explorer
  2. Walk around the Genesis City a lot, look at the profiler, and observe that the game uses a couple megabytes less memory than without this change and that CPU usage of ResolveVisualSceneStateSystem stays low.

Our Code Review Standards

https://github.com/decentraland/unity-renderer/blob/master/docs/code-review-standards.md

Copy link
Contributor

badge

New build in progress, come back later!

for (var i = 0; i < definition.ParcelsCorners.Count; i++)
corners[i] = definition.ParcelsCorners[i];
World.InlineQuery<PartitionScenes, SceneDefinitionComponent, PartitionComponent>(
in existingScenesQuery, ref partitionScenes);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

So this takes 0.12 ms to run on my laptop. If I change it to InlineParallelQuery, it takes 1 ms to run. Crazy.

Bounds sceneBounds = new ();
sceneBounds.SetMinMax(min, max);

float sqrDistance = sceneBounds.SqrDistance(CameraPosition);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Behaviour change: measure the distance to the surface of the bounding box instead the distance to the nearest corner. This is more correct, but might break some other code due to accidental reliance on the quirks of the previous implementation.

Copy link
Collaborator Author

@AnsisMalins AnsisMalins Nov 15, 2024

Choose a reason for hiding this comment

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

Behaviour change: this implementation takes maximum scene height into account. So, if you fly high above the city, it will get unloaded. Or if you look up at the sky, a tall scene next to you will now not count as behind you. Again, this is more "3D correct", but might not be what we want.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Behaviour change: use the bounds of the scene instead of the individual parcels to do the math. This is faster, but if the scene is oddly shaped, less accurate.

@AnsisMalins AnsisMalins changed the title Get rid of partition data Delete out of range scene entities Nov 15, 2024
@AnsisMalins AnsisMalins changed the title Delete out of range scene entities Destroy out of range scene entities Nov 15, 2024
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.

ResolveVisualSceneStateSystem overhead
1 participant