twitch-irc-rs icon indicating copy to clipboard operation
twitch-irc-rs copied to clipboard

Reduce Allocations

Open Nerixyz opened this issue 3 years ago • 3 comments

Especially when parsing IRC messages, a lot of Strings are created that are really just substrings of the original message, so a &str would be more efficient. This would make the message struct tied to a lifetime (of the backing String) making it hard to move the struct around. However, there are crates out there that would make this simpler, like yoke.

I think it's worth at least discussing this.

Also see this article on yoke: Not a Yoking Matter (Zero-Copy #1).

Nerixyz avatar Sep 01 '22 19:09 Nerixyz

I think you're right, that would make a lot of sense. I hadn't heard of yoke, actually. When I last looked into it, self-referential structs were a royal pain in the ass.

RAnders00 avatar Sep 20 '22 13:09 RAnders00

It may be possible to partially get around this by using inline strings. Something like [SmartString] or [compact_str] may work. It wont be a lot (24 bytes at most) but it's better than nothing. [SmartString]: https://lib.rs/crates/smartstring [compact_str]: https://lib.rs/crates/compact_str

MisterEggnog avatar Mar 10 '23 22:03 MisterEggnog

Mentioning fast-str here as well.

RAnders00 avatar Mar 18 '24 10:03 RAnders00