hyperium / hyperium/http

Feature request: compile-time hashes for `HeaderName::from_static`

オープン
#653 コメント 9 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

A-headers B-rfc S-performance
主要言語
Rust
スター
1.4k
フォーク
378
平均マージ
1日 21時間
マージ済み PR(30日)
5

説明

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 StandardHeader only 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_key amounts to ~3% of total CPU usage, most of it being spent in FNV, when replacing the CUSTOM_HEADERS with [ACCESS_CONTROL_ALLOW_CREDENTIALS, ACCESS_CONTROL_ALLOW_HEADERS, ACCESS_CONTROL_EXPOSE_HEADERS] (something of comparable length, basically) leads to the contains_key only 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.

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

HeaderName::from_static と、issue で説明されている contains_key パスから始め、StandardHeader とカスタムヘッダーのハッシュ動作を比較します。リンクされている TechEmpower ベンチマークと flamegraphs を使用して現在のコストを測定します。完了の条件は、ベンチマークの証拠と合意されたトレードオフを伴う、レビュー済みのコンパイル時ハッシュ手法です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
rust
領域
backend-api-design, performance
issue の種類
機能追加
難易度
5/5
見積もり時間
1週間以上
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
35/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。