From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Delivered-To: caml-list@yquem.inria.fr Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by yquem.inria.fr (Postfix) with ESMTP id A9B53BC88 for ; Mon, 7 Feb 2005 15:58:17 +0100 (CET) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id j17EwH6n027281 for ; Mon, 7 Feb 2005 15:58:17 +0100 Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id PAA09290 for ; Mon, 7 Feb 2005 15:58:16 +0100 (MET) Received: from slinky.cs.nyu.edu (SLINKY.CS.NYU.EDU [128.122.20.14]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id j17EwFXk029096 for ; Mon, 7 Feb 2005 15:58:16 +0100 Received: from localhost (localhost [127.0.0.1]) by slinky.cs.nyu.edu (8.12.10+Sun/8.12.10) with ESMTP id j17Ew9W3025689; Mon, 7 Feb 2005 09:58:09 -0500 (EST) Date: Mon, 7 Feb 2005 09:58:09 -0500 (EST) From: Igor Pechtchanski Reply-To: caml-list@inria.fr To: Michael Walter Cc: Brian Hurt , caml-list@inria.fr Subject: Re: [Caml-list] The boon of static type checking In-Reply-To: <877e9a17050206221653d14456@mail.gmail.com> Message-ID: References: <1107741266.6363.362.camel@pelican.wigram> <877e9a17050206221653d14456@mail.gmail.com> Importance: Normal MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Miltered: at nez-perce with ID 42078209.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at concorde with ID 42078207.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; caml-list:01 wrote:01 wrote:01 compiler:01 ocaml:01 optimising:01 inlining:01 inlining:01 compiler:01 fwiw:01 inlined:01 compilers:01 ...:98 functions:01 functions:01 X-Spam-Checker-Version: SpamAssassin 3.0.2 (2004-11-16) on yquem.inria.fr X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.0.2 X-Spam-Level: On Mon, 7 Feb 2005, Michael Walter wrote: > On Sun, 6 Feb 2005 23:34:02 -0600 (CST), Brian Hurt wrote: > > Probably a bad idea, but I've got to jump in here. > > > > Full disclosure: I *hate* C++. Mainly because I've actually written real > > programs in it. The next time I have to use C++ in any sort of serious > > way I'm registering c++sucks.com and starting a website to catalog all the > > different ways C++ sucks. Feel free to stop reading at this point. > :-) As someone who has background in compiler optimizations (of Java, not C++, but they are similar enough in the areas below), I'd like to address one of Brian's points. > > > Again, C++ provides inline functions which > > > provide a way Ocaml does not have so easily > > > for optimising. > > > > Don't assume that inlining is optimization. Actually, it generally isn't. > > Having actually timed it on modern hardware, a function call costs like > > 2-3 clock cycles these days. Plus 1-2 clock cycles per argument. This is > > compared to the 10-30 clock cycles a mispredicted branch costs, the 20+ > > clock cycles an L1 cache miss/L2 cache hit costs, and the 100-350+ clock > > cycles of an L2 cache miss/memory fetch. > Inlining for very small functions generally is an optimization. > > > What little inlining is a good idea can be done by the compiler, > Yep, usually the "inline when appropriate" compiler switch + something > like__forceinline for very small functions (for paranoia reasons) > seems to be the way to go in my experience. FWIW, I agree with Brian that inlining in itself is most often not an optimization at all. However, the main power of inlining is that it enables the compiler to apply intraprocedural optimizations globally. Consider a huge complex dispatch function that, when inlined, boils down to one method call (due to, e.g., constant propagation). Most modern compilers also do specialization if code bloat due to inlining is an issue (I don't know off-hand if g++ does). Igor -- http://cs.nyu.edu/~pechtcha/ |\ _,,,---,,_ pechtcha@cs.nyu.edu ZZZzz /,`.-'`' -. ;-;;,_ igor@watson.ibm.com |,4- ) )-,_. ,\ ( `'-' Igor Pechtchanski, Ph.D. '---''(_/--' `-'\_) fL a.k.a JaguaR-R-R-r-r-r-.-.-. Meow! "The Sun will pass between the Earth and the Moon tonight for a total Lunar eclipse..." -- WCBS Radio Newsbrief, Oct 27 2004, 12:01 pm EDT