From b8a68ff86d14aa70cc51960bf1b8676233110f5e Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Fri, 2 Sep 2022 13:11:48 -0500 Subject: [PATCH] Tweak adapter cost of lists (#4853) I noticed an oss-fuzz-based timeout that was reported for the `component_api` fuzzer where the adapter module generated takes 1.5 seconds to compile the singular function in release mode (no fuzzing enabled). The test case in question was a deeply recursive list-of-list-of-etc and only one function was generated instead of multiple. I updated the cost of strings/lists to cost more in the approximate cost calculation which now forces the one giant function to get split up and the large function is now split up into multiple smaller function that take milliseconds to compile. --- crates/environ/src/fact/trampoline.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/environ/src/fact/trampoline.rs b/crates/environ/src/fact/trampoline.rs index 70255f9908..84e690320b 100644 --- a/crates/environ/src/fact/trampoline.rs +++ b/crates/environ/src/fact/trampoline.rs @@ -514,12 +514,12 @@ impl Compiler<'_, '_> { InterfaceType::Char => 1, // This has a fair bit of code behind it depending on the - // strings/encodings in play, so arbitrarily assign it a cost a 5. - InterfaceType::String => 5, + // strings/encodings in play, so arbitrarily assign it this cost. + InterfaceType::String => 40, // Iteration of a loop is along the lines of the cost of a string // so give it the same cost - InterfaceType::List(_) => 5, + InterfaceType::List(_) => 40, InterfaceType::Flags(i) => { let count = self.module.types[*i].names.len();