Closed
Description
Cargo sometimes makes a lot of copies of data structures. For example the string "serde", was copied for the name of each dependency on that crate, as the name of each version of that package, and for each feature that enables that package. This got fixed by adding a InternedString
data type that deduplicates the data and leaks it into a &'static
reference. We have other data structures which use Arc/Rc
to make cloning cheaper.
We should experiment with Interning them to see if it is a Speed or Memory or Ergonomic win.
Off the top of my head:
-
PackageId
is already usingArc
, is copied and hashed and compared all over the place in hot code. -
SourceId
is already usingArc
, has a manual cache forcrates.io
and will probably be leaked anyway by cachingPackageId
. -
semver::Version/semver::VersionReq
are used a lot, probably often with the same value, and are bigger structures then they seem.