[PR #213] [MERGED] Optimize closest point search using KD-Tree to reduce CPU usage #222

Closed
opened 2026-05-07 00:19:16 +02:00 by BreizhHardware · 0 comments

📋 Pull Request Information

Original PR: https://github.com/IAmTomShaw/f1-race-replay/pull/213
Author: @LRxDarkDevil
Created: 2/2/2026
Status: Merged
Merged: 2/5/2026
Merged by: @IAmTomShaw

Base: mainHead: feature/kd-tree-optimization


📝 Commits (1)

  • 3462872 Optimize closest point search using KD-Tree to reduce CPU usage

📊 Changes

1 file changed (+12 additions, -9 deletions)

View changed files

📝 src/interfaces/race_replay.py (+12 -9)

📄 Description

I noticed that the replay viewer was running pretty heavy on my CPU (hitting 100% usage even on simple replays).
I found out that the app calculates the "closest track point" for every car by scanning all ~4,000 track points every single frame. This adds up to millions of calculations per second just to draw the driver labels.
I swapped that search loop out for a cKDTree (using Scipy). It does the exact same math but is basically instant (O(\log N) instead of O(N)).
Result: The visuals and accuracy are identical, but it uses drastically less CPU and runs smoother.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/IAmTomShaw/f1-race-replay/pull/213 **Author:** [@LRxDarkDevil](https://github.com/LRxDarkDevil) **Created:** 2/2/2026 **Status:** ✅ Merged **Merged:** 2/5/2026 **Merged by:** [@IAmTomShaw](https://github.com/IAmTomShaw) **Base:** `main` ← **Head:** `feature/kd-tree-optimization` --- ### 📝 Commits (1) - [`3462872`](https://github.com/IAmTomShaw/f1-race-replay/commit/3462872117ecf7c2517a80b488f8cb0f375034db) Optimize closest point search using KD-Tree to reduce CPU usage ### 📊 Changes **1 file changed** (+12 additions, -9 deletions) <details> <summary>View changed files</summary> 📝 `src/interfaces/race_replay.py` (+12 -9) </details> ### 📄 Description I noticed that the replay viewer was running pretty heavy on my CPU (hitting 100% usage even on simple replays). I found out that the app calculates the "closest track point" for every car by scanning all ~4,000 track points every single frame. This adds up to millions of calculations per second just to draw the driver labels. I swapped that search loop out for a cKDTree (using Scipy). It does the exact same math but is basically instant ($O(\log N)$ instead of $O(N)$). Result: The visuals and accuracy are identical, but it uses drastically less CPU and runs smoother. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
BreizhHardware 2026-05-07 00:19:16 +02:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/f1-race-replay#222
No description provided.