about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMark Rousskov <mark.simulacrum@gmail.com>2023-02-28 21:19:43 -0500
committerMark Rousskov <mark.simulacrum@gmail.com>2023-03-07 08:30:08 -0500
commitdabafb44e0917709910915dc5b3bc351a519a9e1 (patch)
treec25202c42c8a864d99a77aca699cbd23721fbcbf
parentddc2d1e8063a346124633649b0d97dd6f8c33c83 (diff)
downloadrust-dabafb44e0917709910915dc5b3bc351a519a9e1.tar.gz
rust-dabafb44e0917709910915dc5b3bc351a519a9e1.zip
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.
-rw-r--r--src/tools/rust-installer/src/compression.rs21
1 files changed, 16 insertions, 5 deletions
diff --git a/src/tools/rust-installer/src/compression.rs b/src/tools/rust-installer/src/compression.rs
index 9b176982d00..013e05fda58 100644
--- a/src/tools/rust-installer/src/compression.rs
+++ b/src/tools/rust-installer/src/compression.rs
@@ -61,13 +61,24 @@ impl CompressionFormat {
                 lzma_ops.literal_context_bits(3);
 
                 filters.lzma2(&lzma_ops);
+
+                let mut builder = xz2::stream::MtStreamBuilder::new();
+                builder.filters(filters);
+
+                // On 32-bit platforms limit ourselves to 3 threads, otherwise we exceed memory
+                // usage this process can take. In the future we'll likely only do super-fast
+                // compression in CI and move this heavyweight processing to promote-release (which
+                // is always 64-bit and can run on big-memory machines) but for now this lets us
+                // move forward.
+                if std::mem::size_of::<usize>() == 4 {
+                    builder.threads(3);
+                } else {
+                    builder.threads(6);
+                }
+
                 let compressor = XzEncoder::new_stream(
                     std::io::BufWriter::new(file),
-                    xz2::stream::MtStreamBuilder::new()
-                        .threads(1)
-                        .filters(filters)
-                        .encoder()
-                        .unwrap(),
+                    builder.encoder().unwrap(),
                 );
                 Box::new(compressor)
             }