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

Better Buffer packing

Open bendk opened this issue 1 year ago • 0 comments

We should adjust how we pack values into RustBuffers.

  • Align items, rather than always packing them together. I think the C struct packing algorithm should work well. In addition to potentially speeding up some operations, it also makes it easier to read a native values directly out of the buffer since you can assume the value is always aligned.
  • Pack pointers using their native representation, rather than packing them as big-endian u64s. In addition to being more efficient, it's simpler for binding generation since you can ignore the endian-ness.
  • Allocate all the space needed up-front rather than growing the buffer. This is how things currently work on Kotlin and I think it's a nice improvement. Again, this is both more efficient and also simpler, since you eliminate the chance of the write operation failing in the middle of writing out the data. If we did this, maybe we could remove the capacity field.

bendk avatar Jun 18 '24 15:06 bendk