home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / lang / lisp / 3224 < prev    next >
Encoding:
Text File  |  1993-01-11  |  3.8 KB  |  83 lines

  1. Path: sparky!uunet!spool.mu.edu!agate!ames!biosci!parc!news!cutting
  2. From: cutting@skye.parc.xerox.com (Doug Cutting)
  3. Newsgroups: comp.lang.lisp
  4. Subject: Re: CL I/O performance (Was: Playing sparcaudio directly from lisp)
  5. Message-ID: <CUTTING.93Jan11105659@skye.parc.xerox.com>
  6. Date: 11 Jan 93 18:56:59 GMT
  7. References: <9301081511.AA19973@maya.cs.nyu.edu>
  8. Sender: news@parc.xerox.com
  9. Organization: Xerox PARC, Palo Alto, CA
  10. Lines: 70
  11. In-Reply-To: marcoxa@maya.CS.nyu.EDU's message of 8 Jan 93 05:11:02 GMT
  12.  
  13. In article <9301081511.AA19973@maya.cs.nyu.edu> marcoxa@maya.CS.nyu.EDU (Marco Antoniotti) writes:
  14. > In article <C0IEG8.G5n.1@cs.cmu.edu> mkant+@cs.cmu.edu (Mark Kantrowitz) writes:
  15. >    I wrote the following code for Allegro CL. As you can see by
  16. >    experimentation with the code and variations on it, playing the sound
  17. >    files from Lisp is much too slow. Lisp file IO just isn't fast enough.
  18. >    If you're going to play sound files, you'll have to do much of the
  19. >    work in C, and then use a foreign function interface to run the code. 
  20. > This is an interesting remark. I ran through the code and I sincerely
  21. > do not understand why a Lisp application should be "slower" doing
  22. > IO than a C/C++ application.
  23. > As far as my experience is concerned the only "slow" call is the 'elt'
  24. > in read-ascii-string. The functions do not seem to cons a lot.
  25.  
  26. There are several things in Common Lisp which make it difficult to
  27. implement I/O as quickly as does C.  These include:
  28.  
  29. 1. CL I/O functions can't specialize on the stream argument.
  30.  
  31. CL allows for many different types of streams (string, file,
  32. concatenated, etc).  This suggests a CLOS implementation of the stream
  33. functions, with a one method dispatch overhead for each call.
  34. Unfortunately, the stream argument to most calls is optional, and
  35. hence cannot be specialized.  Hence a CLOS implementation of CL I/O
  36. must have a DEFUN'ed veneer to do the argument defaulting.  A cleanup
  37. proposal (STREAM-DEFINITION-BY-USER) was made to standardize the
  38. generic function level interface, but it has not been adopted.
  39.  
  40. 2. CL stream types can't be adequately declared.
  41.  
  42. The compiler might be able optimize calls to (READ-BYTE S) if it knew
  43. that S was the result of (OPEN P :element-type '(UNSIGNED-BYTE 8)),
  44. but one cannot declare the ELEMENT-TYPEs of FILE-STREAMs.
  45.  
  46. 3. 32-bit quantities, natural for file I/O, are usually bignums in CL.
  47.  
  48. When performing binary I/O, care must be taken to structure things so
  49. that 32-bit quantities are not encountered (16- and 24-bit quantities
  50. are fixnums in most implementations).  Some CL implementations may
  51. provide unboxed 32-bit quantities which substantially ameliorates this
  52. problem.  A rather ugly workaround we've used, when reading 32-bit
  53. quantities which are usually fixnums, is the following:
  54.  
  55. (defun write-byte32 (byte32 stream)
  56.   (declare (type (unsigned-byte 32) byte32))
  57.   (if (typep byte32 'fixnum)
  58.       (progn
  59.         (byte16-write (ash (the fixnum byte32) -16) stream)
  60.         (byte16-write (logand (the fixnum byte32) #xffff) stream))
  61.     (progn (byte16-write (ash byte32 -16) stream)
  62.            (byte16-write (logand byte32 #xffff) stream))))
  63.  
  64. (defun read-byte32 (stream)
  65.   (let ((hi16 (byte16-read stream))
  66.         (lo16 (byte16-read stream)))
  67.     (declare (type (unsigned-byte 16) hi16 lo16))
  68.     (if (< hi16 (ash most-positive-fixnum -16))
  69.         (the (or (unsigned-byte 16) fixnum)
  70.           (logior (the (or (unsigned-byte 16) fixnum) (ash hi16 16)) lo16))
  71.       (the (unsigned-byte 32) 
  72.         (+ (the (unsigned-byte 32) (ash hi16 16)) lo16)))))
  73.  
  74. > Here is my question. Are there any benchmarks around for I/O done in
  75. > CL vs. the usual foes (i.e. C/C++)? I believe this would be another
  76. > valuable piece of information regarding CL implementations.
  77.  
  78. Not that I know of, though I agree that this is a gap which needs filling.
  79.  
  80.     Doug
  81.