FrustumArray: Optimize frustum computations.#33804
Merged
Merged
Conversation
📦 Bundle sizeFull ESM build, minified and gzipped.
🌳 Bundle size after tree-shakingMinimal build including a renderer, camera, empty scene, and dependencies.
|
RenaudRohlinger
requested changes
Jun 16, 2026
Collaborator
There was a problem hiding this comment.
Nice optimization overall.
Could we preserve the cached state in clone() here? Right now an initialized FrustumArray clones to an empty one, so intersection checks on the clone return false until setFromArrayCamera() is called again.
One option would be to add the usual copy() helper and have clone() delegate to it:
/**
* Copies the values of the given frustum array to this instance.
*
* @param {FrustumArray} source - The frustum array to copy.
* @return {FrustumArray} A reference to this frustum array.
*/
copy( source ) {
this.coordinateSystem = source.coordinateSystem;
this._count = source._count;
for ( let i = 0; i < source._count; i ++ ) {
if ( this._frustums[ i ] === undefined ) this._frustums[ i ] = new Frustum();
this._frustums[ i ].copy( source._frustums[ i ] );
}
this._frustums.length = source._count;
return this;
}
clone() {
return new this.constructor().copy( this );
}
Collaborator
Author
There was a problem hiding this comment.
Good point! I've added copy() and use it in clone() now.
RenaudRohlinger
approved these changes
Jun 16, 2026
This was referenced Jun 16, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Related issue: #33797
Description
It turned out
FrustumArraycomputes the frustum for each intersection test over and over again which is quite inefficient. The PR introduces a new methodsetFromArrayCamera()that allows to compute the frustums once for later intersection tests.