Hacker News new | ask | show | jobs
by userbinator 2739 days ago
If you're looking for low-hanging-fruit to optimise, there's a ton of "foo = create_string(<some constant>)" and then "delete_string(foo)" not long afterwards in the code.

I also think I've found a bug: the code seems to assume that the colon in a header will be followed by one space (see parse_request_line in http.c) but according to https://tools.ietf.org/html/rfc7230#section-3.2 and my experience, that space is optional and there may be multiple of them.

(This is part of the reason I'm not a fan of text-based protocols: parsing is full of annoying edge-cases.)

1 comments

I feel like it should be possible to avoid dynamic memory allocation completely during the request processing/parsing. Sure, fixed-sized buffers generally imply some memory overhead, but I'd think the overall effect on performance would be beneficial.
This is what I'm trying to do with wwwee [1], a low-resource web server written in Rust. The request / response buffer is a growing anonymous mmap mapping, but all parsing (http headers, ...) and decoding (base64, JSON) is done borrowing from the buffer. It works especially well in Rust, with it's borrow checker preventing use-after-free.

1: https://github.com/bwindels/wwwee/