From 4be9df6fdcbadd78fe9cecaaef12af7b527f2add Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Ber=C3=A1nek?= Date: Mon, 30 Jun 2025 14:32:12 +0200 Subject: [PATCH] Add `include-blob` secondary benchmark --- collector/compile-benchmarks/README.md | 2 ++ collector/compile-benchmarks/REUSE.toml | 5 +++++ .../compile-benchmarks/include-blob/0-println.patch | 11 +++++++++++ .../compile-benchmarks/include-blob/Cargo.lock | 7 +++++++ .../compile-benchmarks/include-blob/Cargo.toml | 8 ++++++++ collector/compile-benchmarks/include-blob/build.rs | 13 +++++++++++++ .../include-blob/perf-config.json | 4 ++++ .../compile-benchmarks/include-blob/src/main.rs | 7 +++++++ 8 files changed, 57 insertions(+) create mode 100644 collector/compile-benchmarks/include-blob/0-println.patch create mode 100644 collector/compile-benchmarks/include-blob/Cargo.lock create mode 100644 collector/compile-benchmarks/include-blob/Cargo.toml create mode 100644 collector/compile-benchmarks/include-blob/build.rs create mode 100644 collector/compile-benchmarks/include-blob/perf-config.json create mode 100644 collector/compile-benchmarks/include-blob/src/main.rs diff --git a/collector/compile-benchmarks/README.md b/collector/compile-benchmarks/README.md index bfd2b7c86..3e96620d6 100644 --- a/collector/compile-benchmarks/README.md +++ b/collector/compile-benchmarks/README.md @@ -79,6 +79,8 @@ compiler in interesting ways. - **externs**: A large number of extern functions has caused [slowdowns in the past](https://github.com/rust-lang/rust/pull/78448). - **helloworld-tiny**: A trivial program optimized with flags that should reduce binary size. Gives a lower bound on compiled binary size. +- **include-blob**: Stress test for including binary and string blobs with `include_str!` and + `include_bytes!`. Its build script generates 30 MiB blobs that are then included into the program. - **issue-46449**: A small program that caused [poor performance](https://github.com/rust-lang/rust/issues/46449) in the past. - **issue-58319**: A small program that caused [poor diff --git a/collector/compile-benchmarks/REUSE.toml b/collector/compile-benchmarks/REUSE.toml index e16ba1dc9..ecffbcd3c 100644 --- a/collector/compile-benchmarks/REUSE.toml +++ b/collector/compile-benchmarks/REUSE.toml @@ -130,6 +130,11 @@ path = "image-0.25.6/**" SPDX-FileCopyrightText = "The image-rs Developers" SPDX-License-Identifier = "MIT" +[[annotations]] +path = "include-blob/**" +SPDX-FileCopyrightText = "The Rust Project Developers (see https://thanks.rust-lang.org)" +SPDX-License-Identifier = "MIT OR Apache-2.0" + [[annotations]] path = "inflate/**" SPDX-FileCopyrightText = "inflate contributors" diff --git a/collector/compile-benchmarks/include-blob/0-println.patch b/collector/compile-benchmarks/include-blob/0-println.patch new file mode 100644 index 000000000..068b25579 --- /dev/null +++ b/collector/compile-benchmarks/include-blob/0-println.patch @@ -0,0 +1,11 @@ +diff --git a/src/main.rs b/src/main.rs +index 9cb1671e..fc854410 100644 +--- a/src/main.rs ++++ b/src/main.rs +@@ -6,5 +6,5 @@ fn main() { + "Binary blob last element: {}", + BLOB_BINARY[BLOB_BINARY.len() - 1] + ); +- println!("String blob: {BLOB_STRING}"); ++ println!("String blob contents: {BLOB_STRING}"); + } diff --git a/collector/compile-benchmarks/include-blob/Cargo.lock b/collector/compile-benchmarks/include-blob/Cargo.lock new file mode 100644 index 000000000..74acfc8ce --- /dev/null +++ b/collector/compile-benchmarks/include-blob/Cargo.lock @@ -0,0 +1,7 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "include-blob" +version = "0.1.0" diff --git a/collector/compile-benchmarks/include-blob/Cargo.toml b/collector/compile-benchmarks/include-blob/Cargo.toml new file mode 100644 index 000000000..e311a009e --- /dev/null +++ b/collector/compile-benchmarks/include-blob/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "include-blob" +version = "0.1.0" +edition = "2024" + +[dependencies] + +[workspace] diff --git a/collector/compile-benchmarks/include-blob/build.rs b/collector/compile-benchmarks/include-blob/build.rs new file mode 100644 index 000000000..bb567d2b6 --- /dev/null +++ b/collector/compile-benchmarks/include-blob/build.rs @@ -0,0 +1,13 @@ +use std::path::PathBuf; + +fn main() { + let byte_count = 30usize * 1024 * 1024; + let out_dir = PathBuf::from(std::env::var("OUT_DIR").expect("OUT_DIR is missing")); + + // Generate large (30 MiB) blobs of data to include into the resulting program + let binary_data: Vec = (0..byte_count).map(|v| (v % 256) as u8).collect(); + std::fs::write(out_dir.join("blob-binary"), binary_data).expect("cannot write binary blob"); + + let string_data: String = ('a'..'z').cycle().take(byte_count).collect(); + std::fs::write(out_dir.join("blob-string"), string_data).expect("cannot write string blob"); +} diff --git a/collector/compile-benchmarks/include-blob/perf-config.json b/collector/compile-benchmarks/include-blob/perf-config.json new file mode 100644 index 000000000..097c809ff --- /dev/null +++ b/collector/compile-benchmarks/include-blob/perf-config.json @@ -0,0 +1,4 @@ +{ + "category": "secondary", + "artifact": "binary" +} diff --git a/collector/compile-benchmarks/include-blob/src/main.rs b/collector/compile-benchmarks/include-blob/src/main.rs new file mode 100644 index 000000000..3f07848e2 --- /dev/null +++ b/collector/compile-benchmarks/include-blob/src/main.rs @@ -0,0 +1,7 @@ +const BLOB_BINARY: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/blob-binary")); +const BLOB_STRING: &str = include_str!(concat!(env!("OUT_DIR"), "/blob-string")); + +fn main() { + println!("Binary blob: {BLOB_BINARY:?}"); + println!("String blob: {BLOB_STRING:?}"); +}