holepunchto / dht-rpc

Make RPC calls over a Kademlia based DHT.
MIT License
196 stars 37 forks source link

Use dedicated slab for decodeReply buffers #81

Closed HDegroote closed 1 month ago

HDegroote commented 5 months ago

The result of dht replies are often kept around for a long time (for example to populate hypercore's peerInfo objects).

The buffers coming into decodeReply are slab-allocated from udx buffers (~68kb), so large slabs of memory were kept from being garbage collected.

This PR copies the data into a dedicated slab

Note: the buffers of closestNodes are not copied out, because those are assumed to be ephemeral

Note: I didn't know how to test the to.id field (unsure when it's set)

HDegroote commented 1 month ago

This PR is no longer relevant (we put the responsibility of unslabbing at the caller of the queries)