-
-
Notifications
You must be signed in to change notification settings - Fork 16.4k
Stop keeping metadata in memory before writing it to disk #96358
Copy link
Copy link
Closed
Labels
A-metadataArea: Crate metadataArea: Crate metadataE-help-wantedCall for participation: Help is requested to fix this issue.Call for participation: Help is requested to fix this issue.E-mediumCall for participation: Medium difficulty. Experience needed to fix: Intermediate.Call for participation: Medium difficulty. Experience needed to fix: Intermediate.E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.
Description
Activity
Metadata
Metadata
Assignees
Labels
A-metadataArea: Crate metadataArea: Crate metadataE-help-wantedCall for participation: Help is requested to fix this issue.Call for participation: Help is requested to fix this issue.E-mediumCall for participation: Medium difficulty. Experience needed to fix: Intermediate.Call for participation: Medium difficulty. Experience needed to fix: Intermediate.E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.
rustc_metadataencodes all the crate information into an in-memory buffer inEncodedMetadata. This in-memory buffer is then passed around to be written to disk, as anrmetafile inrustc_interface::encode_and_write_metadataand/or in anrlib/dylibby codegen. Codegen wraps metadata into an object file using theobjectcrate to be nice to linkers that will manipulate therlib/dylib.Keeping
metadatain-memory increases the amount of memory used by rustc significantly. We want to investigate saving this memory by writing metadata to disk early, reading it back if required.Instructions:
rustc_codegen_ssa::back::link::emit_metadataandrustc_codegen_ssa::METADATA_FILENAMEto new modulerustc_metadata::fs.rustc_interface::passes::encode_and_write_metadataandrustc_metadata::util::non_durable_renametorustc_metadata::fs.encode_and_write_metadataeven if!need_metadata_file.rustc_serialize::opaque::FileEncoderinrustc_metadata::rmeta::encoderinstead of anopaque::Encoder, it should encode directly to the temporary file, and re-read this temporary file to build theEncodedMetadata.EncodedMetadatato hold aMmapof the on-disk metadata instead of aVec. ThisMmapcan be of the temporary file, or of the proper renamed output file. In the former case,EncodedMetadatashould carry theMaybeTempDirto avoid deleting the temporary directory while accessing theMmap.Extra: the current implementations of
create_rmeta_fileandcreate_compressed_metadata_fileinrustc_codegen_ssa::back::metadatabuffer everything to a vector before writing it all at once. This could be refactored to write directly to the file using aBufWriter.Please reach out on Zulip if you have any questions. Preferably on a public stream so experts on codegen can weigh in when necessary.