[darcs-users] darcs patch: Improve memory usage of darcs check and ... (and 1 more)

Petr Rockai me at mornfall.net
Tue Mar 10 18:44:11 UTC 2009


> Improve memory usage of darcs check and repair.
> -----------------------------------------------
>> Bertram Felgenhauer <int-e at gmx.de>**20090310120357
>>  'applyAndFix' in D.Repository.Repair kept all processed patches around,
>>  but only their info is actually needed.
>> ] hunk ./src/Darcs/Repository/Repair.hs 83
>>            aaf s NilFL = return ([], s, True)
>>            aaf s (p:>:ps) = do
>>              (s', mp') <- run_slurpy s $ applyAndTryToFix p
>> -            finishedOneIO k $ show $ human_friendly $ info p
>> +            let !infp = info p -- assure that 'p' can be garbage collected.
>> +            finishedOneIO k $ show $ human_friendly $ infp
Interesting. This indeed seems to make sense, however I have profiled the
current code before and haven't seen any leaks (ie. the profile looked pretty
flat). However, it might be that the reference to 'info p' post-recursion crept
in only later than I have done my profiling, which would explain it. Either
that or something else.

Also, a summary of how it affects actual memory usage would be great. I could
look into that, although my time is currently rather limited. Either way, I'll
do a benchmark run in a near future, comparing 2.2 against current trunk, so at
that point, how much this patch helps (it should help a lot if the problem it
fixes is really happening, which is hard to discern for me right now).

>>              s'' <- syncSlurpy (update_slurpy r c opts) s'
>>              (ps', s''', restok) <- aaf s'' ps
>>              case mp' of
>> hunk ./src/Darcs/Repository/Repair.hs 91
>>                Nothing -> return (ps', s''', restok)
>>                Just (e,pp) -> do putStrLn e
>>                                  p' <- makePatchLazy r pp
>> -                                return ((info p, p'):ps', s''', False)
>> +                                return ((infp, p'):ps', s''', False)
I suppose this is the crucial bit, since if 'info p' wouldn't have been used
after the recursive call, p would be dead and therefore collectible.

As far as correctness of the post-patch code is concerned, I believe the patch
doesn't change semantics at all, so it should be perfectly safe.


Peter Rockai | me()mornfall!net | prockai()redhat!com
 http://blog.mornfall.net | http://web.mornfall.net

"In My Egotistical Opinion, most people's C programs should be
 indented six feet downward and covered with dirt."
     -- Blair P. Houghton on the subject of C program indentation

More information about the darcs-users mailing list