Skip to content

FrustumArray: Optimize frustum computations.#33804

Merged
Mugen87 merged 2 commits into
mrdoob:devfrom
Mugen87:dev1
Jun 16, 2026
Merged

FrustumArray: Optimize frustum computations.#33804
Mugen87 merged 2 commits into
mrdoob:devfrom
Mugen87:dev1

Conversation

@Mugen87

@Mugen87 Mugen87 commented Jun 13, 2026

Copy link
Copy Markdown
Collaborator

Related issue: #33797

Description

It turned out FrustumArray computes the frustum for each intersection test over and over again which is quite inefficient. The PR introduces a new method setFromArrayCamera() that allows to compute the frustums once for later intersection tests.

@Mugen87 Mugen87 requested a review from RenaudRohlinger June 13, 2026 11:48
@github-actions

github-actions Bot commented Jun 13, 2026

Copy link
Copy Markdown

📦 Bundle size

Full ESM build, minified and gzipped.

Before After Diff
WebGL 365.59
86.85
365.59
86.85
+0 B
+0 B
WebGPU 667.09
184.91
667.13
184.92
+42 B
+8 B
WebGPU Nodes 665.13
184.61
665.17
184.62
+42 B
+11 B

🌳 Bundle size after tree-shaking

Minimal build including a renderer, camera, empty scene, and dependencies.

Before After Diff
WebGL 507.7
123.42
507.7
123.42
+0 B
+0 B
WebGPU 747.08
201.29
746.74
201.34
-346 B
+57 B
WebGPU Nodes 697.4
188.92
697.05
188.94
-346 B
+21 B

@Mugen87 Mugen87 added this to the r185 milestone Jun 14, 2026
Comment thread src/math/FrustumArray.js Outdated

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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 );

}

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Good point! I've added copy() and use it in clone() now.

@Mugen87 Mugen87 merged commit 4d1d644 into mrdoob:dev Jun 16, 2026
10 checks passed
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