From d73e3bce83ff9b7a76df2c182edbfca92c0cac19 Mon Sep 17 00:00:00 2001 From: Chen Lijun Date: Fri, 29 Nov 2024 17:03:58 +0100 Subject: [PATCH] NeighborListCache: don't build neighbor list during initialization (#983) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Given n radios, neighbor list construction has O(n^2) complexity. If, during initialization, when each radio is added, the neighbor list is reconstructed, we end up having a simulation initialization with O(n^3) complexity. Sidenote: In one of our tests, without this patch, when running a WiFi simulation of 5000 nodes, it took ~40 minutes to just initialize the simulation. Co-authored-by: Levente Mészáros --- .../neighborcache/NeighborListNeighborCache.cc | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/inet/physicallayer/wireless/common/neighborcache/NeighborListNeighborCache.cc b/src/inet/physicallayer/wireless/common/neighborcache/NeighborListNeighborCache.cc index fac357c5f4e..2839b6814a3 100644 --- a/src/inet/physicallayer/wireless/common/neighborcache/NeighborListNeighborCache.cc +++ b/src/inet/physicallayer/wireless/common/neighborcache/NeighborListNeighborCache.cc @@ -96,10 +96,13 @@ void NeighborListNeighborCache::addRadio(const IRadio *radio) RadioEntry *newEntry = new RadioEntry(radio); radios.push_back(newEntry); radioToEntry[radio] = newEntry; - updateNeighborLists(); - maxSpeed = radioMedium->getMediumLimitCache()->getMaxSpeed().get(); - if (maxSpeed != 0 && !updateNeighborListsTimer->isScheduled() && initialized()) - scheduleAfter(refillPeriod, updateNeighborListsTimer); + if (initialized()) { + updateNeighborLists(); + maxSpeed = radioMedium->getMediumLimitCache()->getMaxSpeed().get(); + if (maxSpeed != 0 && !updateNeighborListsTimer->isScheduled()) { + scheduleAfter(refillPeriod, updateNeighborListsTimer); + } + } } void NeighborListNeighborCache::removeRadio(const IRadio *radio) @@ -144,4 +147,3 @@ NeighborListNeighborCache::~NeighborListNeighborCache() } // namespace physicallayer } // namespace inet -