[fpc-pascal] "Hello world" syscalls

Michael Van Canneyt michael at freepascal.org
Tue Jan 7 05:44:10 CET 2020



On Tue, 7 Jan 2020, Vojtěch Čihák via fpc-pascal wrote:

> Hi,
>  
> I found this article: https://drewdevault.com/2020/01/04/Slow.html
> but FPC is missing, so I wrote simple:
>  
> program Project1;
> begin
>   writeln('Hello world!');
> end. 
>  
> $ fpc -O3 -XX Project1.pas
>  
> $ strace -C ./Project1
>  
> % time     seconds  usecs/call     calls    errors syscall
> ------ ----------- ----------- --------- --------- ----------------
>  30.83    0.000037          37         1           readlink
>  25.83    0.000031           8         4           ioctl
>  18.33    0.000022          22         1           write
>  17.50    0.000021           5         4           rt_sigaction
>   4.17    0.000005           5         1           getrlimit
>   3.33    0.000004           4         1           execve
> ------ ----------- ----------- --------- --------- ----------------
> 100.00    0.000120                    12           total

If I do the same, I get this:

% time     seconds  usecs/call     calls    errors syscall
------ ----------- ----------- --------- --------- ----------------
   0.00    0.000000           0         1           write
   0.00    0.000000           0         4           rt_sigaction
   0.00    0.000000           0         4           ioctl
   0.00    0.000000           0         1           execve
   0.00    0.000000           0         1           readlink
   0.00    0.000000           0         1           getrlimit
------ ----------- ----------- --------- --------- ----------------
100.00    0.000000                    12           total

>  
> It results in 30kB binary, 12 syscalls total, 6 unique. IMO appropriate.

Size of the binary is irrelevant.

> Has the fact that strings are managed types some relevance here?

No. And in your example, there are no managed strings, since shortstring
will be used.

The rtl (system unit in particular) just takes some setting up.
* execve is normal, you'll always have it.
* Readlink is to determine paramstr(0). 
* rt_sigaction is to set up runtime errors (signal handling). 
* getrlimit is to set up stack/heap checking. 
* ioctl() is to determine whether stdio file descriptors are terminals or not.

These are all one-time calls. No amount of optimization will reduce this.

The real call: write(), happens only once, as it should be.

So these numbers are perfectly normal. 
In the lifetime of any real application, they're negligable.

Michael.


More information about the fpc-pascal mailing list