<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE message PUBLIC
  "-//MLarc//DTD MLarc output files//EN"
  "../../mlarc.dtd"[
  <!ATTLIST message
    listname CDATA #REQUIRED
    title CDATA #REQUIRED
  >
]>

  <?xml-stylesheet href="../../mlarc.xsl" type="text/xsl"?>


<message 
  url="2003/11/f031112a371b21ef7253bc2a605c9b87"
  from="Brian Hurt &lt;bhurt@s...&gt;"
  author="Brian Hurt"
  date="2003-11-12T19:44:11"
  subject="Re: [Caml-list] Executable size?"
  prev="2003/11/8d3470473c76d4d737a32634cf2fd9f6"
  next="2003/11/22901198363d2fec6aeb0a21290445ef"
  prev-in-thread="2003/11/0e23cd4114467c85799878b5f0ff09f5"
  next-in-thread="2003/11/22901198363d2fec6aeb0a21290445ef"
  prev-thread="2003/11/6e7b16172669003eddadf343f60fb496"
  next-thread="2003/11/8f2ee87fc20d2eebce952ca4abe9d3be"
  root="../../"
  period="month"
  listname="caml-list"
  title="Archives of the Caml mailing list">

<thread subject="[Caml-list] Executable size?">
<msg 
  url="2003/11/e8fd0dfd31a596714c76d480bdfae207"
  from="John J Lee &lt;jjl@p...&gt;"
  author="John J Lee"
  date="2003-11-12T16:15:01"
  subject="[Caml-list] Executable size?">
<msg 
  url="2003/11/0ececf4654a552e0efdc76ebdb05a19f"
  from="Richard Jones &lt;rich@a...&gt;"
  author="Richard Jones"
  date="2003-11-12T17:35:37"
  subject="Re: [Caml-list] Executable size?">
<msg 
  url="2003/11/bda9330dde477c713c11ca12756d241f"
  from="Dustin Sallings &lt;dustin@s...&gt;"
  author="Dustin Sallings"
  date="2003-11-12T18:07:12"
  subject="Re: [Caml-list] Executable size?">
<msg 
  url="2003/11/2862f492e5c858822827730fa8eafeac"
  from="Sven Luther &lt;sven.luther@w...&gt;"
  author="Sven Luther"
  date="2003-11-12T18:32:39"
  subject="Re: [Caml-list] Executable size?">
<msg 
  url="2003/11/e3564502e6692e2148d9f1b60d6f0c22"
  from="John J Lee &lt;jjl@p...&gt;"
  author="John J Lee"
  date="2003-11-12T18:51:16"
  subject="Re: [Caml-list] Executable size?">
<msg 
  url="2003/11/c68f377e1fbdd825192dd31b8efbff7d"
  from="Sven Luther &lt;sven.luther@w...&gt;"
  author="Sven Luther"
  date="2003-11-13T09:10:27"
  subject="Re: [Caml-list] Executable size?">
<msg 
  url="2003/11/71a0c66034a92266bac0f272cebaf5ca"
  from="John J Lee &lt;jjl@p...&gt;"
  author="John J Lee"
  date="2003-11-13T13:47:02"
  subject="Re: [Caml-list] Executable size?">
<msg 
  url="2003/11/25d3eec7ad9a818f1f2a5aede8703ba9"
  from="Sven Luther &lt;sven.luther@w...&gt;"
  author="Sven Luther"
  date="2003-11-13T14:28:05"
  subject="Re: [Caml-list] Executable size?">
</msg>
</msg>
</msg>
</msg>
</msg>
</msg>
<msg 
  url="2003/11/dd378fd18d2cba0deb5cf6916002b2ab"
  from="Brian Hurt &lt;bhurt@s...&gt;"
  author="Brian Hurt"
  date="2003-11-12T18:07:23"
  subject="Re: [Caml-list] Executable size?">
<msg 
  url="2003/11/dc67149a7d78ca2c79f2c1ec5ff756ee"
  from="Sven Luther &lt;sven.luther@w...&gt;"
  author="Sven Luther"
  date="2003-11-12T18:39:43"
  subject="Re: [Caml-list] Executable size?">
<msg 
  url="2003/11/75a43061468c8402d71028fd7a43ec6b"
  from="Karl Zilles &lt;zilles@1...&gt;"
  author="Karl Zilles"
  date="2003-11-12T18:58:51"
  subject="Re: [Caml-list] Executable size?">
<msg 
  url="2003/11/8fe1648602c0b38c615182f558e3dba1"
  from="Brian Hurt &lt;bhurt@s...&gt;"
  author="Brian Hurt"
  date="2003-11-12T20:30:37"
  subject="Re: [Caml-list] Executable size?">
</msg>
</msg>
<msg 
  url="2003/11/8d3470473c76d4d737a32634cf2fd9f6"
  from="Brian Hurt &lt;bhurt@s...&gt;"
  author="Brian Hurt"
  date="2003-11-12T19:05:32"
  subject="Re: [Caml-list] Executable size?">
<msg 
  url="2003/11/30fcc60dbf2162cf992eed578ede5bb8"
  from="Kamil Shakirov &lt;kamils@i...&gt;"
  author="Kamil Shakirov"
  date="2003-11-13T04:10:33"
  subject="Re: [Caml-list] Executable size?">
<msg 
  url="2003/11/cf321eb53140a3017c46f5d61f7d405c"
  from="Richard Jones &lt;rich@a...&gt;"
  author="Richard Jones"
  date="2003-11-13T09:06:42"
  subject="Re: [Caml-list] Executable size?">
</msg>
</msg>
<msg 
  url="2003/11/713cebbf306ed0c2ba9eb576f7a36c77"
  from="Sven Luther &lt;sven.luther@w...&gt;"
  author="Sven Luther"
  date="2003-11-13T09:18:36"
  subject="Re: [Caml-list] Executable size?">
</msg>
</msg>
</msg>
<msg 
  url="2003/11/0e23cd4114467c85799878b5f0ff09f5"
  from="John J Lee &lt;jjl@p...&gt;"
  author="John J Lee"
  date="2003-11-12T18:47:00"
  subject="Re: [Caml-list] Executable size?">
<msg 
  url="2003/11/f031112a371b21ef7253bc2a605c9b87"
  from="Brian Hurt &lt;bhurt@s...&gt;"
  author="Brian Hurt"
  date="2003-11-12T19:44:11"
  subject="Re: [Caml-list] Executable size?">
<msg 
  url="2003/11/22901198363d2fec6aeb0a21290445ef"
  from="Basile Starynkevitch &lt;basile.starynkevitch@i...&gt;"
  author="Basile Starynkevitch"
  date="2003-11-12T20:10:42"
  subject="Re: [Caml-list] Executable size?">
</msg>
<msg 
  url="2003/11/5d8ed462d90ff736b6f0c01518ef3b65"
  from="John J Lee &lt;jjl@p...&gt;"
  author="John J Lee"
  date="2003-11-12T20:35:40"
  subject="Re: [Caml-list] Executable size?">
<msg 
  url="2003/11/dced1efd242ca0c9b43c3768982ddd9e"
  from="Brian Hurt &lt;bhurt@s...&gt;"
  author="Brian Hurt"
  date="2003-11-12T20:52:56"
  subject="Re: [Caml-list] Executable size?">
<msg 
  url="2003/11/3e1c995e35cec5998236f414bdc223f4"
  from="David Brown &lt;caml-list@d...&gt;"
  author="David Brown"
  date="2003-11-12T21:36:14"
  subject="Re: [Caml-list] Executable size?">
</msg>
</msg>
<msg 
  url="2003/11/b93b426cc0b10e3d9bd024af470742a9"
  from="Eric Dahlman &lt;edahlman@a...&gt;"
  author="Eric Dahlman"
  date="2003-11-12T22:18:18"
  subject="Re: [Caml-list] Executable size?">
<msg 
  url="2003/11/e1480d57477bc32caa3fb64e225ca6ff"
  from="Brian Hurt &lt;bhurt@s...&gt;"
  author="Brian Hurt"
  date="2003-11-12T22:34:15"
  subject="Re: [Caml-list] Executable size?">
<msg 
  url="2003/11/ad98f40f9ebd9794d97fa0f0a67f32a5"
  from="Eric Dahlman &lt;edahlman@a...&gt;"
  author="Eric Dahlman"
  date="2003-11-12T22:54:51"
  subject="Re: [Caml-list] Executable size?">
</msg>
<msg 
  url="2003/11/ba636ecd1fb724781a975f3a6976f883"
  from="John J Lee &lt;jjl@p...&gt;"
  author="John J Lee"
  date="2003-11-12T23:36:05"
  subject="Re: [Caml-list] Executable size?">
</msg>
</msg>
<msg 
  url="2003/11/eeb28a6005d16b393316f3f003de65eb"
  from="John J Lee &lt;jjl@p...&gt;"
  author="John J Lee"
  date="2003-11-12T23:59:39"
  subject="Re: [Caml-list] Executable size?">
<msg 
  url="2003/11/f00e08180a1ab731de0fc4fa8c9330bb"
  from="Karl Zilles &lt;zilles@1...&gt;"
  author="Karl Zilles"
  date="2003-11-13T00:20:42"
  subject="Re: [Caml-list] Executable size?">
<msg 
  url="2003/11/7ab9775da554c1df94ee536ef27992e3"
  from="Oleg Trott &lt;oleg_trott@c...&gt;"
  author="Oleg Trott"
  date="2003-11-13T01:30:16"
  subject="[Caml-list] F-sharp (was: Executable size?)">
<msg 
  url="2003/11/e9e72661772b71fc00ec1280a727a273"
  from="Christophe Raffalli &lt;Christophe.Raffalli@u...&gt;"
  author="Christophe Raffalli"
  date="2003-11-14T06:04:05"
  subject="[Caml-list] float_of_num">
</msg>
</msg>
</msg>
<msg 
  url="2003/11/d7f8f4a36c2e046d4c4290c8d9d6bb34"
  from="Eric Dahlman &lt;edahlman@a...&gt;"
  author="Eric Dahlman"
  date="2003-11-13T15:44:21"
  subject="Re: [Caml-list] Executable size?">
<msg 
  url="2003/11/b2d16db3d208c5971fbd1e85af468ff6"
  from="John J Lee &lt;jjl@p...&gt;"
  author="John J Lee"
  date="2003-11-13T19:58:27"
  subject="Re: [Caml-list] Executable size?">
<msg 
  url="2003/11/7346e7f962264608c3236055c3d16d75"
  from="Eric Dahlman &lt;edahlman@a...&gt;"
  author="Eric Dahlman"
  date="2003-11-13T20:37:22"
  subject="Re: [Caml-list] Executable size?">
<msg 
  url="2003/11/757884e18af7a172b305ded316e2c1c1"
  from="John J Lee &lt;jjl@p...&gt;"
  author="John J Lee"
  date="2003-11-13T22:16:51"
  subject="Re: [Caml-list] Executable size?">
</msg>
</msg>
<msg 
  url="2003/11/8e7e66067004e33ecc5251b3f21af44b"
  from="skaller &lt;skaller@o...&gt;"
  author="skaller"
  date="2003-11-15T14:42:35"
  subject="Re: [Caml-list] Executable size?">
<msg 
  url="2003/11/63aa341439daef5caf6c5ed8adc998ec"
  from="John J Lee &lt;jjl@p...&gt;"
  author="John J Lee"
  date="2003-11-15T15:13:30"
  subject="Re: [Caml-list] Executable size?">
<msg 
  url="2003/11/91e68e552501a942264ea37d0b52fa8d"
  from="skaller &lt;skaller@o...&gt;"
  author="skaller"
  date="2003-11-15T19:08:30"
  subject="Re: [Caml-list] Executable size?">
</msg>
</msg>
</msg>
</msg>
<msg 
  url="2003/11/de5255c5acfd45e09ecc91f76e024031"
  from="skaller &lt;skaller@o...&gt;"
  author="skaller"
  date="2003-11-15T14:37:54"
  subject="Re: [Caml-list] Executable size?">
<msg 
  url="2003/11/dcb13375990280267975422d95eb17bd"
  from="John J Lee &lt;jjl@p...&gt;"
  author="John J Lee"
  date="2003-11-15T15:01:31"
  subject="Re: [Caml-list] Executable size?">
<msg 
  url="2003/11/57655e1257a623e2d3dcd339dcbca36b"
  from="skaller &lt;skaller@o...&gt;"
  author="skaller"
  date="2003-11-15T18:54:53"
  subject="Re: [Caml-list] Executable size?">
</msg>
</msg>
</msg>
</msg>
</msg>
</msg>
</msg>
<msg 
  url="2003/11/3caf9264583e81a6c34b9092df597891"
  from="Florian Hars &lt;hars@b...&gt;"
  author="Florian Hars"
  date="2003-11-13T13:37:59"
  subject="Re: [Caml-list] Executable size?">
</msg>
</msg>
</msg>
</msg>
<msg 
  url="2003/11/a3e1a27ce18316f5d944af8c9358d941"
  from="John J Lee &lt;jjl@p...&gt;"
  author="John J Lee"
  date="2003-11-12T18:21:43"
  subject="Re: [Caml-list] Executable size?">
<msg 
  url="2003/11/9a9bf0df20ce6a3fe0dcb9546d8a7a14"
  from="Richard Jones &lt;rich@a...&gt;"
  author="Richard Jones"
  date="2003-11-12T22:53:10"
  subject="Re: [Caml-list] Executable size?">
<msg 
  url="2003/11/1317209bcb631533835b0907a9c5f3b9"
  from="John J Lee &lt;jjl@p...&gt;"
  author="John J Lee"
  date="2003-11-12T23:50:20"
  subject="Re: [Caml-list] Executable size?">
</msg>
</msg>
<msg 
  url="2003/11/e35875dbb026d72841763b2af8639f74"
  from="skaller &lt;skaller@o...&gt;"
  author="skaller"
  date="2003-11-15T13:51:02"
  subject="Re: [Caml-list] Executable size?">
<msg 
  url="2003/11/ecb981b603d7c1c84f940c2730d1d87b"
  from="John J Lee &lt;jjl@p...&gt;"
  author="John J Lee"
  date="2003-11-15T15:26:00"
  subject="Re: [Caml-list] Executable size?">
</msg>
</msg>
</msg>
</msg>
<msg 
  url="2003/11/afc0ed6c2b331f867381141361e9d310"
  from="Dustin Sallings &lt;dustin@s...&gt;"
  author="Dustin Sallings"
  date="2003-11-12T18:05:21"
  subject="Re: [Caml-list] Executable size?">
<msg 
  url="2003/11/f7653abab4587d67e4f3c0f44e21c202"
  from="John J Lee &lt;jjl@p...&gt;"
  author="John J Lee"
  date="2003-11-12T18:37:00"
  subject="Re: [Caml-list] Executable size?">
<msg 
  url="2003/11/032882a4c4c4265f4b7b297c83bcf603"
  from="Vitaly Lugovsky &lt;vsl@o...&gt;"
  author="Vitaly Lugovsky"
  date="2003-11-12T19:01:51"
  subject="Re: [Caml-list] Executable size?">
</msg>
<msg 
  url="2003/11/fe090eb4633f25a5bb774320daad1dfa"
  from="Dustin Sallings &lt;dustin@s...&gt;"
  author="Dustin Sallings"
  date="2003-11-12T19:05:09"
  subject="Re: [Caml-list] Executable size?">
<msg 
  url="2003/11/0b34d659fe0041366bc2ff6e67c2c1a1"
  from="John J Lee &lt;jjl@p...&gt;"
  author="John J Lee"
  date="2003-11-12T20:17:51"
  subject="Re: [Caml-list] Executable size?">
</msg>
</msg>
</msg>
</msg>
<msg 
  url="2003/11/5dd5cba6e148291f19fdcc39b61364ba"
  from="Nicolas Cannasse &lt;warplayer@f...&gt;"
  author="Nicolas Cannasse"
  date="2003-11-13T01:24:47"
  subject="Re: [Caml-list] Executable size?">
</msg>
<msg 
  url="2003/11/ac5d222a4bbe17cc4b0accf0cdc88148"
  from="skaller &lt;skaller@o...&gt;"
  author="skaller"
  date="2003-11-15T13:10:47"
  subject="Re: [Caml-list] Executable size?">
</msg>
</msg>
</thread>

<contents>
On Wed, 12 Nov 2003, John J Lee wrote:

&gt; On Wed, 12 Nov 2003, Brian Hurt wrote:
&gt; 
&gt; &gt; On Wed, 12 Nov 2003, Richard Jones wrote:
&gt; [...]
&gt; &gt; &gt; This is not a criticism of OCaml, but the executables do tend to be
&gt; &gt; &gt; quite large. This seems mainly down to the fact that OCaml links the
&gt; &gt; &gt; runtime library in statically. There was previous discussion on this
&gt; [...]
&gt; &gt; This isn't as bad as it sounds.  A simplistic "hello world!" application
&gt; &gt; in Ocaml weighs in at 112K, versus 11K for the equivelent (dynamically
&gt; &gt; linked) C program- almost entirely either statically linked standard
&gt; &gt; libraries and infrastructure (garbage collections, etc.)- stuff that
&gt; &gt; doesn't expand with larger programs.
&gt; 
&gt; OK.  Is that 100K difference for "hello world" (which doesn't necessarily
&gt; stay the same for larger programs, as you say below) simply a result of
&gt; the fact that C has the "unfair" advantage of already having its runtime
&gt; sitting on everyone's hard drive already?

Actually, I think Ocaml uses C's runtime libraries and builds on top of
them.  For example, if I understand things correctly, Ocaml's printf is a
wrapper which calls C's printf.  Which is why I haven't bothered comparing
Ocaml's size to C programs being statically linked.  Ocaml is at least
nice enough to only link libraries you are actually using (see the
print_string v. printf results).

In addition to a more complicated and complete standard library and 
bultins, Ocaml also has garbage collection, which is non-trivial to 
implement.  I wouldn't be surprised if half or more of that 100K of 
overhead is just the GC.  Currying, exceptions, etc. also have small size 
penalties.

On the other hand, I would argue that these features, while bloating the 
application.  Which is exactly the sort of thing small "benchmark" 
programs don't show.  I don't know how many times I've read or written C 
code like:

int copy_file(char * src, char * dst) {
    char * buf;
    FILE * inf;
    FILE * outf;

    if ((src == NULL) || (dst == NULL)) {
        return EINVAL;
    }

    inf = fopen(src, "rb");
    if (inf == NULL) {
        return errno;
    }

    outf = fopen(dst, "wb");
    if (outf == NULL) {
        fclose(inf);
        return errno;
    }

    buf = (char *) malloc(4096);
    if (buf == NULL) {
        fclose(outf);
        fclose(inf);
        return errno;
    }

    blah blah blah you get the idea

Vr.s the same code in Ocaml:

let copyfile src dst =
    let inf = open_in_bin src
    and outf = open_out_bin dst
    and buf = String.make 4096 ' '
    in
    let rec loop () =
        let c = input inf buf 0 4096 in
        if (c &gt; 0) then
            begin
                output outf buf 0 c;
                loop ()
            end
        else
            ()
    in
    loop ()

The ocaml executable code for copyfile function will be smaller than the C 
version, simply because the ocaml version takes advantage of various 
features of the larger ocaml library and infrastructure- especially (in 
this case) exceptions and garbage collection.  

&gt; 
&gt; 
&gt; &gt; A naive assumption would be that an Ocaml program is about 100K or so
&gt; &gt; larger than the equivelent C program.  Not much, considering how easy it
&gt; &gt; is to get executables multiple megabytes in size.
&gt; 
&gt; [...]
&gt; &gt; Ocaml gets a lot more code reuse, and thus can actually lead to smaller
&gt; &gt; executables.
&gt; 
&gt; I don't understand what you mean by that (probably my fault).  What do you
&gt; mean by "code reuse" here?  I usually understand that phrase to mean using
&gt; code written by people other than me, but you seem to mean it in a
&gt; different sense.
&gt; 

I was using it in the most literal sense- using code more than once, in
more than one way.  In general, it's much better to have only one copy of
a function, used in two places, than two copies of the function.  The 
trick is that generally the two copies are not exactly identical- if 
the functions are, for example, the length of a linked list, one function 
might operate on a linked list of integers, another a linked list of 
floats.  Ocaml encourages you to program in a generic way- you actually 
have to work at it to write a linked list length routine that *isn't* 
generic, the naive implementation is (so is the optimized version).

Again, this generally isn't a problem in small programs, which easily fit 
into you brain as a whole.  Code reuse becomes more of a trick on moderate 
to large programs, especially moderate to large programs with more than 
one programmer.  How many times have we reimplemented linked lists in C?

&gt; 
&gt; &gt; Unless you have special constraints, the difference between C program
&gt; &gt; sizes and Ocaml program sizes are not enough to be worth worrying about.
&gt; 
&gt; I don't really agree that the problem of distributing simple (few lines of
&gt; code) applications in small executables is all that "special".  Certainly
&gt; there are *many* applications where you don't need that; equally, there
&gt; are quite a few where you do need/want that.

I was thinking of special cases where the difference of a 100K or 1M or so 
is the difference between working and not working.  If you are, for 
example, trying to fit your program on a 512K ROM, Ocaml's overhead might 
be a problem.  

-- 
"Usenet is like a herd of performing elephants with diarrhea -- massive,
difficult to redirect, awe-inspiring, entertaining, and a source of
mind-boggling amounts of excrement when you least expect it."
                                - Gene Spafford 
Brian

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners

</contents>

</message>

