A few people say that our network scripts are slow. Well, they were damn slow when 1.11 first hit portage. 😦 Stopping is always the slowest as every module is loaded and evaluated. As we add more modules to do more fancy networking tricks, we get slower and slower. So over time we've added a few speed ups.
First, we cached a lot of repeatedly called functions (mainly _provides, _before and _after). Then we removed a function which checked to see if a module over-wrote any functions (nice idea, but very very slow and didn't always work as you could nest functions in bash). This brought us from a stop time of around 15 seconds to the current stop time of around 5 seconds on my laptop (1.6 Celery for reference).
Ever since I've been bugged with how slow the sort routine agriffis wrote (which replaced my even slower bubble sort) as it's the slowest point of the whole process. Infact, sorting the modules when stopping normally took around 2.5 seconds on my laptop, the only part of the process which takes over 0.3 seconds.
So I had a wild idea, lets try and implement a topological sort routine. Luckily I had made one earlier for the main rc system, and written in bash (the C tsort command is in /usr/bin and may not always be available).
This has reduced our times to as follows with
lan_config=( "dhcp" )
# time /etc/init.d/net.lan stop real 0m3.005s user 0m1.740s sys 0m1.000s # time /etc/init.d/net.lan start real 0m2.662s user 0m1.612s sys 0m0.888s
Now, thats fast - almost cut the times in two! 😃 We get even faster with less modules, and of course there's still the option to force modules.
Experience it when baselayout-1.12.0_pre10 hits a portage near you!