From 9e9e4f90ef299aeb19c31c41d15af76d6667569c Mon Sep 17 00:00:00 2001 From: Rayhaan Jaufeerally Date: Fri, 9 Oct 2026 00:07:46 +0200 Subject: [PATCH] fib: take best routes from the table 16384 at a time The kernel task read changes of best route from the routing table 1024 at a time. A poll of the table does two binary searches and takes a read lock in every shard, however few events the shard has; with the 128 shards of an 8-core machine, that overhead was paid for every 8 events a shard, and the profile of a full-table load showed 8% to 9% of the daemon's CPU time in the reader's searches and locks. This change raises the batch to 16384. In the Linux VM, with four peers sending the synthetic table of 1.23 million prefixes, the kernel is in step 2.2 s after the first route instead of 2.9 s, and the daemon's CPU time over the load falls 13%; the reader's share drops from 9% to under 1%. With one peer the kernel-side share falls the same way and the CPU time 3%. A batch holds up to 16384 small records between polls, which is about a megabyte. Testing: the fib unit tests pass; measured with scripts/profile/full-table.sh with one and four peers. Co-Authored-By: Claude Fable 5.1 --- crates/fib/src/kernel.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/crates/fib/src/kernel.rs b/crates/fib/src/kernel.rs index 9f35304..5e14cab 100644 --- a/crates/fib/src/kernel.rs +++ b/crates/fib/src/kernel.rs @@ -34,8 +34,11 @@ use crate::routes::KernelRoutes; use crate::topology::Topology; use crate::{Fib, FibConfig, FibError, Stop}; -/// How many best routes are taken from the routing table at a time. -const BATCH: usize = 1024; +/// How many best routes are taken from the routing table at a time. A +/// poll of the table costs two binary searches and a lock in every shard, +/// however few events it brings back; with a few hundred shards, a batch +/// of a thousand had that overhead for every eight events a shard. +const BATCH: usize = 16384; /// How many requests are sent to the kernel in one write. const WRITE_BATCH: usize = 512;