kinode-dao / kinode

Kinode OS runtime
https://kinode.org
Apache License 2.0
35 stars 13 forks source link

feature: [optimization] improve bit packing of `struct`s #616

Closed nick1udwig closed 1 day ago

nick1udwig commented 1 day ago

Is your feature request related to a problem? Please describe. While working on Printout I noticed that we don't optimally pack bits. Ideally we should pack bits so that fields that take up more space are fields earlier in the struct, e.g.

struct Foo {
    a: u8,
    b: u64,
}

packs less efficiently than

struct Foo {
    b: u64,
    a: u8,
}

which leads to memory bloat and performance degradation (since caches will be more frequently invalidated).

Describe the solution you'd like Pack bits efficiently!

Additional context I had thought this might be a breaking change, but I've convinced myself it is not for everything that gets serialized to JSON. The reason is that JSON objects have unordered fields, so as long as things go through the serialization step it doesn't matter how they're packed when they are deserialized into a given runtime's structs.

This might not be the case for other serialization formats, e.g., MessagePack may be fine but bincode will probably not (we need to doublecheck).

nick1udwig commented 1 day ago

Misled by LLMs!

https://doc.rust-lang.org/nomicon/repr-rust.html