Reduce per-position ORM lookups when tracing profiled cable paths #135

Open
opened 2026-04-05 16:22:05 +02:00 by MrUnknownDE · 0 comments
Owner

Originally created by @pheus on 3/17/2026

NetBox Version

v4.5.4

Python Version

3.12

Area(s) of Concern

  • User Interface
  • REST API
  • GraphQL API
  • Python ORM
  • Other

Details

While reviewing the multi-position tracing fix in #21681, I noticed a follow-up performance opportunity in CablePath.from_origin() when tracing profiled cables.

Today, Step 6 resolves each (termination, position) pair by calling cable_profile.get_peer_termination() individually. That is correct, but it can result in one ORM lookup per pair, which becomes increasingly expensive for multi-position and multi-connector profiles.

A follow-up optimization could batch the peer lookup for a profiled segment and resolve the mapped positions in memory, rather than querying once per pair. This should reduce query count without changing behavior.

I do not have a formal benchmark yet; this came up during code review rather than production troubleshooting. The expected result would be fewer database queries and better cable-path tracing performance, especially for larger profiled/trunk topologies.

*Originally created by @pheus on 3/17/2026* ### NetBox Version v4.5.4 ### Python Version 3.12 ### Area(s) of Concern - [ ] User Interface - [ ] REST API - [ ] GraphQL API - [x] Python ORM - [ ] Other ### Details While reviewing the multi-position tracing fix in #21681, I noticed a follow-up performance opportunity in `CablePath.from_origin()` when tracing profiled cables. Today, Step 6 resolves each `(termination, position)` pair by calling `cable_profile.get_peer_termination()` individually. That is correct, but it can result in one ORM lookup per pair, which becomes increasingly expensive for multi-position and multi-connector profiles. A follow-up optimization could batch the peer lookup for a profiled segment and resolve the mapped positions in memory, rather than querying once per pair. This should reduce query count without changing behavior. I do not have a formal benchmark yet; this came up during code review rather than production troubleshooting. The expected result would be fewer database queries and better cable-path tracing performance, especially for larger profiled/trunk topologies.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github/netbox#135