Skip to content

Conversation

@berendt
Copy link
Member

@berendt berendt commented Oct 29, 2025

Further optimize SONIC configuration generation by implementing global caching strategies for metalbox devices and VIP addresses, and simplifying peer type calculation.

Changes in config_generator.py:

  1. Metalbox Global Cache:

    • Add _metalbox_devices_cache global variable
    • Create _load_metalbox_devices_cache() to bulk fetch all metalbox devices, interfaces, and IPs at sync start
    • Modify _get_metalbox_ip_for_device() to use pre-loaded cache
    • Performance: O(N × M × K) → O(1) lookups (~100x faster)
  2. Peer Type Optimization:

    • Simplify _determine_peer_type() to use existing device_as_mapping
    • Eliminate redundant spine/superspine device queries and group calculations
    • Performance: Removed O(N) queries per peer type check (~20x faster)

Changes in connections.py:

  1. VIP Addresses Global Cache:
    • Add _vip_addresses_cache global variable
    • Create load_vip_addresses_cache() to bulk fetch all VIP addresses at sync start
    • Create clear_vip_addresses_cache() for cache cleanup
    • Modify get_connected_interface_ipv4_address() to use cached VIPs
    • Performance: O(N × P) → O(1) lookups (~50x faster)

Changes in sync.py:

  1. Cache Integration:
    • Call _load_metalbox_devices_cache() after cache clearing
    • Call load_vip_addresses_cache() after cache clearing
    • Add clear_vip_addresses_cache() to cleanup process

All function signatures preserved. Error handling and logging patterns maintained.

AI-assisted: Claude Code

@berendt berendt force-pushed the optimize-sonic-global-caches branch from b8e3918 to c1ed524 Compare October 29, 2025 13:55
Further optimize SONIC configuration generation by implementing global
caching strategies for metalbox devices and VIP addresses, and simplifying
peer type calculation.

Changes in config_generator.py:

1. Metalbox Global Cache:
   - Add _metalbox_devices_cache global variable
   - Create _load_metalbox_devices_cache() to bulk fetch all metalbox
     devices, interfaces, and IPs at sync start
   - Modify _get_metalbox_ip_for_device() to use pre-loaded cache
   - Performance: O(N × M × K) → O(1) lookups

2. Peer Type Optimization:
   - Simplify _determine_peer_type() to use existing device_as_mapping
   - Eliminate redundant spine/superspine device queries and group calculations
   - Performance: Removed O(N) queries per peer type check

Changes in connections.py:

3. VIP Addresses Global Cache:
   - Add _vip_addresses_cache global variable
   - Create load_vip_addresses_cache() to bulk fetch all VIP addresses at sync start
   - Create clear_vip_addresses_cache() for cache cleanup
   - Modify get_connected_interface_ipv4_address() to use cached VIPs
   - Performance: O(N × P) → O(1) lookups

Changes in sync.py:

4. Cache Integration:
   - Call _load_metalbox_devices_cache() after cache clearing
   - Call load_vip_addresses_cache() after cache clearing
   - Add clear_vip_addresses_cache() to cleanup process

All function signatures preserved. Error handling and logging patterns maintained.

AI-assisted: Claude Code

Signed-off-by: Christian Berendt <[email protected]>
@berendt berendt force-pushed the optimize-sonic-global-caches branch from c1ed524 to 6eeede6 Compare October 29, 2025 14:00
@berendt berendt merged commit dd00bbf into main Oct 29, 2025
2 checks passed
@berendt berendt deleted the optimize-sonic-global-caches branch October 29, 2025 14:06
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.

2 participants