Skip to content

Enhance the speed of 'show arp'#121

Merged
gord1306 merged 1 commit into
edge-core:202311.Xfrom
link19430:Enhance_speed_of_show_arp
Nov 18, 2025
Merged

Enhance the speed of 'show arp'#121
gord1306 merged 1 commit into
edge-core:202311.Xfrom
link19430:Enhance_speed_of_show_arp

Conversation

@link19430

Copy link
Copy Markdown

What I did

  • Optimize FDB lookup and ARP display performance

How I did it

  • Cache all BVID → VLAN mappings in advance to avoid repeated get_vlan_id_from_bvid() calls.
  • Replace linear search over bridge_mac_list with a dictionary lookup (vlan, mac) → if_name for O(1) performance.
  • Greatly reduces latency for show arp with large ARP/FDB tables.

How to verify it

  • Execute the test case

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR optimizes the performance of the show arp command by implementing caching mechanisms for BVID-to-VLAN mappings and replacing linear searches with dictionary lookups.

Key Changes:

  • Pre-cache all BVID to VLAN ID mappings to avoid repeated database lookups
  • Convert bridge MAC list to a dictionary for O(1) lookup performance
  • Fix minor spacing issue in JSON parsing

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread scripts/nbrshow Outdated
Comment on lines +77 to +84
bvid_list = set()
for s in fdb_str:
fdb_entry = s
fdb = json.loads(fdb_entry.split(":", 2)[-1])
if not fdb:
continue
if 'bvid' in fdb:
bvid_list.add(fdb['bvid'])

Copilot AI Nov 17, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The FDB entries are now processed twice: once to collect BVIDs (lines 77-84) and once to build the bridge_mac_list (lines 97-128). Consider combining these loops to collect BVIDs and process entries in a single pass, which would be more efficient. You could use bvid_to_vlan.setdefault() or check if a BVID is new before calling get_vlan_id_from_bvid().

Copilot uses AI. Check for mistakes.
Optimize FDB lookup and ARP display performance
- Cache all BVID → VLAN mappings in advance to avoid repeated get_vlan_id_from_bvid() calls.
- Replace linear search over bridge_mac_list with a dictionary lookup (vlan, mac) → if_name for O(1) performance.
- Greatly reduces latency for show arp with large ARP/FDB tables.
@link19430 link19430 force-pushed the Enhance_speed_of_show_arp branch from 9d64536 to 71d1ab4 Compare November 18, 2025 02:10
@link19430

Copy link
Copy Markdown
Author

Hi @gord1306

Please help review, thanks.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread scripts/nbrshow
else:
bvid_to_vlan[bvid] = None
except Exception:
bvid_to_vlan[bvid] = bvid

Copilot AI Nov 18, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When an exception occurs while resolving BVID to VLAN ID, the code stores the raw bvid value in the cache. This could lead to inconsistent behavior because vlan_id is expected to be a VLAN ID integer, but bvid might be in a different format (e.g., it could be an OID string). This will later be used as int(vlan_id) on line 122, which could fail or produce unexpected results. Consider either storing None and continuing (skipping the entry), or ensuring the bvid value is properly converted to an integer format that makes sense as a fallback VLAN ID.

Suggested change
bvid_to_vlan[bvid] = bvid
bvid_to_vlan[bvid] = None

Copilot uses AI. Check for mistakes.
@gord1306 gord1306 merged commit 674fde4 into edge-core:202311.X Nov 18, 2025
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants