Version française
Home     About     Download     Resources     Contact us    
Browse thread
Estimating the size of the ocaml community
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: skaller <skaller@u...>
Subject: Re: [Caml-list] The boon of static type checking
On Mon, 2005-02-07 at 21:57, Ville-Pertti Keinonen wrote:
> On Sun, 2005-02-06 at 23:34 -0600, Brian Hurt wrote:
> 
> > optimizations to it.  Of course, the more I look at SSA, the more it looks 
> > like a functional language to me.  So, in effect, the GCC optimization 
> 
> While the single-assignment aspect of SSA could be considered
> "functional", representing control flow using blocks and branches can't.
> 
> > Don't assume that inlining is optimization.  Actually, it generally isn't.  
> 
> Note that for OCaml, more aggressive inlining could be a significant
> improvement, not because it would eliminate calls, but because it could
> eliminate closures. 

Well, Felix can eliminate direct calls, and without
any complex flow control. This is done precisely
to eliminate closures, since in Felix the overhead
is quite large. In addition, the code is much smaller.
For example, this code:

for {i=0;} {i<10} {i++;} { 
  for(j=0} ...
    for {k=0}

consisting of 8 or so nested loops, where 'for'
is actually a HOF, and curried functions are
represented by a function which returns
the closure of a nested function.

This code takes a LONG time to run without
optimisation -- it has to create 4 closures
to do a loop .. and in the inner loop
that's expensive!

However since all the arguments are manifest,
the whole thing can be inlined, resulting in 
a chain of conditional gotos with some increments
which runs 100-1000 times faster and is 20 times
smaller.

> Obviously this doesn't apply to C++.

Sure it does -- although C++ doesn't have proper
function closures, it does have other
related facilities -- applicative objects,
and methods for example. What it does
lack is lexical scoping, meaning you have
to construct closures by hand (or use Felix
which does it for you :).

In some senses, in C++ inlinling is used to 
eliminate abstraction and turn typed code
into untyped code (after type checking),
where Ocaml would use a different technique.

So perhaps inlining in Ocaml 'isn't usually
an optimisation' but in C++ it is mandatory.
Not inlining at all isn't even marginally acceptable:
without it you'd have to use casts as in C,
and forget OO style abstraction (eg get/set methods)
because it would impact performance.

In addition, note that function calls can cost
a lot more than just a CALL machine instruction:
don't forget functions have arguments ... and
also use registers.

-- 
John Skaller, mailto:skaller@users.sf.net
voice: 061-2-9660-0850, 
snail: PO BOX 401 Glebe NSW 2037 Australia
Checkout the Felix programming language http://felix.sf.net