Closed jalil-salame closed 1 month ago
Apparently bytemuck
's TransparentWrapper
handles this case, so we could switch to that instead and have it execute the unsafe code.
Closing as this should be sent to rust-lang/rust
Sorry, I didn't read the contributing guidelines. The comment addresses experimental changes where we switch from HashMap<&Id, _>
to HashMap<&IdRef, _>
instead of changing to FxHashMap<&Id, _>
. I'm preparing a PR where I do add the IdRef
.
The generics are from an experiment on unsized coercion, I thought I might be able to coerce Box<str>
to str
(because you can't build &IdRef
safely otherwise). This works for [_; N] -> [_]
coercion, but not Box<str> -> str
sadly.
This reduces the size of
Id
from 24 bytes to 16 bytes on 64-bit systems, and from 12 bytes to 8 bytes in 32-bit systems.It also adds an
IdRef
type that we can use instead of a&Id
, this avoids a double indirection (&str
vs&String
). Intrustfall-rustdoc-adapter
we see a 7% perf improvement when using&IdRef
instead of&Id
.Sadly, AFAIK, there is no way to safely coerce
Id(Box<str>)
to&IdRef(str)
so we need to do an unsafestd::mem::transmute(&str) -> &IdRef
.zulip discussion