Skip to content

Commit 886ec39

Browse files
committed
Lmdb Disk Cache: partially reuse GCed IDs to save cycles on cleaning LMDB
1 parent adcf717 commit 886ec39

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/lib/disk_cache/lmdb/disk_cache.ml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,13 @@ module Make (Data : Binable.S) = struct
3939
Rw.get ~env db idx |> Option.value_exn
4040

4141
let put ({ env; db; counter; reusable_keys } : t) (x : Data.t) : id =
42-
(* TODO: we may reuse IDs by pulling them from the `garbage` hash set *)
43-
let idx = !counter in
44-
incr counter ;
42+
let idx =
43+
match Queue.dequeue reusable_keys with
44+
| None ->
45+
incr counter ; !counter - 1
46+
| Some reused_key ->
47+
reused_key
48+
in
4549
let res = { idx } in
4650
(* When this reference is GC'd, delete the file. *)
4751
Gc.Expert.add_finalizer_last_exn res (fun () ->

0 commit comments

Comments
 (0)