caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: "Marcin 'Qrczak' Kowalczyk" <qrczak@knm.org.pl>
To: caml-list@inria.fr
Subject: Re: [Caml-list] OCaml troll on Slashdot
Date: Fri, 18 Mar 2005 19:44:56 +0100	[thread overview]
Message-ID: <87br9gx07r.fsf@qrnik.zagroda> (raw)
In-Reply-To: <Pine.LNX.4.58.0503180933530.23606@shell1.sea5.speakeasy.net> (brogoff@speakeasy.net's message of "Fri, 18 Mar 2005 09:46:07 -0800 (PST)")

brogoff <brogoff@speakeasy.net> writes:

>> It's not the fault of the mapping function but of the stack
>> being non-extensible. A user-written recursion can blow it too.
>> Functional programming is supposed to encourage recursion, and a
>> non-tail-recursive 'map' is much more readable than alternatives.
>
> Interesting approach. Do you have any information as to how big the
> performance hit is?

No.

I recall there was some paper which claimed that heap allocation is
significantly more expensive than stack allocation even with the most
clever GCs. I couldn't find it now. My stack frame allocation is very
similar to heap allocation.

What matters is not only the overhead of stack overflow checking
itself, but the combined effect of several interdependent design
choices. Even if I measured the cost of stack overflow checking in
isolation, it would not give a meaningful answer because it requires
and provides other things and thus the cost would be different if
applied to an implementation with different properties.

I implement a custom stack instead of using the system stack. Effects:
- a C global variable is used for the stack pointer instead of a
  machine register, thus stack frame allocation and access to stack
  contents is slower (even if it was not checked for overflow)
- checking for stack overflow adds overhead
+ tail call optimization is easier
+ scanning the stack by the GC is easier
+ portable green threads are easier
+ stack overflow is not fatal
+ triggering a context switch is done by faking the stack overflow
  condition, so it doesn't need an *additional* overhead (except that
  the stack limit is a volatile variable and allocation of a stack
  frame is one machine instruction longer because of that)

> I've never used SML/NJ except for a few toy programs, but I recall
> that it puts activation records on the Gc'ed heap (correct me if I'm
> wrong someone) so that call/cc is more efficient, so stack overflows
> shouldn't be a problem there either. Could you comment on why you
> chose extensible stacks rather than the SMLNJ approach for Kogut.

It should be slightly more efficient because allocating stack frames
doesn't increase the frequency of GCs, because stack frames don't need
to be copied by a copying GC, and because they don't need a link to
the previous frame (they do have a "descriptor" pointer though, which
stores their size and is also used to generate stack trace on uncaught
exceptions).

I haven't measured how large the efficiency difference is. It could
even be negative, because I must deallocate a stack frame explicitly,
but I doubt that.

> What I think you intend is that you'd rather it be easy to write
> safe code than that it be asy to write fast code, in the language.
> I wouldn't mind that, as long as it isn't ridiculously hard or
> impossible to do the latter in the language.

It's hard to allow everything...

The combined effect of dynamic typing, passing function arguments in
C global variables, using a custom stack and stack overflow checking
caused the Ackermann function to be 5 times slower than in C.

