Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Wow! Do you have numbers anywhere showing the space saved? Especially for step 6, using a Vec as a Box, I would not expect that to save much.


> Especially for step 6, using a Vec as a Box, I would not expect that to save much.

It's not that using a Vec as a Box saves anything at all. It's that generics require monomorphisation, and that eats up a bunch of space, and more instances of generic types translates into more space.

If your application uses Vec<i16> elsewhere, you've already paid the binary size price for using it. Vec<i16> is close enough to Box<[i16]> that the functional differences don't warrant the extra code generation.


Unfortunately nothing concrete, it's a few kb here & there. I'd estimate I've saved ~300kb overall. I'd have to go back to compare these things. Removing floats saved more space than I expected

Also important is configuring compiler correctly,

  [profile.release]
  opt-level = "z"
  lto = "fat"
  codegen-units = 1


he meant Box<[T]> (aka fixed-size vec or heap allocated array) rather than Box<T> (a single heap allocated element)




Consider applying for YC's Fall 2026 batch! Applications are open till July 27.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: