tqwewe / kameo

Fault-tolerant Async Actors Built on Tokio
https://docs.page/tqwewe/kameo
Apache License 2.0
634 stars 16 forks source link

feat: use interned peer ids for improved performance #43

Closed tqwewe closed 2 months ago

tqwewe commented 2 months ago

This PR improves performance of actor spawning by ~16% by reducing the memory size of ActorID with the use of interning the inner PeerId. This reduces the size of ActorID from 96 to 16, which gives a nice performance increase when creating and copying ActorIDs.

Important note: Creating ActorIDs with different PeerIds is technically a memory leak, since the cache of PeerIds is never cleaned up. However the size of a PeerId is 80 bytes, and so for 1MB of memory to be used, you'd need to have 12,500 unique PeerIds used, which could technically happen if they're created randomly and frequently, however nodes shouldn't be changed that often for this to be an issue.

Fixes https://github.com/tqwewe/kameo/issues/42