I want to optimize (and learn more about) the performance of my almost-finished web server. Should vectors and data structures that change in size be allocated on the heap before storing them in the database and cache or when should I do it?
You should probably benchmark your server and only optimize the parts that actually take up a lot of time. There is no point trying to optimize memory allocations if for example you spend less than 1% of your time in allocating. Instead you did be better off optimizing the actually hot parts of the code. Or if the performance is more than enough to handle the expected load of the program, you may want to skip spending time optimizing entirely. (That is not a free pass to intentionally do things in a slow way, but you don't need to micro optimize at the expense of readability either in that case.)
If you are doing it just to learn optimizations that is fine and in that case, do go ahead with trying to optimize!
Vec
already heap allocates it's content. Heap allocating Vec
itself is unlikely to provide any benefit.
Ok, thanks