Skip to content

Commit

Permalink
Free intermediate translation results as soon as possible
Browse files Browse the repository at this point in the history
This fixes the recently introduced peak memory usage regression by
freeing the intermediate results as soon as they're not required
anymore instead of keeping them around for the whole compilation
process.

Refs #8077
  • Loading branch information
dotdash committed Jul 28, 2013
1 parent 293ec2c commit 075560a
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/librustc/driver/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -409,12 +409,19 @@ pub fn stop_after_phase_5(sess: Session) -> bool {
pub fn compile_input(sess: Session, cfg: ast::CrateConfig, input: &input,
outdir: &Option<Path>, output: &Option<Path>) {
let outputs = build_output_filenames(input, outdir, output, [], sess);
let crate = phase_1_parse_input(sess, cfg.clone(), input);
if stop_after_phase_1(sess) { return; }
let expanded_crate = phase_2_configure_and_expand(sess, cfg, crate);
let analysis = phase_3_run_analysis_passes(sess, expanded_crate);
if stop_after_phase_3(sess) { return; }
let trans = phase_4_translate_to_llvm(sess, expanded_crate, &analysis, outputs);
// We need nested scopes here, because the intermediate results can keep
// large chunks of memory alive and we want to free them as soon as
// possible to keep the peak memory usage low
let trans = {
let expanded_crate = {
let crate = phase_1_parse_input(sess, cfg.clone(), input);
if stop_after_phase_1(sess) { return; }
phase_2_configure_and_expand(sess, cfg, crate)
};
let analysis = phase_3_run_analysis_passes(sess, expanded_crate);
if stop_after_phase_3(sess) { return; }
phase_4_translate_to_llvm(sess, expanded_crate, &analysis, outputs)
};
phase_5_run_llvm_passes(sess, &trans, outputs);
if stop_after_phase_5(sess) { return; }
phase_6_link_output(sess, &trans, outputs);
Expand Down

9 comments on commit 075560a

@bors
Copy link
Contributor

@bors bors commented on 075560a Jul 28, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from alexcrichton
at dotdash@075560a

@bors
Copy link
Contributor

@bors bors commented on 075560a Jul 28, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging dotdash/rust/peak_mem = 075560a into auto

@bors
Copy link
Contributor

@bors bors commented on 075560a Jul 28, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dotdash/rust/peak_mem = 075560a merged ok, testing candidate = 85b5513

@bors
Copy link
Contributor

@bors bors commented on 075560a Jul 28, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = 85b5513

@kud1ing
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cmr: Do we have one of your memory plots for this?

@huonw
Copy link
Member

@huonw huonw commented on 075560a Jul 29, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kud1ing, a plot will appear here at some point in the near future.

@huonw
Copy link
Member

@huonw huonw commented on 075560a Jul 29, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(It's there now, and is actually 150 MB lower than it was before the regression.)

@alexcrichton
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's awesome! Both the patch and the tools :)

Please sign in to comment.