Conversation
There are a number of things I dislike about `CrateMetadataRef`. - It contains two fields `cstore` and `cdata`. The latter points to data within the former. It's like having an `Elem` type that has a reference to a vec element and also a reference to the vec itself. Weird. - The `cdata` field gets a lot of use, and the `Deref` impl just derefs that field. The `cstore` field is rarely used. - `CrateMetadataRef` is not a good name. - Variables named `cdata` sometimes refer to values of this type and sometimes to values of type `CrateMetadata`, which is confusing. The good news is that `CrateMetadataRef` is not necessary and can be replaced with `&CrateMetadata`. Why? Everywhere that `CrateMetadataRef` is used, a `TyCtxt` is also present, and the `CStore` is accessible from the `TyCtxt` with `CStore::from_tcx`. So this commit removes `CrateMetadataRef` and replaces all its uses with `&CrateMetadata`. Notes: - This requires adding only two uses of `CStore::from_tcx`, which shows how rarely the `cstore` field was used. - `get_crate_data` now matches `get_crate_data_mut` more closely. - A few variables are renamed for consistency, e.g. `data`/`cmeta` -> `cdata`. - An unnecessary local variable (`local_cdata`) in `decode_expn_id` is removed. - All the `CrateMetadataRef` methods become `CrateMetadata` methods, and their receiver changes from `self` to `&self`. - `RawDefId::decode_from_cdata` is inlined and removed, because it has a single call site.
|
Locally this was a perf win, mostly on doc builds. Let's try on CI: @bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Eliminate `CrateMetadataRef`.
This comment has been minimized.
This comment has been minimized.
|
Finished benchmarking commit (073731e): comparison URL. Overall result: ✅ improvements - no action neededBenchmarking means the PR may be perf-sensitive. It's automatically marked not fit for rolling up. Overriding is possible but disadvised: it risks changing compiler perf. @bors rollup=never Instruction countOur most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.
Max RSS (memory usage)Results (primary 1.8%)A less reliable metric. May be of interest, but not used to determine the overall result above.
CyclesResults (secondary -2.4%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Binary sizeResults (secondary 0.0%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Bootstrap: 492.161s -> 492.336s (0.04%) |
|
Perf results are good, and match what I saw locally. |
|
This looks really nice, but I think petrochenkov has some thoughts :) |
This wasn't the case until recently, only |
|
@bors r=mejrs,petrochenkov |
There are a number of things I dislike about
CrateMetadataRef.cstoreandcdata. The latter points to data within the former. It's like having anElemtype that has a reference to a vec element and also a reference to the vec itself. Weird.cdatafield gets a lot of use, and theDerefimpl just derefs that field. Thecstorefield is rarely used.CrateMetadataRefis not a good name.cdatasometimes refer to values of this type and sometimes to values of typeCrateMetadata, which is confusing.The good news is that
CrateMetadataRefis not necessary and can be replaced with&CrateMetadata. Why? Everywhere thatCrateMetadataRefis used, aTyCtxtis also present, and theCStoreis accessible from theTyCtxtwithCStore::from_tcx.So this commit removes
CrateMetadataRefand replaces all its uses with&CrateMetadata. Notes:CStore::from_tcx, which shows how rarely thecstorefield was used.get_crate_datanow matchesget_crate_data_mutmore closely.data/cmeta->cdata.local_cdata) indecode_expn_idis removed.CrateMetadataRefmethods becomeCrateMetadatamethods, and their receiver changes fromselfto&self.RawDefId::decode_from_cdatais inlined and removed, because it has a single call site.r? @mejrs