
On Tue, Aug 02, 2022 at 05:32:58PM +0200, J. Reinders wrote:
Could you use `StablePtr` for the keys?
That might be an option, but I have no idea how performant stable pointers are and manual management is obviously not ideal.
If your hash table keys qualify for being stored in a "compact region", you may not need per-key stable pointers, just (carefully) coercing the keys to pointers suffices to produce primitive "handles" that are stable for the lifetime of the "compact region". The inverse (unsafe) coercion recovers the key. This also has the advantage that a key count does not incur a high ongoing GC cost. The keys are of course copied into the compact region. With this you could store "pointer + count" in a primitive cell. The hash table then holds a reference to the compact region and compacts keys on insert. https://hackage.haskell.org/package/compact-0.2.0.0/docs/Data-Compact.html -- Viktor.