im-rs
im-rs copied to clipboard
Empty collections allocate a surprising amount
In the standard library, the only collection that allocates when you call new() is VecDeque, which will allocate space for 7 elements.
By comparison, the collections in this library allocate a lot more. Using an element type of u64 for testing:
HashSet(andHashMap) will allocate a small amount for the hasher (which is typically a 0-size or Copy type) and 536 bytes of spaceOrdSetallocates 1080 bytesVectorallocates 544 bytes
I'm not sure if this is easily fixable without a performance penalty but it would be nice to not allocate at all.
It would be nice, but I share your concern about a performance penalty - I'd rather waste memory than cycles, tbh. It might be a negligible hit, though - I'll try it and see.