[PR #7366] [MERGED] Fix #7365: Optimize calculation of prefix utilization #13233

Closed
opened 2025-12-29 22:26:08 +01:00 by adam · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/netbox-community/netbox/pull/7366
Author: @shuichiro-makigaki
Created: 9/25/2021
Status: Merged
Merged: 9/28/2021
Merged by: @jeremystretch

Base: developHead: optimize-prefix-util


📝 Commits (1)

  • d514290 Fix #7365: Optimize calculation of prefix utilization

📊 Changes

1 file changed (+3 additions, -5 deletions)

View changed files

📝 netbox/ipam/models/ip.py (+3 -5)

📄 Description

Fixes: #7365

By profiling the python interpreter, I found Prefix.get_utilization() in ipam/models/ip.py consumes a lot of time.
Especially, IPSet.add() in a loop is the biggest bottle-neck.
https://github.com/netbox-community/netbox/blob/develop/netbox/ipam/models/ip.py#L491

In my experiment, instead of IPset.add(), IPSet() constructor could reduces the execution time. IPSet() also can dedup IPs and IP ranges.

Five times quick experiments results (unit: second):

v3.0.3 fixed
37.93 9.24
38.51 9.18
39.06 10.06
37.80 9.98
38.46 10.22

🔄 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/netbox-community/netbox/pull/7366 **Author:** [@shuichiro-makigaki](https://github.com/shuichiro-makigaki) **Created:** 9/25/2021 **Status:** ✅ Merged **Merged:** 9/28/2021 **Merged by:** [@jeremystretch](https://github.com/jeremystretch) **Base:** `develop` ← **Head:** `optimize-prefix-util` --- ### 📝 Commits (1) - [`d514290`](https://github.com/netbox-community/netbox/commit/d5142906885f3e9284a4d942eafa1b3e0197eff2) Fix #7365: Optimize calculation of prefix utilization ### 📊 Changes **1 file changed** (+3 additions, -5 deletions) <details> <summary>View changed files</summary> 📝 `netbox/ipam/models/ip.py` (+3 -5) </details> ### 📄 Description <!-- Thank you for your interest in contributing to NetBox! Please note that our contribution policy requires that a feature request or bug report be opened for approval prior to filing a pull request. This helps avoid wasting time and effort on something that we might not be able to accept. Please indicate the relevant feature request or bug report below. IF YOUR PULL REQUEST DOES NOT REFERENCE AN ACCEPTED BUG REPORT OR FEATURE REQUEST, IT WILL BE MARKED AS INVALID AND CLOSED. --> ### Fixes: #7365 By profiling the python interpreter, I found `Prefix.get_utilization()` in `ipam/models/ip.py` consumes a lot of time. Especially, `IPSet.add()` in a loop is the biggest bottle-neck. https://github.com/netbox-community/netbox/blob/develop/netbox/ipam/models/ip.py#L491 In my experiment, instead of `IPset.add()`, `IPSet()` constructor could reduces the execution time. `IPSet()` also can dedup IPs and IP ranges. Five times quick experiments results (unit: second): v3.0.3 | fixed -------|------- 37.93 | 9.24 38.51 | 9.18 39.06 | 10.06 37.80 | 9.98 38.46 | 10.22 --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
adam added the pull-request label 2025-12-29 22:26:08 +01:00
adam closed this issue 2025-12-29 22:26:08 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#13233