Move the large member of cmp tables to heap to reduce stack frame size. This is particularly useful in `CentipedeFuzzerAdaptor::RunInFuzzingMode` where the runner callback object is allocated on stack - removing cmp_tables saves at least ~64 (8*4+32) KiB stack size per object. PiperOrigin-RevId: 706888297
diff --git a/fuzztest/internal/centipede_adaptor.cc b/fuzztest/internal/centipede_adaptor.cc index c8a0e46..26a3cb1 100644 --- a/fuzztest/internal/centipede_adaptor.cc +++ b/fuzztest/internal/centipede_adaptor.cc
@@ -161,8 +161,8 @@ : runtime_(*runtime), fuzzer_impl_(*fuzzer_impl), configuration_(*configuration), - prng_(GetRandomSeed()) { - } + cmp_tables_(std::make_unique<TablesOfRecentCompares>()), + prng_(GetRandomSeed()) {} bool Execute(centipede::ByteSpan input) override { auto parsed_input = @@ -248,7 +248,8 @@ parsed_origin = fuzzer_impl_.params_domain_.Init(prng_); } auto mutant = FuzzTestFuzzerImpl::Input{*std::move(parsed_origin)}; - fuzzer_impl_.MutateValue(mutant, prng_, {.cmp_tables = &cmp_tables_}); + fuzzer_impl_.MutateValue(mutant, prng_, + {.cmp_tables = cmp_tables_.get()}); mutant_data = fuzzer_impl_.params_domain_.SerializeCorpus(mutant.args).ToString(); } @@ -269,7 +270,7 @@ T b_int; memcpy(&a_int, a, sizeof(T)); memcpy(&b_int, b, sizeof(T)); - cmp_tables_.GetMutable<sizeof(T)>().Insert(a_int, b_int); + cmp_tables_->GetMutable<sizeof(T)>().Insert(a_int, b_int); } void SetMetadata(const centipede::ExecutionMetadata* metadata) { @@ -288,7 +289,7 @@ } else if (size == 8) { InsertCmpEntryIntoIntegerDictionary<uint64_t>(a.data(), b.data()); } - cmp_tables_.GetMutable<0>().Insert(a.data(), b.data(), size); + cmp_tables_->GetMutable<0>().Insert(a.data(), b.data(), size); }); } @@ -299,7 +300,7 @@ Runtime& runtime_; FuzzTestFuzzerImpl& fuzzer_impl_; const Configuration& configuration_; - TablesOfRecentCompares cmp_tables_; + std::unique_ptr<TablesOfRecentCompares> cmp_tables_; absl::BitGen prng_; };