im-rs icon indicating copy to clipboard operation
im-rs copied to clipboard

Empty collections allocate a surprising amount

Open andrewhickman opened this issue 6 years ago • 1 comments

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 (and HashMap) will allocate a small amount for the hasher (which is typically a 0-size or Copy type) and 536 bytes of space
  • OrdSet allocates 1080 bytes
  • Vector allocates 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.

andrewhickman avatar Feb 05 '19 22:02 andrewhickman

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.

bodil avatar Feb 08 '19 16:02 bodil