Problem: Addrman groups peer addresses by network prefix or (when ASMap finds a match) by autonomous system. Without ASMap, grouping classifies the address twice. With ASMap, an IP lookup allocates a temporary key and the decoder calculates a shift distance for each mantissa bit. Building the group can also take several allocations for just a few bytes.
Fix: When ASMap is disabled, skip the extra address classification in GetMappedAS.
Build ASMap lookup keys on the stack and decode integers by shifting each bit into the mantissa.
Reserve space for the address group before appending its bytes.
Time to group one IPv4 address: (Raspberry Pi 5, ns per call, lower is better)
With ASMap Without ASMap
master baseline ███████████████████▉ 1,982 █████▏ 518
80a39cd417 Decode integers ██████████████████▎ 1,830 █████▎ 524
adc7012941 Skip empty map ██████████████████▎ 1,824 ███▉ 390
bbe7b52765 Build lookup key █████████████████▌ 1,744 ████ 394
13e0803197 Reserve group space ████████████████▍ 1,640 ███▏ 307
Across the full series, AddrManAdd is 19.2% faster (59.1 to 49.6 ms).