-
-
Notifications
You must be signed in to change notification settings - Fork 382
Feature request: compile-time hashes for HeaderName::from_static #653
Copy link
Copy link
Open
Labels
A-headersArea: HTTP headersArea: HTTP headersB-rfcBlocked: request for comments. More discussion would help move this along.Blocked: request for comments. More discussion would help move this along.S-performanceSeverity: performance. Make existing functionality go faster.Severity: performance. Make existing functionality go faster.
Description
Activity
Metadata
Metadata
Assignees
Labels
A-headersArea: HTTP headersArea: HTTP headersB-rfcBlocked: request for comments. More discussion would help move this along.Blocked: request for comments. More discussion would help move this along.S-performanceSeverity: performance. Make existing functionality go faster.Severity: performance. Make existing functionality go faster.
Hi!
An almost complete rust newbie here (coming from C++, mostly), so please forgive my ignorance.
I believe it's a pretty common practice to have some company-wide standard headers for, say, tracing/authorization/etc., which are de-facto
StandardHeaders in that sense.However, since they aren't actually values of that enum, hashing them calls into FNV (i assume hashing a
StandardHeaderonly hashes its discriminant, am i right?), and that FNV usage is measurable.For example, i took the axum implementation from TechEmpower benchmarks, and did this: https://github.com/itrofimow/FrameworkBenchmarks/pull/7/files
Looking at flamegraphs, the
contains_keyamounts to ~3% of total CPU usage, most of it being spent in FNV, when replacing theCUSTOM_HEADERSwith[ACCESS_CONTROL_ALLOW_CREDENTIALS, ACCESS_CONTROL_ALLOW_HEADERS, ACCESS_CONTROL_EXPOSE_HEADERS](something of comparable length, basically) leads to thecontains_keyonly taking ~0.3%.Does it make sense to implement the optimization proposed, or do its drawbacks outweigh its performance benefits?
I have a clear understanding of how that could be done in C++ (we actually do so in the web-framework of ours, with its HeaderMap implementation being heavily inspired by what hyper offers), and would be glad to give it a try in Rust.