[Pkg-libvirt-commits] [libguestfs] 55/72: generator: small optimization of pod2text cache memoization

Hilko Bengen bengen at moszumanska.debian.org
Sun Apr 5 15:19:52 UTC 2015


This is an automated email from the git hooks/post-receive script.

bengen pushed a commit to branch master
in repository libguestfs.

commit 49ba96001b0c4daac78e125e40b81ee5107dbe9f
Author: Pino Toscano <ptoscano at redhat.com>
Date:   Thu Mar 12 17:31:57 2015 +0100

    generator: small optimization of pod2text cache memoization
    
    Instead of save every time there's a new element in the cache, batch the
    saving to disk every 100 changes, saving the unsaved remainder at the
    exit.
    
    While not a big optimization, this reduces a bit the disk usage during
    generator run.
    
    (cherry picked from commit 04f1f1b741ace41f8c36ae3059690084c7a2dc9c)
---
 generator/utils.ml | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/generator/utils.ml b/generator/utils.ml
index ecb35fd..9d34918 100644
--- a/generator/utils.ml
+++ b/generator/utils.ml
@@ -291,10 +291,22 @@ let pod2text_memo : (memo_key, memo_value) Hashtbl.t =
     v
   with
     _ -> Hashtbl.create 13
-let pod2text_memo_updated () =
+let pod2text_memo_unsaved_count = ref 0
+let pod2text_memo_atexit = ref false
+let pod2text_memo_save () =
   let chan = open_out pod2text_memo_filename in
   output_value chan pod2text_memo;
   close_out chan
+let pod2text_memo_updated () =
+  if not (!pod2text_memo_atexit) then (
+    at_exit pod2text_memo_save;
+    pod2text_memo_atexit := true;
+  );
+  pod2text_memo_unsaved_count := !pod2text_memo_unsaved_count + 1;
+  if !pod2text_memo_unsaved_count >= 100 then (
+    pod2text_memo_save ();
+    pod2text_memo_unsaved_count := 0;
+  )
 
 (* Useful if you need the longdesc POD text as plain text.  Returns a
  * list of lines.

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-libvirt/libguestfs.git



More information about the Pkg-libvirt-commits mailing list