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

Lazy initialization of the upAdjustment matrix (Three.js) #601

Closed
wants to merge 5 commits into from

Conversation

Nmzik
Copy link
Contributor

@Nmzik Nmzik commented Jul 5, 2024

  1. Instead of creating a new Matrix4 per tile, reuse it.
  2. Pass the upAdjustment matrix to each loader constructor, keeping a reference to it without instantiating and copying the matrix itself.

@Nmzik Nmzik changed the title Lazy Lazy initialization of the upAdjustment matrix (Three.js) Jul 5, 2024
Copy link
Contributor

@gkjohnson gkjohnson left a comment

Choose a reason for hiding this comment

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

Thanks! I'd prefer not to change the Loader constructor signatures, though, and think we should keep the new Matrix4 on the class. There's already a ton of memory allocation that's going to necessarily happen during during loading and parsing of model geometry and one more Matrix4 is going to be really minor.

Comment on lines 82 to 83
this.upAdjustment = null;

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 move this to a global value, instead? See tempMat etc above.

Comment on lines -580 to +585
loader.adjustmentTransform.copy( upAdjustment );
loader.adjustmentTransform = upAdjustment;
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's still use the "copy" function instead of assigning the variable.

Comment on lines +573 to +575
const cached = tile.cached;
const cachedTransform = cached.transform;

Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a reason these were moved? It would be best to only perform a minimal amount of changes in a PR, I think, and avoid unneeded code organization updates. IT makes it easier to understand what's changing and why.

@@ -24,6 +24,7 @@ const INITIAL_FRUSTUM_CULLED = Symbol( 'INITIAL_FRUSTUM_CULLED' );
const tempMat = new Matrix4();
const tempMat2 = new Matrix4();
const tempVector = new Vector3();
let upAdjustment = null;
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's just create the matrix4 here. Only creating something like a matrix4 when needed is a bit of an over optimization, I think, especially when we're creating other variables. In fact we can probably just use of the existing tempMat objects as long as it's not being used in the parseTiles function, already.

@gkjohnson
Copy link
Contributor

gkjohnson commented Jul 14, 2024

Closing in favor of #610 #611

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