From d10b7c898172b4a5352422ce8ba1f4210be94a9d Mon Sep 17 00:00:00 2001 From: nilsbecker Date: Mon, 24 Nov 2014 23:52:09 +0100 Subject: [PATCH 1/4] eliminate some weak array creations the idea was to save on gc load by letting weak arrays expire by themselves test.ml passes. the non-emptyness of the arrays above Wa.len does not seem to be a problem --- src/react.ml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/react.ml b/src/react.ml index 4ef44bd..0559747 100644 --- a/src/react.ml +++ b/src/react.ml @@ -19,7 +19,7 @@ module Wa = struct For now the arrays only grow. We could try to compact and downsize the array in scan_add if a threshold of empty slots is exceeded. *) - +jddu let create size = { arr = Weak.create size; len = 0 } let length a = a.len let is_empty a = @@ -30,7 +30,7 @@ module Wa = struct true with Exit -> false - let clear a = a.arr <- Weak.create 0; a.len <- 0 + let clear a = a.len <- 0 let get a i = Weak.get a.arr i let set a i = Weak.set a.arr i let swap a i i' = @@ -299,7 +299,7 @@ module Step = struct (* Update steps. *) let rec execute c = let eops c = List.iter (fun op -> op ()) c.eops; c.eops <- [] in let cops c = List.iter (fun op -> op ()) c.cops; c.cops <- [] in - let finish c = c.over <- true; c.heap <- Wa.create 0 in + let finish c = c.over <- true; Wa.clear c.heap in let rec update c = match H.take c.heap with | Some n when n.rank <> delayed_rank -> n.update c; update c | Some n -> From 2f07ab3d4d72f6e022ab5df6831cec9c1e1815e5 Mon Sep 17 00:00:00 2001 From: nilsbecker Date: Tue, 25 Nov 2014 00:03:34 +0100 Subject: [PATCH 2/4] Update react.ml --- src/react.ml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/react.ml b/src/react.ml index 0559747..306c8d6 100644 --- a/src/react.ml +++ b/src/react.ml @@ -19,7 +19,7 @@ module Wa = struct For now the arrays only grow. We could try to compact and downsize the array in scan_add if a threshold of empty slots is exceeded. *) -jddu + let create size = { arr = Weak.create size; len = 0 } let length a = a.len let is_empty a = From 25cada1bba761a47df944f6ade9f4541d297ca4d Mon Sep 17 00:00:00 2001 From: Nils Becker Date: Thu, 22 Jan 2015 11:55:04 +0100 Subject: [PATCH 3/4] store step heaps in a global stack for reuse this saves a lot of allocation/gc of weak arrays and gives speedups up to 40% in overhead dominated simulation tests --- src/react.ml | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/react.ml b/src/react.ml index 306c8d6..bac27dc 100644 --- a/src/react.ml +++ b/src/react.ml @@ -281,12 +281,20 @@ end let delayed_rank = max_int +(*try to preallocate. this should have the same semantics.*) +let global_weak_heap_stack = ref [] + module Step = struct (* Update steps. *) type t = step let nil = { over = true; heap = Wa.create 0; eops = []; cops = []} let create () = - let h = Wa.create 11 in + (*let h = Wa.create 11 in*) + let gh = global_weak_heap_stack in + let h = match !gh with + | top::r -> (gh := r; Wa.clear top; top) + | [] -> Wa.create 11 + in { over = false; heap = h; eops = []; cops = []} let add c n = if n.stamp == c then () else (n.stamp <- c; H.add c.heap n) @@ -299,11 +307,15 @@ module Step = struct (* Update steps. *) let rec execute c = let eops c = List.iter (fun op -> op ()) c.eops; c.eops <- [] in let cops c = List.iter (fun op -> op ()) c.cops; c.cops <- [] in - let finish c = c.over <- true; Wa.clear c.heap in + let finish c = + global_weak_heap_stack := c.heap::!global_weak_heap_stack; + c.over <- true in let rec update c = match H.take c.heap with | Some n when n.rank <> delayed_rank -> n.update c; update c | Some n -> let c' = create () in + (*debug...*) + (*let () = print_endline "created delayed nested step" in*) eops c; List.iter (fun n -> n.update c') (n :: H.els c.heap); cops c; finish c; execute c' From 4a4b0de4a40f90ffb816c76319922fb8b7d4ee98 Mon Sep 17 00:00:00 2001 From: nbecker Date: Sun, 1 Feb 2015 20:02:46 +0100 Subject: [PATCH 4/4] ignore executables and swap files --- .gitignore | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index f854d6d..aa8c603 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,7 @@ tmp \#*# *.native *.byte -*.install \ No newline at end of file +*.install +CLOCK.org +*.o +*.swp