Skip to content
This repository has been archived by the owner on Aug 23, 2022. It is now read-only.

Use stack allocated fixed-size vectors where possible #13

Open
dtzxporter opened this issue Jun 28, 2022 · 1 comment
Open

Use stack allocated fixed-size vectors where possible #13

dtzxporter opened this issue Jun 28, 2022 · 1 comment

Comments

@dtzxporter
Copy link

dtzxporter commented Jun 28, 2022

Since processing of packets is likely to happen thousands of times per second, there will be a performance gain if the struct doesn't allocate to Vec<> every time you unmarshal a header.

Something like arrayvec would be suitable for this: https://crates.io/crates/arrayvec

@k0nserv
Copy link
Member

k0nserv commented Jun 29, 2022

I do agree about reducing the number of heap allocations, but in a future context I think arrayvec is not advisable because it makes the futures themselves too large. Further, I think it complicates achieving cancel safety since the stack gets dropped when a future is cancelled.

The cancel safety point is equally true for naive heap allocations of course.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants