From 66e864a53ffdc31b446a963a382a50a1896b0425 Mon Sep 17 00:00:00 2001 From: alainfrisch Date: Fri, 4 Dec 2015 08:57:16 +0100 Subject: [PATCH] Use raise_notrace instead of raise to implement Hashtbl.replace. This significantly improves the benchmark below: let ht = Hashtbl.create 100 in for x = 1 to 2500000 do Hashtbl.replace ht x (); Hashtbl.remove ht x done (about 20% faster, still not as good as #328, which is about 35% faster than trunk on this one) In addition to the speedup, using raise_notrace should avoid destroying the current stack trace when Hashtbl.replace is used in an exception handler. --- stdlib/hashtbl.ml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stdlib/hashtbl.ml b/stdlib/hashtbl.ml index 708e49463..28fd46335 100644 --- a/stdlib/hashtbl.ml +++ b/stdlib/hashtbl.ml @@ -158,7 +158,7 @@ let find_all h key = let replace h key info = let rec replace_bucket = function | Empty -> - raise Not_found + raise_notrace Not_found | Cons(k, i, next) -> if compare k key = 0 then Cons(key, info, next) @@ -350,7 +350,7 @@ module MakeSeeded(H: SeededHashedType): (SeededS with type key = H.t) = let replace h key info = let rec replace_bucket = function | Empty -> - raise Not_found + raise_notrace Not_found | Cons(k, i, next) -> if H.equal k key then Cons(key, info, next)