Performance: Particle collision
HIGH IMPACT
Particle collision affects frame rendering speed and input responsiveness by increasing CPU and GPU workload during physics calculations.
void Update() {
var spatialGrid = BuildSpatialGrid(particles);
foreach (var cell in spatialGrid) {
CheckCollisionsWithinCell(cell);
}
}void Update() {
foreach (var particle in particles) {
foreach (var other in particles) {
if (particle != other && particle.Bounds.Intersects(other.Bounds)) {
HandleCollision(particle, other);
}
}
}
}| Pattern | Collision Checks | CPU Usage | Frame Rate Impact | Verdict |
|---|---|---|---|---|
| Naive double loop | O(n²) | High | Severe frame drops | [X] Bad |
| Spatial partitioning | O(n) | Low to Medium | Smooth frame rate | [OK] Good |