Store weak pointers by hash
commite5c35478272115f2cf8ea3aacf9a808239a0ab91
authorJake Bailey (Hacklang) <jakebailey@fb.com>
Wed, 26 Jan 2022 00:14:05 +0000 (25 16:14 -0800)
committerFacebook GitHub Bot <facebook-github-bot@users.noreply.github.com>
Wed, 26 Jan 2022 00:24:35 +0000 (25 16:24 -0800)
treec7d37cf94cf70af5f75396c819a4326dbb74441c
parent745a1884bb4de1bca4300078bf1873a35c454610
Store weak pointers by hash

Summary:
Currently, a Conser stores a map from T -> Weak<T>. This means that there's one copy of T stored in the map as a key, and a second, ref-counted copy stored on the heap (which will be destroyed if its strong refcount drops to 0, and freed on the next Conser::gc invocation). Ideally, we should just store a single copy on the heap! Having an owned version inside the map also makes it impossible for us to reclaim some unused memory: if we hashcons a value containing other hashconsed values, those other values will be strongly referenced by the value we store as the map's key.

If we key the table by value hashes instead, we avoid these problems at the cost of needing to handle collisions. I've punted on collision handling in this diff (u64 is a pretty big space). Additionally, since we no longer need to store an owned copy of the value in the map, we're able to hashcons unsized types like `str`. The next diff removes an indirection in `Symbol` by switching its representation from `Hc<Box<str>>` to `Hc<str>` now that this is possible.

Reviewed By: edwinsmith

Differential Revision: D33698451

fbshipit-source-id: 4e74f97ddd64af32fb5a3ec006c40d94ebfc1f36
hphp/hack/src/rupro/lib/hcons/mod.rs