hyperium / http

Rust HTTP types
Apache License 2.0
1.16k stars 291 forks source link

HeaderMap: Store pos and hash as u16 #386

Closed mbrubeck closed 4 years ago

mbrubeck commented 4 years ago

HeaderMap currently truncates all hashes to 16 bits, and limits its capacity to 32768 elements. The comments say this is done in order to store positions and hashes as u16, to improve cache locality. However, they are currently stored as usize. This branch changes the code to match the comments.

This does not appear to cause any measurable improvement or regression in speed in the HeaderMap benchmarks on my workstation. However, it should at least reduce the memory footprint of every Headermap.

seanmonstar commented 4 years ago

Oh sweet!

(I've filed https://github.com/hyperium/http/pull/387 for the deprecation errors.)

mbrubeck commented 4 years ago

Note that the Link and Links types still store indices as usize. Changing these to u16 would probably be beneficial for some use cases, though they are not as important as Size and HashValue which together make up the entire HeaderMap::indices vector.

I didn't change Link and Links because it would touch a lot more code and add a lot more u16/usize conversions. This could be error-prone if not done carefully. However, it might be a good follow-up task.