From 112b8f3fa6158ce7e681fd80435e2a4a02378163 Mon Sep 17 00:00:00 2001 From: Alex Pyattaev Date: Wed, 5 Mar 2025 19:07:18 +0200 Subject: [PATCH 1/6] enable optimizer in tests and procmacros --- Cargo.toml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index 6b87b3872e1da1..300828ba0b64b9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,6 +8,14 @@ lto = false # Preserve the 'thin local LTO' for this build. split-debuginfo = "unpacked" lto = "thin" +# Enable basic optimizations for unittests +[profile.test] +opt-level = 1 + +# Enable optimizations for procmacros for faster recompile +[profile.dev.build-override] +opt-level = 1 + [workspace] members = [ "account-decoder", From 95310717d701ce34d35934cb890a91dfba0aa5f1 Mon Sep 17 00:00:00 2001 From: Alex Pyattaev Date: Wed, 5 Mar 2025 20:54:45 +0000 Subject: [PATCH 2/6] remove UB-checking assert from accountsdb test --- accounts-db/Cargo.toml | 4 ++++ accounts-db/src/append_vec.rs | 1 - 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/accounts-db/Cargo.toml b/accounts-db/Cargo.toml index c722ecf9d2358a..04da324a03d704 100644 --- a/accounts-db/Cargo.toml +++ b/accounts-db/Cargo.toml @@ -148,3 +148,7 @@ harness = false [lints] workspace = true + +# Enable basic optimizations for unittests +[profile.test] +opt-level = 0 diff --git a/accounts-db/src/append_vec.rs b/accounts-db/src/append_vec.rs index b9aaa0b9420825..97615dada80463 100644 --- a/accounts-db/src/append_vec.rs +++ b/accounts-db/src/append_vec.rs @@ -1830,7 +1830,6 @@ pub mod tests { { let executable_bool: bool = account.executable(); assert!(!executable_bool); - assert_eq!(account.get_executable_byte(), 0); // Wow, not crafted_executable! } }) .unwrap(); From 3a892cc2309b4ae5dafc6d71b9637536178ee7cd Mon Sep 17 00:00:00 2001 From: Alex Pyattaev Date: Fri, 7 Mar 2025 14:57:04 +0000 Subject: [PATCH 3/6] hotfix for gossip test flaking --- gossip/src/cluster_info.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/gossip/src/cluster_info.rs b/gossip/src/cluster_info.rs index de52bb097625ab..f9c49aa8203daf 100644 --- a/gossip/src/cluster_info.rs +++ b/gossip/src/cluster_info.rs @@ -3752,6 +3752,7 @@ mod tests { let mut node = cluster_info.my_contact_info.write().unwrap(); node.set_shred_version(42); } + std::thread::sleep(Duration::from_millis(1)); cluster_info.refresh_my_gossip_contact_info(); cluster_info.flush_push_queue(); // Should now include both epoch slots. From 40a2be1ab9b31f57d8567a67b1931a5ebe983e83 Mon Sep 17 00:00:00 2001 From: Alex Pyattaev Date: Fri, 7 Mar 2025 20:32:50 +0000 Subject: [PATCH 4/6] eliminate dead code --- accounts-db/src/append_vec.rs | 7 ------- 1 file changed, 7 deletions(-) diff --git a/accounts-db/src/append_vec.rs b/accounts-db/src/append_vec.rs index 97615dada80463..a919745d1148f2 100644 --- a/accounts-db/src/append_vec.rs +++ b/accounts-db/src/append_vec.rs @@ -1277,13 +1277,6 @@ pub mod tests { } } - fn get_executable_byte(&self) -> u8 { - let executable_bool: bool = self.executable(); - // UNSAFE: Force to interpret mmap-backed bool as u8 to really read the actual memory content - let executable_byte: u8 = unsafe { std::mem::transmute::(executable_bool) }; - executable_byte - } - fn set_executable_as_byte(&self, new_executable_byte: u8) { // UNSAFE: Force to interpret mmap-backed &bool as &u8 to write some crafted value; unsafe { From e0ba9678c70927be59da521f9c7a666a17f639c5 Mon Sep 17 00:00:00 2001 From: Alex Pyattaev Date: Fri, 7 Mar 2025 22:25:41 +0000 Subject: [PATCH 5/6] stragglers --- accounts-db/Cargo.toml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/accounts-db/Cargo.toml b/accounts-db/Cargo.toml index 04da324a03d704..c722ecf9d2358a 100644 --- a/accounts-db/Cargo.toml +++ b/accounts-db/Cargo.toml @@ -148,7 +148,3 @@ harness = false [lints] workspace = true - -# Enable basic optimizations for unittests -[profile.test] -opt-level = 0 From 3627c2579030a371acce1a7123739dbce0ec60a6 Mon Sep 17 00:00:00 2001 From: Alex Pyattaev Date: Sat, 8 Mar 2025 20:01:18 +0000 Subject: [PATCH 6/6] also optimize deps to O2 level --- Cargo.toml | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 300828ba0b64b9..83c7de598e05ed 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,14 +8,18 @@ lto = false # Preserve the 'thin local LTO' for this build. split-debuginfo = "unpacked" lto = "thin" -# Enable basic optimizations for unittests -[profile.test] +# Enable basic optimizations for dev builds and unittests to trigger const propagation and inlining +[profile.dev] opt-level = 1 -# Enable optimizations for procmacros for faster recompile +# Enable optimizations for procmacros for faster codegen [profile.dev.build-override] opt-level = 1 +# Enable heavier optimizations in deps (we do not rebuild them every time in dev cycle) +[profile.dev.package."*"] +opt-level = 2 + [workspace] members = [ "account-decoder",