Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
hconstr v3 use int map ref instead of hashtbl
Not sure if I messed up the hashtbl usage but it seems to produce big buckets, which we then need to linearly scan. Int map has exactly one bucket per hash and ends up faster. ~~~coq Require Import Ltac2.Ltac2. Require Import PrimInt63. Set Debug "hconstr". Inductive tree := Leaf (_:int) | Node (_:tree) (_:tree). Import Constr.Unsafe. Ltac2 rec big' node leaf n := if Int.equal n 0 then leaf() else let n := Int.sub n 1 in let c := big' node leaf n in let c' := big' node leaf n in make (App node [|c; c'|]). Lemma baz : tree. Time let x := Ref.ref '(0 :> int) in let leaf := 'Leaf in let leaf () := let c := Ref.get x in let c' := (eval cbv in (add $c 1)) in Ref.set x c'; make (App leaf [|c|]) in let c := big' 'Node leaf 17 in Std.exact_no_check c. Time Defined. (* 16 -> master: 2s, hconstr v2: 8s 17 -> master: 8s, hconstr v2: 31s, hconstr v3: 8s *) (* v2: Debug: [hconstr] num_bindings = 393217 num_buckets = 262144 max_bucket_length = 16385 Debug: [hconstr] num_bindings = 1 num_buckets = 64 max_bucket_length = 1 *) (* v3: Debug: [hconstr] hashes = 392326 bindings = 393217 most_collisions = 256 Debug: [hconstr] hashes = 1 bindings = 1 most_collisions = 1 *) ~~~ (BTW the hcons debug says ~~~ Debug: [hcons] num_bindings = 393291 num_buckets = 67482 max_bucket_length = 4103 ~~~ which is sgnificantly smaller than the hconstr max bucket length, IDK why)
- Loading branch information