Const-ify hashing of Key
.
#241
Labels
C-core
Component: core functionality such as traits, etc.
E-complex
Effort: complex.
S-waiting-on-upstream
Status: issue/PR requires an upstream change to either a dependency or Rust itself
T-enhancement
Type: enhancement.
A while back, we added support to pre-generate the hash of a
Key
in order to speed up its hashing performance when used withmetrics_util::Registry
. One part that I was never truly satisfied with was that we had to accomplish it by using atomics so that we could store the hash after construction. This was required because:const
fn (had to be hashed on first access)Key
is passed around as&Key
, so it has to be doable with only an immutable reference availableSince then, many features related to
const
fns have become stabilized. While not all of the necessary features are stabilized yet, I was able to craft a solution (a lot of unsafe code, unfortunately) that can do entirelyconst
hashing of a key: https://gist.github.com/tobz/fec84b1ac850aeaef216608a8585c982We should pay attention to the next few Rust releases to see what other
const
features get stabilized. The primary grossness of the approach taken in the gist relates tostd::slice::from_raw_parts
not having a stabilizedconst
impl, so we reimplemented a lot of the union trickery that gets used to safely transmute between*const u8
and*const [u8]
, which provides the basis of jumping to*const str
/&str
. A recent PR was merged for that which should hopefully land in 1.58.0, but there might be other useful stabilizations that let us clean up more of the code.The text was updated successfully, but these errors were encountered: