Skip to content

Commit dabafb4

Browse files
Use 3 or 6 compression threads for rust-installer
Limit to 3 threads for 32-bit platforms, otherwise we use 6 threads. This avoids exceeding the amount of memory we can allocate on a 32-bit platform.
1 parent ddc2d1e commit dabafb4

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

Diff for: src/tools/rust-installer/src/compression.rs

+16-5
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,24 @@ impl CompressionFormat {
6161
lzma_ops.literal_context_bits(3);
6262

6363
filters.lzma2(&lzma_ops);
64+
65+
let mut builder = xz2::stream::MtStreamBuilder::new();
66+
builder.filters(filters);
67+
68+
// On 32-bit platforms limit ourselves to 3 threads, otherwise we exceed memory
69+
// usage this process can take. In the future we'll likely only do super-fast
70+
// compression in CI and move this heavyweight processing to promote-release (which
71+
// is always 64-bit and can run on big-memory machines) but for now this lets us
72+
// move forward.
73+
if std::mem::size_of::<usize>() == 4 {
74+
builder.threads(3);
75+
} else {
76+
builder.threads(6);
77+
}
78+
6479
let compressor = XzEncoder::new_stream(
6580
std::io::BufWriter::new(file),
66-
xz2::stream::MtStreamBuilder::new()
67-
.threads(1)
68-
.filters(filters)
69-
.encoder()
70-
.unwrap(),
81+
builder.encoder().unwrap(),
7182
);
7283
Box::new(compressor)
7384
}

0 commit comments

Comments
 (0)