logoalt Hacker News

jll29 • yesterday at 5:06 PM • 7 replies • view on HN

While some comparisons may look silly, the fact that the touch command's binary should exceed Turbo Pascal is insane: the command basically creates an empty file or updates the file change date if the file already exists, not more.

There's no reason (other than laziness) why that should take more than 2k.

On the other hand, a lot of boilerplace code is repeated in each and every command. When I first learned as a kid about UNIX commands being ordinary programs, I was intrigued (there is nothing "special" about them, you can also write your own!) but also shocked about the overhead compared to an architecture in which e.g. the shell contained all (at least core) commands compiled into a single binary, which could share all the error handing, startup code, command line parsing code and so on.


Replies

zahlman • yesterday at 5:29 PM

> the command basically creates an empty file or updates the file change date if the file already exists, not more.

GNU coreutils touch does a lot more than that. My local copy is about 95k; it allows for choosing from multiple different timestamps to update; suppressing the (default) creation of an empty file if it doesn't already exist; operating on symlinks directly rather than following them (if the system supports it); specifying a custom timestamp rather than "now" (including by parsing a date string), and of course outputting a help message and a version.

➕ show 2 replies
pron • today at 12:57 AM

By "laziness", do you mean attention to costs? Because there's been a ~30,000x inflation in RAM between 1986 and today (probably much more, because we didn't have virtual memory, let alone fast SSDs), and what's silly is to ignore that 1GB of RAM has about the same impact on the machine as 20kB in 1986. Software back then (and even a decade later) was significantly more bloated than the "lazy" programs of today.

Of course we spent a lot of effort cramming as much as we could into every byte back then, but it wasn't because of laziness, but because there was no choice and the value of that work to the user was many, many times higher than it is today.

zvmaz • yesterday at 9:43 PM

> There's no reason (other than laziness) why that should take more than 2k.

I presume you know some of the intricacies of coreutils or the touch program. I'll probably go and donate to whomever receives donations for coreutils; it's the least I can do: Show some respect to the developers of these free and open source tools.

agumonkey • yesterday at 7:42 PM

I'd love to have a graph of gnu [core]utils growth over time. IIRC in Unix days, these simple utils were simple.. until they had to support various flags, and various hosts ..

raddan • yesterday at 8:33 PM

If you run `strace` you can get a hint at why `touch` (and any modern, compiled C binary) might be big: it is doing way more than you think it does, and you definitely _want_ a lot of that. For example, any program that uses the C standard library needs to have that code available-- since virtually every C program is going to use it, it will be loaded and mmap'ped into some region of memory. The stack needs to be set up, memory protection bits will be set, a random value is read to be used as a stack canary, etc, etc. I count on the order of 50+ system calls.

Watching `mv` do its thing is even better. About 100 system calls, including playing nice with SELinux in case it happens to be installed, just to issue a single `renameat2` system call.

Don't forget that we're running on a 64-bit machine. MS-DOS in 1986 was a 16-bit machine? The word size on a modern machine is bigger because we have a bigger address space, more registers, and more instructions.

We want speed and security and convenience and pleasant error messages. All of this is put here by the compiler to ensure that we have nice things. It sounds awesome to have such a small Pascal compiler, and it makes the modern state of binaries seem bloated, but all those extra bytes are paying for things that we want. There's probably a little bloat, but really, there is not much bloat.

mitxela • today at 12:43 AM

The minimum size for a program is about 20k due to page alignment and sections. That's one page each for text, data, bss, rodata, and file headers that don't get loaded into memory at all.

1/5

teiferer • yesterday at 5:29 PM

Agree with everything you wrote, but if you go look for bloat on your storage device, the last thing that will be of any significance is that overhead.

➕ show 1 reply