`Json_encoding.assoc` stack-overflows with a huge alist.
Json_encoding.assoc uses OCaml Stdlib's non tail recursive List.map, therefore fails due to stack overflow for huge alists. For example:
let () =
let open Data_encoding in
let l = Stdlib.List.init 5000000 (fun x -> (string_of_int x, Int64.of_int x)) in
let enc = assoc int64 in
let j = Json.construct enc l in (* stack overflow *)
let l' = Json.destruct enc j in
assert ( l = l' )
Background
The next Tezos protocol upgrade "H" flattens its context and some directories now have millions of files. An RPC call to get JSON encoding of a huge context directory kills the node:
- Issue of tezos: tezos/tezos#1100 (closed)
- MR (currently WIP): tezos/tezos!3324 (merged)
Edited by Jun Furuse