caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Pierre Chambart <pierre.chambart@ocamlpro.com>
To: Goswin von Brederlow <goswin-v-b@web.de>,
	Christoph H??ger <christoph.hoeger@tu-berlin.de>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] <SPAM> Re: Compile-time performance problem
Date: Tue, 8 Nov 2016 11:49:19 +0100	[thread overview]
Message-ID: <207e46ad-86f5-4171-b1bc-7525f9e6338b@ocamlpro.com> (raw)
In-Reply-To: <20161108101015.GC18517@frosties>

Le 08/11/2016 à 11:10, Goswin von Brederlow a écrit :
> On Tue, Nov 08, 2016 at 09:56:33AM +0100, Christoph H??ger wrote:
>> let (<+) a v = Array.append a [|v|] 
>> let foo k s =
>>   ((fun k  -> fun s  -> (k#_continue_ (object (self)  end)) 1)
>>      (object (self)
>>         val _continue_ =
>>           fun x  ->
>>             (fun k  ->
>>                fun s  ->
>>                  ((fun k  -> fun s  -> (k#_continue_ (object (self)  end)) 2)
> ...
>
> Do you have to use objects there? Does the problem go away if you use
> a simple type for the continuation?
>
> The thing with CPS is that your code can be converted into simple
> jumps instead of function calls. Everything is a tail call. And all
> your objects are dummies that can be optimized away if you try hard
> enough. Really complex dummies. I can imagine the bytecode simply
> creates the objects and calls the methods while the native code
> optimizes it all away. Hard to say if that is linear (and really
> slow), quadratic or exponential with just one example though.
>
> MfG
> 	Goswin
>
It is linear with a very large constant factor.

It is linked to a known exponential case in closure conversion that was
limited: In case of deeply nested functions when the initial closeness
estimation is systematically wrong, this can fall into that case. To prevent
problems the search depth is limited to 5. See
https://github.com/ocaml/ocaml/blob/trunk/asmcomp/closure.ml#L765
and
https://github.com/ocaml/ocaml/blob/trunk/asmcomp/closure.ml#L1195

Please fill a bug on mantis for this.

Side not: Flambda does not have this kind of problem, this estimation
is done by a linear time fixpoint. (this might be the only known example
where flambda compilation is faster...)
-- 
Pierre



      reply	other threads:[~2016-11-08 10:49 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-07 17:01 [Caml-list] " Christoph Höger
2016-11-07 17:07 ` Christoph Höger
2016-11-07 17:18   ` Nicolas Ojeda Bar
2016-11-07 17:32     ` Christoph Höger
2016-11-08  8:56       ` Christoph Höger
2016-11-08 10:10         ` Goswin von Brederlow
2016-11-08 10:49           ` Pierre Chambart [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=207e46ad-86f5-4171-b1bc-7525f9e6338b@ocamlpro.com \
    --to=pierre.chambart@ocamlpro.com \
    --cc=caml-list@inria.fr \
    --cc=christoph.hoeger@tu-berlin.de \
    --cc=goswin-v-b@web.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).