-- 
   __("<         Marcin Kowalczyk
   \__/       qrczak@knm.org.pl
    ^^     http://qrnik.knm.org.pl/~qrczak/


  reply	other threads:[~2005-03-18 18:45 UTC|newest]

Thread overview: 71+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-03-15  1:29 Karl Zilles
2005-03-15  8:32 ` [Caml-list] " Oliver Bandel
2005-03-15  8:45   ` Michael Vanier
2005-03-15  8:59     ` Jon Harrop
2005-03-15 20:17       ` Yoann Padioleau
2005-03-15 20:36         ` Jon Harrop
2005-03-15 21:03           ` padiolea
2005-03-15 21:40             ` William D.Neumann
2005-03-15 22:12               ` Yoann Padioleau
2005-03-15 23:07                 ` William D.Neumann
2005-03-15 23:39                   ` Jon Harrop
2005-03-15 23:54                     ` Thomas Fischbacher
2005-03-16  0:03                   ` Christopher Dutchyn
2005-03-16  0:18                   ` Oliver Bandel
2005-03-16  1:05                     ` Yoann Padioleau
2005-03-16  2:55                       ` Oliver Bandel
2005-03-16 11:23                         ` Thomas Fischbacher
2005-03-16 23:41                           ` Oliver Bandel
2005-03-16 13:33                         ` Yoann Padioleau
2005-03-16 23:59                           ` Oliver Bandel
2005-03-16  3:01                     ` Jon Harrop
2005-03-16 13:10                       ` Yoann Padioleau
2005-03-16 13:41                         ` Jacques Garrigue
2005-03-16 14:14                           ` Yoann Padioleau
2005-03-17  0:27                             ` Oliver Bandel
2005-03-16 17:43                           ` brogoff
2005-03-16 19:51                             ` Jon Harrop
2005-03-17  3:35                               ` brogoff
2005-03-17  3:48                                 ` Yaron Minsky
2005-03-17 10:16                                   ` Jon Harrop
2005-03-17 10:47                                     ` Oliver Bandel
2005-03-17 18:06                                     ` brogoff
2005-03-17 19:15                                       ` Marcin 'Qrczak' Kowalczyk
2005-03-18 17:46                                         ` brogoff
2005-03-18 18:44                                           ` Marcin 'Qrczak' Kowalczyk [this message]
2005-03-17 21:31                                       ` Oliver Bandel
2005-03-17  9:45                                 ` Christian Szegedy
2005-03-17 10:31                                 ` Jon Harrop
2005-03-17 11:11                                   ` Ville-Pertti Keinonen
2005-03-17 11:31                               ` tail-recursion vs. no tail-recursion in list functions sebastian.egner
2005-03-17 21:41                                 ` [Caml-list] " Oliver Bandel
2005-03-18  0:04                                   ` David Brown
2005-03-18  0:06                                   ` Karl Zilles
2005-03-18  1:13                                 ` Jacques Garrigue
2005-03-17  0:21                             ` [Caml-list] OCaml troll on Slashdot Oliver Bandel
2005-03-17  1:05                             ` Jacques Garrigue
2005-03-17 17:32                             ` Jason Hickey
2005-03-17 19:06                               ` Marcin 'Qrczak' Kowalczyk
2005-03-17  0:14                           ` Oliver Bandel
2005-03-16  1:38             ` Jacques Garrigue
2005-03-31 11:42         ` Paul Argentoff
2005-03-31 11:41       ` Paul Argentoff
2005-03-15 20:06   ` Yoann Padioleau
2005-03-15  9:25 ` Richard Jones
2005-03-15 10:08   ` YANG Shouxun
2005-03-15 20:02     ` Yoann Padioleau
2005-03-15 22:33       ` Richard Jones
2005-03-16  1:33       ` YANG Shouxun
2005-03-15 10:34   ` padiolea
2005-03-15 10:52     ` Diego Olivier Fernandez Pons
2005-03-15 14:12     ` Eijiro Sumii
2005-03-15 15:25       ` Christophe TROESTLER
2005-03-15 18:05         ` Thomas Fischbacher
2005-03-15 18:26           ` Kip Macy
2005-03-16  0:32             ` Oliver Bandel
2005-03-16 11:26             ` David Fox
2005-03-15 18:55         ` Christopher A. Watford
2005-03-15 19:56           ` Jon Harrop
2005-03-16  0:35             ` Oliver Bandel
2005-03-16  0:34           ` Oliver Bandel
2005-03-18  6:04 Harrison, John R

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=87br9gx07r.fsf@qrnik.zagroda \
    --to=qrczak@knm.org.pl \
    --cc=caml-list@inria.fr \
    /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).