Adds RmetaLinkCache a per-link cache that uses path as the key of dec…#158194
Adds RmetaLinkCache a per-link cache that uses path as the key of dec…#158194mehdiakiki wants to merge 1 commit into
Conversation
…oded lib.rmeta-link archive members, and routes add_archive read through it so each rlib link metadata is decoded at most once per link. This is a demand that originated from the discussion in rust-lang#156735 and we split it out as its own PR. It gives that PR a decode once path tp read instead of reparsing each rlib per crate once native_lib_filenames moves to a link time read.
|
r? @wesleywiser rustbot has assigned @wesleywiser. Use Why was this reviewer chosen?The reviewer was selected based on:
|
|
|
|
||
| impl RmetaLinkCache { | ||
| pub fn get_or_insert_with( | ||
| &self, |
There was a problem hiding this comment.
| &self, | |
| &mut self, |
Any specific reason to use &self and RefCell instead of &mut and no RefCell?
| &self, | ||
| rlib_path: &Path, | ||
| load: impl FnOnce() -> Option<RmetaLink>, | ||
| ) -> Option<Rc<RmetaLink>> { |
There was a problem hiding this comment.
| ) -> Option<Rc<RmetaLink>> { | |
| ) -> Option<&RmetaLink> { |
Is Rc necessary?
The current use in add_archive doesn't seem to require it.
| return cached.clone(); | ||
| } | ||
| let loaded = load().map(Rc::new); | ||
| self.cache.borrow_mut().insert(rlib_path.to_path_buf(), loaded.clone()); |
There was a problem hiding this comment.
| self.cache.borrow_mut().insert(rlib_path.to_path_buf(), loaded.clone()); | |
| self.cache.borrow_mut().entry(rlib_path).or_insert_with(...); |
Can simplify this and avoid the double lookup by using the entry API.
| let _timer = sess.timer("link_binary"); | ||
| let output_metadata = sess.opts.output_types.contains_key(&OutputType::Metadata); | ||
| let mut tempfiles_for_stdout_output: Vec<PathBuf> = Vec::new(); | ||
| let rmeta_link_cache = rmeta_link::RmetaLinkCache::default(); |
There was a problem hiding this comment.
| let rmeta_link_cache = rmeta_link::RmetaLinkCache::default(); | |
| let rmeta_link_cache = RmetaLinkCache::default(); |
Nit: imports (in archive.rs too).
|
|
||
| pub enum AddArchiveKind<'a> { | ||
| Rlib(/*skip*/ &'a dyn Fn(&str, ArchiveEntryKind) -> bool), | ||
| Rlib { skip: &'a dyn Fn(&str, ArchiveEntryKind) -> bool, cache: &'a rmeta_link::RmetaLinkCache }, |
There was a problem hiding this comment.
| Rlib { skip: &'a dyn Fn(&str, ArchiveEntryKind) -> bool, cache: &'a rmeta_link::RmetaLinkCache }, | |
| Rlib(&'a RmetaLinkCache, /*skip*/ &'a dyn Fn(&str, ArchiveEntryKind) -> bool), |
Style nit: not enough fields to convert to named fields, and closures usually go last.
|
I thought about using |
|
Reminder, once the PR becomes ready for a review, use |
|
Ok will address the comments above! |
Adds
RmetaLinkCachea per link and path keyed cache of decodedlib.rmeta-linkarchive members and routes the add_archive read through it so that each rlib link metadata is decoded only one per link at most.This is a request that originated from the discussion in #156735 and we split it out as its own PR. It gives that PR a decode once path to read instead of reparsing each
rlibper crate, and this will be in effect oncenative_lib_filenamesmoves to a link-time read.Part of #138243