]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/commit
rc.subr: Optimize repeated sourcing.
authorJilles Tjoelker <jilles@FreeBSD.org>
Sun, 11 Jun 2017 19:06:07 +0000 (19:06 +0000)
committerJilles Tjoelker <jilles@FreeBSD.org>
Sun, 11 Jun 2017 19:06:07 +0000 (19:06 +0000)
commiteaac4bffc7566a21e5e8429caa82d7d4249b9ff1
tree2ae56a939131098a695d9d9add38598fd34572e5
parentb5f0918be5c791c17ee111b9c5d57f266189cae5
rc.subr: Optimize repeated sourcing.

When /etc/rc runs all /etc/rc.d scripts, it has already loaded /etc/rc.subr
but each /etc/rc.d script sources it again (since /etc/rc.d scripts must
also work when started stand-alone).

Therefore, if rc.subr is already loaded, return so sh need not parse the
rest of the file.

A second effect is that there is no longer a compound command around most of
rc.subr. This reduces memory usage while sh is loading rc.subr for the first
time (but this memory is free()d once rc.subr is loaded).

For purposes of porting this to other systems, I do not recommend porting
this to systems with shells that do not have the change to the return
special builtin like in r255215 (before FreeBSD 10.0-RELEASE). This change
ensures that return in the top level of a dot script returns from the dot
script, even if the dot script was sourced from a function.

A comparison of CPU time on an amd64 bhyve virtual machine from a times
command added near the end of /etc/rc, all four values summed:

x orig1
+ quickreturn
+--------------------------------------------------------------------------+
|  +    +              +                             x    x               x|
||______M__A_________|                             |______M___A__________| |
+--------------------------------------------------------------------------+
    N           Min           Max        Median           Avg        Stddev
x   3         1.704         1.802         1.726         1.744   0.051419841
+   3         1.467         1.559         1.487     1.5043333   0.048387326
Difference at 95.0% confidence
-0.239667 +/- 0.113163
-13.7424% +/- 6.48873%
(Student's t, pooled s = 0.0499266)
etc/rc.subr