Skip to content

[Bug]: $O(N^2)$ Bottleneck and Hardcoded TCA in CollisionEngine #192

Description

@AryanYadav215

Bug description

[Performance/Bug]: $O(N^2)$ Bottleneck and Hardcoded TCA in CollisionEngine

Description

As an ECSoC'26 contributor reviewing the orbital engine logic (referencing the file kepler.pdf verbatim), I found major architectural and logical flaws in the CollisionEngine that will cause performance degradation and inaccurate predictions[cite: 1].

Issues Identified

  1. $O(N^2)$ Algorithmic Bottleneck: CollisionEngine.predict_collisions utilizes a nested loop to calculate distances between every single object pair in the catalog (for i in range(len(propagated)): ... for j in range(i + 1, len(propagated)):)[cite: 1]. For a catalog of thousands of satellites and debris, this results in hundreds of millions of distance calculations, severely bottlenecking the system[cite: 1].
  2. Logical Flaw in Time of Closest Approach (TCA): The engine currently calculates the distance between objects at the exact instant of datetime.utcnow(), rather than propagating the trajectories to identify the actual Time of Closest Approach[cite: 1]. Furthermore, the conjunctionTime is hardcoded to now + datetime.timedelta(minutes=12.0) regardless of orbital dynamics[cite: 1].

Steps to reproduce

Steps to Reproduce

  1. Populate the database with a realistic number of SpaceObject entries (e.g., > 5,000)[cite: 1].
  2. Trigger the run_collision_scanning task[cite: 1].
  3. Observe the task hanging or timing out due to the unoptimized $O(N^2)$ loop[cite: 1].
  4. Review generated conjunctions and note the hardcoded 12.0 minute forward projection[cite: 1].

Expected behavior

Expected Behavior

The engine utilizes a broad-phase spatial filter or orbital plane pre-filtering to scale efficiently for thousands of objects[cite: 1]. It dynamically propagates orbits forward in time to calculate the true Time of Closest Approach (TCA)[cite: 1].

Actual behavior

Actual Behavior

The engine uses a deeply nested loop to evaluate distances for every possible object pair, resulting in an $O(N^2)$ bottleneck[cite: 1]. Additionally, it calculates the distance between objects at the exact instant of datetime.utcnow() and simply hardcodes the future conjunction time to exactly 12 minutes later (now + datetime.timedelta(minutes=12.0)) regardless of actual orbital dynamics[cite: 1].

Screenshots or recordings

No response

Platform

Backend

Environment

No response

Error messages or logs

Difficulty

None

Priority

None

Additional information

No response

Metadata

Metadata

Assignees

Labels

assignedIndicates that the issue has been assigned to a contributor who is actively working on it.backendBackend developmentbugSomething isn't workingdatabaseDatabase and schema related changestype:backendChanges backend services or server-side logic.type:bugFixes an existing bug or unexpected behavior.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions