[Toybox] top overhead

Rob Landley rob at landley.net
Sat Nov 16 23:45:10 PST 2024


On 11/17/24 01:13, Rob Landley wrote:
> It doesn't appear to be doing it here and it's still slow for me, I've 
> meant to track down why and try to speed it up but I didn't think it was 
> necessarily on the ps side? Debian's ps is slower:
> 
> $ time bash -c 'for ((i=0; i<100; i++)); do ps -A >/dev/null; done'
> real    0m4.632s
> user    0m1.649s
> sys    0m2.926s
> $ time bash -c 'for ((i=0; i<100; i++)); do toybox ps -A >/dev/null; done'
> real    0m2.874s
> user    0m1.220s
> sys    0m1.638s
> 
> Seemed most likely to be the crunch_string() stuff being terrible...

Although thinking more about it, how much of that is the command launch 
overhead from /bin/ps dynamicly linking in libgtk3-nocsd (yes really) 
and libproc2 (whatever that is) vs my statically linked toybox?

$ time bash -c 'for ((i=0; i<100; i++)); do /bin/false >/dev/null; done'
real	0m0.099s
user	0m0.071s
sys	0m0.034s

Hmmm, not _that_ much. And 100 execs taking almost 3 seconds is ~3% of 
CPU time per invocation, which is ballpark of what we're seeing in top, 
and it's not my startup code either:

$ time bash -c 'for ((i=0; i<100; i++)); do toybox false >/dev/null; done'
real	0m0.052s
user	0m0.042s
sys	0m0.017s

So maybe it's NOT the display code.

Well, ok: ps is _also_ doing some crunch_string logic to pad fields to 
the right lengths for utf8 because command names and usernames can have 
multicolumn and combining characters. But still...

I'm happy to have somebody bench this and find the bottlenecks. :)

Rob


More information about the Toybox mailing list