caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* RE: [Caml-list] Generation of streams is slow
@ 2001-07-17 16:01 Dave Berry
  0 siblings, 0 replies; 16+ messages in thread
From: Dave Berry @ 2001-07-17 16:01 UTC (permalink / raw)
  To: Jacques Garrigue, avv; +Cc: caml-list

Two people at CMU implemented this a couple of years ago.  They called
it "destination-passing style", because the implementation passes an
uninitialised "destination" that is filled in later.  There are some
subtle interactions with the garbage collector, which they investigated.
I don't know why they didn't publish this work -- perhaps they found
some problems with it that I never heard about.

There have also been papers on automatically discovering
source-to-source transformations for this sort of optimisation.  And
there is a very old paper called "tail-recursion modulo Cons" for doing
this particular case in Lisp.

Dave.


-----Original Message-----
From: Jacques Garrigue [mailto:garrigue@kurims.kyoto-u.ac.jp]
Sent: 17 July 2001 03:37
To: avv@quasar.ipa.nw.ru
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Generation of streams is slow


From: "Alexander V. Voinov" <avv@quasar.ipa.nw.ru>

> Sorry :-), an example in Prolog is:
> 
> f([],[]) :- !.
> f([H1|T1], [H2|T2]) :-
> 	g(H1,H2),
> 	f(T1,T2).
> 
> Last call in this case deals with the final locations of the tails of
> the lists. Though chains of indirection may be long, they are handled
by
> the garbage collection, whose launch strategy may be based more on
> heuristics than on a theory. In OCaml, if it were possible to handle
the
> special case of the _two_ last calls of the form:
> 
>     h::(make_tail arg1 argN),
> 
> that is
> 	CALL make_tail
> 	CONS
> 
> and change them to
>  
> 	PREPARE_CONS
> 	CALL make_tail
> 
> the scope of tail recursion optimization would increase. But it's
> unlikely that this idea didn't come to developers. Which may mean that
> this [being not that simple] is impossible.

You can see:
    Yasuhiko Minamide, "A functional representation of data-structures
    with a hole", POPL'98.
It does exactly that, using linear types to make sur the hole is
initialized later.

I don't know of any published compiler implementing it, but this may
exist.

Jacques
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ:
http://caml.inria.fr/FAQ/
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/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr


^ permalink raw reply	[flat|nested] 16+ messages in thread
* [Caml-list] Generation of streams is slow
@ 2001-07-13 22:06 Alexander V. Voinov
  2001-07-14  2:27 ` Daniel de Rauglaudre
  0 siblings, 1 reply; 16+ messages in thread
From: Alexander V. Voinov @ 2001-07-13 22:06 UTC (permalink / raw)
  To: caml-list

Hi All,

I've run the following program and found it to be extremely slow. Why?
Does it mean that streams are worth using only when they are built from
input text channels, and in all other cases they are just a waste of
time?

Alexander

open Printf

let gen_stream n =
  let rec gs i n =
    if i = n then [< 'n >] else [< 'i; (gs (i+1) n) >]
  in
  gs 1 n

let rec stupid_loop n s =
  if n > 0 then begin
    if n mod 1000 = 0 then (print_char('.'); flush stdout);
    let i = Stream.next s in
    if i <> n then raise (Failure "they don't match");
    stupid_loop (n+1) s
  end
  else 0;;

let _ =
  stupid_loop 1 (gen_stream 100000);;


-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr


^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2001-07-20  8:06 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-07-17 16:01 [Caml-list] Generation of streams is slow Dave Berry
  -- strict thread matches above, loose matches on Subject: below --
2001-07-13 22:06 Alexander V. Voinov
2001-07-14  2:27 ` Daniel de Rauglaudre
2001-07-14  2:51   ` Alexander V. Voinov
2001-07-14  4:04     ` Daniel de Rauglaudre
2001-07-14  4:15       ` Alexander V. Voinov
2001-07-14  4:40         ` Alexander V. Voinov
2001-07-14  8:34           ` Daniel de Rauglaudre
2001-07-14 18:08             ` Alexander V. Voinov
2001-07-14 19:02               ` Daniel de Rauglaudre
2001-07-14 19:51                 ` Alexander V. Voinov
2001-07-14 21:59                 ` Alexander V. Voinov
2001-07-14 22:29                   ` Daniel de Rauglaudre
2001-07-17  2:36               ` Jacques Garrigue
2001-07-14  8:31         ` Daniel de Rauglaudre
2001-07-20  7:49           ` Chris Hecker

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).