rust-lightning icon indicating copy to clipboard operation
rust-lightning copied to clipboard

Use buffers in filesystem read APIs

Open TheBlueMatt opened this issue 2 years ago • 0 comments

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:

  • MonitorName has an obvious maximum size, so should be a fixed length buffer with a length field.
  • Similarly, we realloc a ton when building paths with the PathBuf abstraction. 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 use with_capacity on 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).

TheBlueMatt avatar Nov 04 '23 18:11 TheBlueMatt