[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Speed up SAVE-APPLICATION by up to 4 times!



The following patch, will for some people
speed up SAVE-APPLICATION by a factor of more than 4 times.

In my case, SAVE-APPLICATION used to take 1m50s to complete
and now takes only 25s with the patch installed.

This patch is the result of very hard detective work by myself
and a friend. We spent 5 hours roaming the MCL memory in MacsBug
to find the sick spot. (so that's how C programmers feel! :-)

Many thanks to all the people who answered my SAVE-APPLICATION timings
post a few month ago, I hope this patch will be as usefull to them as it
is to me (these answers showed me I was not the only one having this
problem...).

This patch should be very safe. It first check to see if the word it
replaces is the one expected. If it's not it errors.

It is still a partial mystery to why exactly the patch has such a
dramatic effect. My understanding is that MCL's SAVE-APPLICATION dumps
the memory to disk in small chunks. The patch replaces this chunk size
by a much bigger one which results in the memory beeing dumped at the
biggest chunck size your hard disk likes. Tests I did, lead me to conclude
that my hard disk didn't like small chunk sizes and that's where the speedup
comes from. If somebody has a better understanding of the situation, I
would immensely enjoy hearing from him.

Here's the patch:

;; This patch is designed for MCL 2.0 final (p1 or not), I do not
;; know if it will work under other versions of MCL.

;; To apply the patch, evaluate the following expression and then
;; simply quit MCL. The patch changes 2 bytes in a MCL code resource,
;; the resource beeing updated automaticaly when MCL quits.

;; The patch is permanent, you apply it only once. The patch will
;; follow you across a SAVE-APPLICATION, no need to repatch newly
;; created applications.

(let (;; the long at this offset is the size of the chunks
      ;; that will be used to write the application to disk
      (offset #x566)
      (resource (#_GetResource :|CODE| 3)))
  (cond ((/= (%hget-long resource offset) #x00004000)
         ;; check for original size 16k
         (error "Something went wrong, patch not applied."))
        (t ;; a new size of 4meg means the application
           ;; will be written to disk in just one step
           (%hput-long resource #x00400000 offset)
           (#_ChangedResource resource)
           (format t "~&;Patch applied, you can now simply quit."))))

Have fun.

*********************************************************************
* Guillaume Cartier                 (514) 844-5294 (maison)         *
* L.A.C.I.M.                        (514) 987-4290 (bureau)         *
* Universite du Quebec a Montreal   (514) 987-8477 (telecopieur)    *
* Montreal, Quebec, Canada          cartier@math.uqam.ca (internet) *
*********************************************************************