Skip to content

Collision Zone Performance Refactor [SYNTH-132]#1354

Open
azaleacolburn wants to merge 48 commits into
devfrom
colbura/132/collision-zone-perf
Open

Collision Zone Performance Refactor [SYNTH-132]#1354
azaleacolburn wants to merge 48 commits into
devfrom
colbura/132/collision-zone-perf

Conversation

@azaleacolburn

@azaleacolburn azaleacolburn commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

Task

SYNTH-132

Symptom

Performance tanks when robots and pieces enter zones. Generally zones cause poor performance.

This is due to the way in which ZoneSceneObjects handle collisions. Basically, each one creates a sensor, then subscribes to every collision between all Jolt bodies, this is horribly expensive for two reasons:

  1. Not every zone should care about every object, e.g., scoring zones only care about game pieces. So the zones have to filter through a lot of information they don't care about.
  2. A lot of Jolt body collisions happen, so for complicated robots like 2471's 2018 bot, each zone has to deal with each body's collision with the zone's sensor.

Solution

Each sub-class of ZoneSceneObject now implements a function called checkObjectsInZone, which is responsible for manually going through every object that the zone cares about and checking if they are in the zone, then performing the needed actions given that information.

Instead of listening for collisions, these functions (in ScoringZoneSceneObject and ProtectedZoneSceneObject) draw bounding boxes around every object they care about (e.g. each robot), then check if that bounding box overlaps with that of the zone.

Verification

We don't have standardized performance benchmarks, but the lag that used to be present when a robot enters a protected zone is gone. Try this with 2471's 2018 bot, the difference is actually huge (on my machine).

The performance for game pieces in scoring zones is gone, however on some fields (e.g. 2023), there complicated jolt bodies around the scoring zone, which can cause placed bodies to lag slightly. However, other parts of the scoring zone are unaffected.

Tests have been updated to match the new way zones work.


Before merging, ensure the following criteria are met:

  • All acceptance criteria outlined in the ticket are met.
  • Necessary test cases have been added and updated.
  • A feature toggle or safe disable path has been added (if applicable).
  • User-facing polish:
    • Ask: "Is this ready-looking?"
  • Cross-linking between Jira and GitHub:
    • PR links to the relevant Jira issue.
    • Jira ticket has a comment referencing this PR.

@azaleacolburn azaleacolburn changed the title Collision Zone Performance Refactor Collision Zone Performance Refactor [SYNTH-132] Jul 1, 2026
@azaleacolburn azaleacolburn marked this pull request as ready for review July 1, 2026 16:48
@azaleacolburn azaleacolburn requested review from a team as code owners July 1, 2026 16:48
@azaleacolburn azaleacolburn force-pushed the colbura/132/collision-zone-perf branch from ead903f to 9468a61 Compare July 1, 2026 16:49
@azaleacolburn azaleacolburn self-assigned this Jul 10, 2026
@azaleacolburn azaleacolburn added enhancement physics Relating to either the underlying physics engine or the usage of it refactor The most important part of software development. labels Jul 10, 2026

@AlexD717 AlexD717 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The protected zone collisions seem to be triggering when they are not supposed to sometimes (had it happen multiple times but doesn't happen every time)

Fission._.Synthesis.-.Google.Chrome.2026-07-10.11-08-50.-.Trim.mp4

Comment thread fission/src/mirabuf/ScoringZoneSceneObject.ts Outdated

@rutmanz rutmanz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm only requesting changes for the acronyms. Also because I could reproduce Alexey's issue with premature contact penalties

Comment on lines -87 to -92
// Remove from any scoring zones
const zones = World.sceneRenderer.filterSceneObjects(x => x instanceof ScoringZoneSceneObject)
zones.forEach(x => {
if (this._gamePieceBodyId) ScoringZoneSceneObject.removeGamepiece(x, this._gamePieceBodyId)
})

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

what was the original purpose of this

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It was old game pieces removing themselves from old scoring zones. I don't know why this would ever be needed, but we're doing things in such a way that this couldn't ever be necessary.

Plus, the function being called here wouldn't even work, since it compares objects of different origin by reference.

Comment thread fission/src/mirabuf/MirabufSceneObject.ts Outdated
Comment thread fission/src/util/Utility.ts
Comment thread fission/src/mirabuf/ProtectedZoneSceneObject.ts
Comment thread fission/src/systems/physics/PhysicsSystem.ts Outdated
@azaleacolburn azaleacolburn force-pushed the colbura/132/collision-zone-perf branch from d8532ca to d9ff69e Compare July 10, 2026 23:28
@azaleacolburn azaleacolburn force-pushed the colbura/132/collision-zone-perf branch from c6f942d to 76be4b5 Compare July 13, 2026 16:27
@azaleacolburn azaleacolburn reopened this Jul 13, 2026
@azaleacolburn azaleacolburn marked this pull request as draft July 13, 2026 17:26
@azaleacolburn azaleacolburn marked this pull request as ready for review July 13, 2026 17:46
@azaleacolburn azaleacolburn requested a review from Copilot July 13, 2026 17:46

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 18 out of 18 changed files in this pull request and generated 8 comments.

Comment thread fission/src/systems/physics/PhysicsSystem.ts
Comment thread fission/src/mirabuf/MirabufSceneObject.ts
Comment thread fission/src/mirabuf/MirabufSceneObject.ts
Comment on lines +138 to +149
private generateVisualProperties(): VisualProperties | undefined {
// `GetWorldTransform` returns a reference, destroying it causes a memory out of bounds later
const newTransform = World.physicsSystem.getBody(this.parentBodyId!)!.GetWorldTransform()
const transformHasNotUpdated =
this._cachedFieldTransformation && newTransform.Equals(this._cachedFieldTransformation)

// Update translation, rotation, and scale only if the field has moved
if (transformHasNotUpdated && !this._deltaTransHasUpdated) return undefined

if (this._cachedFieldTransformation) JOLT.destroy(this._cachedFieldTransformation)
this._cachedFieldTransformation = newTransform
this._deltaTransHasUpdated = false
Comment thread fission/src/mirabuf/ZoneSceneObject.ts
Comment thread fission/src/mirabuf/ProtectedZoneSceneObject.ts Outdated
Comment thread fission/src/mirabuf/ProtectedZoneSceneObject.ts
Comment on lines +1 to +4
import type Jolt from "@azaleacolburn/jolt-physics"
import * as THREE from "three"
import Pako from "pako"
import World from "@/systems/World"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement physics Relating to either the underlying physics engine or the usage of it refactor The most important part of software development.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants