-
Notifications
You must be signed in to change notification settings - Fork 123
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Message type optimizations #249
Comments
Agreed, most messages have less than 4 arguments in general, though 8 is not some hard limit, other protocol extensions can definitely have messages with more arguments, nothing forbids that. And using
Well, yes and no. Server-side this is mostly true, but client side it isn't. Messages are first stored in temporary buffers for each event queue, and there is no guarantee that the messages will be consumed from these event queues. In a more general view, I'm not very clear about what would be gained from such optimizations. In contrast, the C library also does a lot of copying around and allocations, and it does not appear to be such a bottleneck that anyone has complained about it. So I'm not willing to significantly increase the complexity of the implementation for small hypothetical performance gains. |
Hm, then one way to solve this will be to introduce in addition to the current owning |
Reducing the allocations using Regarding copies though, in practice messages with Though I'll seriously consider the issue if somebody ever reports how this is a bottleneck for their specific app, but other than that I prefer to keep the implementation as simple as possible (which is already not very simple 😕 ). |
Any message with 4 argument or less will have these arguments stored inline rather than in an heap-allocated vec. The number 4 was chose because almost all messages have 4 arguments or less, and some potentially very spammy messages (wl_touch.move) have exactly 4 arguments. Avoiding allocations in these cases should generally be a gain. Moreother, to avoid bloating the size of Message due to this, String and Array arguments are further boxed, reducing the size of Argument from 4*usize to 2*usize. These kind of arguments are generally pretty rare, so the double allocation should overall not counter the size gain. Closes #268, #249
Any message with 4 argument or less will have these arguments stored inline rather than in an heap-allocated vec. The number 4 was chose because almost all messages have 4 arguments or less, and some potentially very spammy messages (wl_touch.move) have exactly 4 arguments. Avoiding allocations in these cases should generally be a gain. Moreother, to avoid bloating the size of Message due to this, String and Array arguments are further boxed, reducing the size of Argument from 4*usize to 2*usize. These kind of arguments are generally pretty rare, so the double allocation should overall not counter the size gain. Closes #268, #249
Any message with 4 argument or less will have these arguments stored inline rather than in an heap-allocated vec. The number 4 was chose because almost all messages have 4 arguments or less, and some potentially very spammy messages (wl_touch.move) have exactly 4 arguments. Avoiding allocations in these cases should generally be a gain. Moreother, to avoid bloating the size of Message due to this, String and Array arguments are further boxed, reducing the size of Argument from 4*usize to 2*usize. These kind of arguments are generally pretty rare, so the double allocation should overall not counter the size gain. Closes #268, #249
Any message with 4 argument or less will have these arguments stored inline rather than in an heap-allocated vec. The number 4 was chose because almost all messages have 4 arguments or less, and some potentially very spammy messages (wl_touch.move) have exactly 4 arguments. Avoiding allocations in these cases should generally be a gain. Moreother, to avoid bloating the size of Message due to this, String and Array arguments are further boxed, reducing the size of Argument from 4*usize to 2*usize. These kind of arguments are generally pretty rare, so the double allocation should overall not counter the size gain. Closes #268, #249
I think
wayland_commons::wire::Message
is a bit sub-optimal right now.Currently
Vec
is allocated for every message, while judging bywayland.xml
max number of arguments is 8. To remove unnecessary allocations we can useSmallVec
forargs
, though we will have to decide the array size forSmallVec
, e.g. 3, 4, 6, or 8.Argument
always heap allocates forArray
andString
types, not only it causes needless allocations and data copies, but also makesArgument
bigger (right now it uses 32 bytes). Instead of copying data we could point to the origin buffer instead, i.e. we will add a lifetimeArgument<'a>
bound to the origin buffer (and consequently toMessage
as well). The simplest option will be to use&'a [u8]
and&'a CStr
, but it will bringArgument
size to only 24 bytes. Instead with a bit of unsafe code we can store*const u8
and phantom data (to track lifetime) inside two opaque types which will dereference to&'a [u8]
and&'a CStr
respectively. It will bringArgument
size to 16 bytes on 64-bit machines. I think adding lifetime toMessage
shouldn't be a big problem, as IIUC they are almost immediately consumed inside event loop.The text was updated successfully, but these errors were encountered: