home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / programm / 3604 < prev    next >
Encoding:
Internet Message Format  |  1993-01-26  |  5.2 KB

  1. Path: sparky!uunet!cs.utexas.edu!qt.cs.utexas.edu!yale.edu!ira.uka.de!sbusol.rz.uni-sb.de!coli.uni-sb.de!coli-gate.coli.uni-sb.de!spackman
  2. From: spackman@disco-sol.dfki.uni-sb.de (Stephen Spackman)
  3. Newsgroups: comp.programming
  4. Subject: Re: C/C++ Speed
  5. Followup-To: comp.programming
  6. Date: 26 Jan 1993 14:03:01 GMT
  7. Organization: DFKI Saarbruecken GmbH, D-W 6600 Saarbruecken
  8. Lines: 75
  9. Distribution: na
  10. Message-ID: <SPACKMAN.93Jan26150814@disco-sol.dfki.uni-sb.de>
  11. References: <1993Jan19.140118.14183@bcrka451.bnr.ca> <1993Jan20.180908.8784@tc.fluke.COM>
  12.     <1993Jan21.133432.26293@bcrka451.bnr.ca> <25415@galaxy.ucr.edu>
  13. Reply-To: stephen@acm.org
  14. NNTP-Posting-Host: disco-sol.dfki.uni-sb.de
  15. In-reply-to: rhyde@ucrengr.ucr.edu's message of 25 Jan 93 17:53:16 GMT
  16.  
  17. In article <25415@galaxy.ucr.edu> rhyde@ucrengr.ucr.edu (randy hyde) writes:
  18. |Trying to get fast software on a UNIX box is a joke.  UNIX is not
  19. |real-time and by the time you have all the background stuff running
  20. |(e.g., X-stuff) it makes for a really slow system.  People who talk
  21. |about how optimizing their code doesn't pay off, when the code they're
  22. |writing is running under UNIX, are fooling themselves.  I know, I've
  23. |done a lot of this (I'm not talking about going from 10 minutes to five,
  24. |I'm talking about going from 1 sec to 0.1 sec which is very important for
  25. |highly interactive programs).  Given the typical 1/60 sec time slice in
  26. |a multitasking OS (not just UNIX), it is very difficult to optimize such
  27. |machines at this level.
  28.  
  29. Well, I do once recall installing a small optimisation that reduced
  30. response time to about a quarter of a second, from on the order of a
  31. hundred billion years [estimated]. I thought that was twenty minutes of
  32. programming time well spent.... Even under Unix this resulted in a
  33. *significant* increase in throughput.
  34.  
  35. Oh, since this is comp.programming, I'll tell you what I was doing. The
  36. problem was to store a matrix of how often each different word is used
  37. in each of a thousand books, how often by each author, how often in each
  38. year, decade and century - in all, a 2000 * 200,000 matrix of maximally
  39. 24-bit numbers. The naive method doesn't work well, because those
  40. thousand books were already being stored on the CD along with their
  41. various indices (itself no mean feat, the uncompressed text alone was
  42. bigger than the whole CD). Not room for another gig of matrix.
  43.  
  44. So first we used a couple of obvious optimisations, based on the idea
  45. that when (e.g.) an author only has two books in the database, we can
  46. store just the author summary and the smaller of the book summaries.
  47.  
  48. Since most of the numbers are small, the obvious encoding for the
  49. numbers themselves is something like a variable-width mantissa preceded
  50. by a huffman-encoded exponent, but in fact you can do a lot better.
  51. Since the categories of info stored are mostly heirarchic (each decade
  52. is in some century, many authors fit inside one decade), you can choose
  53. a spanning tree for the various objects and then (a) guarantee that the
  54. count for a given word in an object is no greater than the count for the
  55. same word in its parent object (thus the number of bits USED in the
  56. parent upper-bounds the number of bits you need STORE for the child - an
  57. optimisation at its most useful in the most common case, when the
  58. frequency stored is zero, and the child needs no entry at all); and (b)
  59. estimate that the frequencies are distributed evenly by corpus size (so
  60. usually you can store the number of word-occurrences for a year in the
  61. number of bits actually used to represent the product of the number of
  62. occurrences for the decade and the proportion of the *total* volume of
  63. the decade, for all words, that falls in the year). It's worth a bit to
  64. choose between these two representations (except when reprentation a
  65. needs one bit or less :-).
  66.  
  67. This method is nice and compact (not that I haven't omitted a lot of
  68. obvious statistically-based refinements) - about 10,000:1 nonlossy
  69. compression over the original matrix (well, not such a huge surprise
  70. since an incredible number of words are only used in one work, ever -
  71. because they're typos or names or really weird) but when you come to
  72. decompress it, it's all yucchy bitstreams :-).
  73.  
  74. And being a good functionalist, even though this was all in C, I made
  75. all my interfaces nice clean stateless ones: to decompress the entry for
  76. a word, you (1) compute the position at which its entry starts (to do
  77. this you just read the preceding entry!), (2) read the entry for the
  78. same word in the parent object, and do the little calculation that tells
  79. you how many bits to read. The only problem is that both steps recur on
  80. the whole operation, and the damned thing is (as coded!) somewhat worse
  81. than O(n^m) (where n is the number of words, 200,000 in this case, and m
  82. is the depth of the tree - call it five).
  83.  
  84. Of course, memoising the functions (with LRU caches to keep the space
  85. requirements down) - makes the whole thing linear again.
  86.  
  87. The nice thing is that it doesn't mess up the code structure at all.
  88. ----------------------------------------------------------------------
  89. stephen p spackman    +49 681 302 5288(o) 5282(sec)    stephen@acm.org
  90.       dfki / stuhlsatzenhausweg 3 / d-w-6600 saarbruecken 11 / germany
  91. ----------------------------------------------------------------------
  92.