sks-devel
[Top][All Lists]
Advanced

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

Re: [Sks-devel] Dump recurses to dumpsize on stack?


From: Kim Minh Kaplan
Subject: Re: [Sks-devel] Dump recurses to dumpsize on stack?
Date: Sun, 22 Mar 2009 06:00:23 +0000
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (gnu/linux)

Phil Pennock:

> Is it known that when you do "sks dump <N> <dir>", you end up with up to
> 10 stack frames per N, plus the calls into the DB layer, etc?
[...]
> I was suspecting db problems, and it's not.  Looks as though something
> was expecting tail recursion optimisation but not getting it.  I really
> don't know enough about programming in functional languages to look into
> this properly.  I don't even know if things like shuffling exception
> handling around would let the tail recursion optimisation kick in and
> where things like integrity of backup dumps are concerned, I play around
> less.

I highly suspect that the inside of a try block is not a tail position
and that "shuffling exception handling around" is the right thing to do
here.  Try this.

Kim Minh.
diff -r 181a19755969 sksdump.ml
--- a/sksdump.ml        Sat Mar 21 18:31:36 2009 +0000
+++ b/sksdump.ml        Sun Mar 22 05:58:10 2009 +0000
@@ -46,19 +46,22 @@
       match SStream.next stream with
        | None -> ()
        | Some (hash,string) ->
+           let remain =
            try
              let skey = Keydb.skey_of_string string in
              if should_dump skey then
                let keystring = Keydb.keystring_of_skey skey in
                output_string cout keystring;
-               write_to_file (size - 1) stream cout
+               size - 1
              else
-               write_to_file size stream cout
+               size
            with
                e -> 
                  eplerror 1 e "Failed attempt to extract key %s" 
                  (KeyHash.hexify hash);
-                 write_to_file size stream cout
+                 size
+           in
+           write_to_file remain stream cout
 
 
   let write_to_fname size stream fname = 

reply via email to

[Prev in Thread] Current Thread [Next in Thread]