improved last

Denys Vlasenko vda.linux at googlemail.com
Wed May 21 17:44:49 UTC 2008


On Wednesday 21 May 2008 17:59, Cristian Ionescu-Idbohrn wrote:
> On Wed, 21 May 2008, Denys Vlasenko wrote:
> 
> > On Wednesday 21 May 2008 01:04, Cristian Ionescu-Idbohrn wrote:
> > > Please consider for inclusion this optional (and yes, bigger)
> > > variation of 'last', which a collegue of mine wrote (see copyright
> > > mote), as we badly need something like this at work.
> > >
> > > The output is identical with sysvinit 'last' at an extra cost of
> > > 1238 bytes.
> > >
> > > function                                             old     new   delta
> > > last_main                                            448    1084    +636
> > > show_entry                                             -     355    +355
> > > .rodata                                           120946  121080    +134
> > > add_entry                                              -      45     +45
> > > packed_usage                                       17924   17956     +32
> > > static.ret                                             -       8      +8
> > > static.pos                                             -       8      +8
> > > start_time                                             -       4      +4
> > > show_wide                                              -       4      +4
> > > list                                                 348     352      +4
> > > filename                                               -       4      +4
> > > boot_down                                              -       4      +4
> > > ------------------------------------------------------------------------------
> > > (add/remove: 8/0 grow/shrink: 4/0 up/down: 1238/0)           Total: 1238 bytes
> >
> > Can you work on it a bit more?
> >
> > static int boot_down = 0;
> >
> > Completely wasted four bytes. grep for it.
> 
> Alright, I did that and managed to save 2 bytes.  I also tested to
> remove most of the other static variables.  That led to increased
> size.  If you think the 2 bytes lighter version of the applet is
> interesting, just let me know.

This is a 10-minute worth of shrinking:

function                                             old     new   delta
show_entry                                           355     359      +4
boot_down                                              4       1      -3
show_wide                                              4       -      -4
filename                                               4       -      -4
last_main                                           1084    1030     -54
------------------------------------------------------------------------------
(add/remove: 0/2 grow/shrink: 1/2 up/down: 4/-65)             Total: -61 bytes

# size last-org.o last.o
   text    data     bss     dec     hex filename
   1730      12      24    1766     6e6 last-org.o
   1680       8      17    1705     6a9 last.o

See attached patch.

You can easily continue. For example, by folding get_state() into its
single call site you can eliminate global variable boot_down.
And so on...
--
vda
-------------- next part --------------
A non-text attachment was scrubbed...
Name: last_fancy.c.diff
Type: text/x-diff
Size: 3245 bytes
Desc: not available
Url : http://lists.busybox.net/pipermail/busybox/attachments/20080521/d1c99bb2/attachment.bin 


More information about the busybox mailing list