etr/libhttpserver

move toward a more zero-copy API

stuart-byma opened this issue · 0 comments

Is your feature request related to a problem? Please describe.
Currently when getting any kind of header, footer, cookie, etc. new string objects are constructed every time. This leads to a large number of memory allocations, which are generally expensive. Even if I have a key value as a const char* or a string_view I am forced to construct a std::string to use the interface. Even worse is requesting all keys and values, where a std::map is allocated and constructed and every key and value copied into a std::string.

Describe why the feature or enhancement you are proposing fits the library.
Performance should be a priority for any HTTP server 😄

Describe the solution you'd like
The API calls should favor string_view or similar to pass views on underlying data in MHD (which is mostly immutable) and avoid having to make copies. Any MHD data should be viable for the lifetime of the HTTP request object anyway. If the user really wants a copy to keep the data around longer, they can make a copy explicitly themselves.

Describe alternatives you've considered
I'm not sure there is any better option than using std::string_view or similar here.

Additional context
None.