home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / lang / function / 962 < prev    next >
Encoding:
Text File  |  1992-07-27  |  3.5 KB  |  73 lines

  1. Newsgroups: comp.lang.functional
  2. Path: sparky!uunet!mcsun!sunic!kth.se!dentex.tds.kth.se!kff
  3. From: kff@dentex.tds.kth.se (Karl-Filip Faxen)
  4. Subject: Re: Predicting efficiency from theoretical models (Re: ** LAZY LANGUAGES FASTER?? **)
  5. Message-ID: <1992Jul27.165728.16279@kth.se>
  6. Sender: usenet@kth.se (Usenet)
  7. Nntp-Posting-Host: dentex.tds.kth.se
  8. Reply-To: kff@dentex.tds.kth.se (Karl-Filip Faxen)
  9. Organization: Royal Institute of Technology, Stockholm, Sweden
  10. References: <1992Jul24.134857.23289@gdstech.grumman.com> <1992Jul25.190252.9173@cs.cornell.edu>
  11. Date: Mon, 27 Jul 1992 16:57:28 GMT
  12. Lines: 59
  13.  
  14. In article <1992Jul25.190252.9173@cs.cornell.edu>, murthy@cs.cornell.edu (Chet Murthy) writes:
  15.  
  16. |> Anybody thought about the question of _why_ CBV is more efficient?
  17.  
  18. [Stuff deleted...]
  19.  
  20. |> In the end, it came down for me to something disgustingly applied -
  21. |> the frequency of expressions which are weak-head-normalizable to
  22. |> closure-free objects (i.e. which compute to data-values) is very high
  23. |> in normal programs - so CBV wins because it "represents" them
  24. |> efficiently - as the values they denote.
  25.  
  26. Well, I would like to put it in a slightly different way:
  27.  
  28. (1) In CBN, the value of a variable may or may not already
  29.     be evaluated. A strict primitive, like integer add, needs its
  30.     argument in evaluated form. Hence in an expression like `x+y',
  31.     both arguments needs to be tested, and perhaps evaluated, before
  32.     the addition is performed. This incurrs two costs relative to CBV:
  33.  
  34.     (a) The run time test is not needed in CBV, since variables are
  35.         only allowed to denote fully evaluated objects.
  36.  
  37.     (b) A variable must be able to represent not only all objects of
  38.         its type, but also all possible ways of evaluating such objects
  39.         (all possible closures). Thus if a variable is implemented as a
  40.         machine word, either there will be fewer objects of its type
  41.         than bit patterns in a machine word (which is a pain in the
  42.         behind when it comes to ints or floats), or some (or all) values
  43.         in the type have to be stored in the heap and represented as 
  44.         pointers (all values must be boxed) which wastes storage and
  45.         instructions (to move data between the heap and the CPU).
  46.  
  47. (2) Optimizations such as register allocation and static instruction
  48.     scheduling depends on the compiler being able figure out what the 
  49.     program will do when run. Every conditional branch is one more place 
  50.     where the compiler has to assume the worst. Thus these carry indirect
  51.     costs as well as the direct cost of executing them.
  52.  
  53. (3) It may be expensive to allocate, initialize and in general manipulate
  54.     the closures. Especially since these are generally in the heap, they
  55.     may well destroy locality, resulting in a thrashing data cache.
  56.  
  57. Unfortunately, effects such as (1b), (2) and the locality loss in (3) are
  58. not accounted for by standard complexity theory. They just slips between
  59. your fingers if you're only counting the number of operations a program
  60. will execute since on a modern computer, the cost of an operation in 
  61. general depends on its context, what operations preceede and follow it in
  62. the dynamic instruction stream, when, where and by whom its operands were
  63. computed and when, where and by whom its result will be used.
  64.  
  65. |> I mean, for a theoretician, there seems to be no really good answer.
  66.  
  67. I think that is a sure sign that there is a lot of new and interesting
  68. theory to be done in this field!
  69.  
  70. Karl-Filip
  71. ----------------------------------------------------------------
  72. Make the frequent case fast, and the fast case frequent!
  73.