rust-lightning
rust-lightning copied to clipboard
Use buffers in filesystem read APIs
After handling #2706 locally, 44% of my allocations locally are from path building when using the MonitorUpdatingPersister! That's obviously nuts, and luckily we can cut this down with careful buffer management:
MonitorNamehas an obvious maximum size, so should be a fixed length buffer with a length field.- Similarly, we
realloca ton when building paths with thePathBufabstraction. Because they're super short, we should be storing them on the stack in constant-size buffers, though sadly its a bit more involved because on Unix its all bytes and on Windows its all u16s. IMO we should just usewith_capacityon Windows, but on Unix we should use fixed-length buffers and make it a path with https://doc.rust-lang.org/std/os/unix/ffi/trait.OsStrExt.html#tymethod.from_bytes (internet claims max path len is only 4096 bytes, so this should be easy).