Open Lol3rrr opened 4 years ago
This has for now been mostly done to the point that reducing the memory allocations is becoming increasingly harder to manage
We can also look into adopting a new faster memory allocator to replace the current malloc stuff, as we don't need such a general version and can make use of the fact, that we know more about the data we have.
There may be some points, where more malloc calls can be avoided in the hot path of the code.
For example when accepting a request it, the queue entry can be allocated before waiting for a connection, this would move the allocation out of the hot path and possibly allow for other optimizations in the future.
Problem
Right now the code makes too much calls to malloc for my taste and it really slows down everything.
Solution
All the stuff for parsing the Request should be done on the one malloced array, that actually holds the request. All the Headers then just simply hold a pointer to some value inside that block and how long it is supposed to be, this could really reduce the amount of malloc calls. This also needs the headers to be aware of the fact that they only sometimes need to free their content and otherwise don't, this could be achieved using a simple boolean being passed to them on creation that indicates this.