Skip to content

Skip RunMemoryManager() when the benchmark run was skipped - #2378

Open
mhansen wants to merge 3 commits into
google:mainfrom
mhansen:skip_memory3
Open

mhansen wants to merge 3 commits into
google:mainfrom
mhansen:skip_memory3

Conversation

@mhansen

@mhansen mhansen commented Nov 12, 2026

Copy link
Copy Markdown
Contributor

No description provided.

Documents the current behavior in `BenchmarkRunner::DoOneRepetition()`: when a
benchmark calls `SkipWithError()` before the loop, `RunMemoryManager()` still
runs (`memory_manager_ran == true`) even though `CreateRunReport()` discards all
memory results (`memory_iterations == 0`).

A follow-up commit fixes `DoOneRepetition()` to skip `RunMemoryManager()` and
flips this assertion.

AI-assisted: this change was written with the help of an AI coding tool.
Previously `BenchmarkRunner::DoOneRepetition()` called `RunMemoryManager()`
even when the timed run was skipped (`i.results.skipped_ != internal::NotSkipped`),
re-running `Setup()`, the benchmark body, `MemoryManager::Start()`/`Stop()`, and
`Teardown()` even though `CreateRunReport()` discards all memory results when
`report.skipped != 0`.

Guard `RunMemoryManager()` on `i.results.skipped_ == internal::NotSkipped`, and
update the regression test in `memory_manager_ordering_gtest.cc` to expect that
`MemoryManager` does not run.

AI-assisted: this change was written with the help of an AI coding tool.
@mhansen

mhansen commented Nov 12, 2026

Copy link
Copy Markdown
Contributor Author

Let's merge #2377 first then I'll rebase on top. Sad that I can't use stacked github PRs from my repo into the google repo (stacked PRs have to be within the same repo)

@LebedevRI

Copy link
Copy Markdown
Collaborator

What is the need to do this? What is the practical benefit?

@mhansen

mhansen commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor Author

Fair question. TBH, there is not a "need" to do this - it's just an optimization.

It should make benchmark running faster if we have some skipped benchmarks.

This avoids completely discarded work:

  • Benchmark Setup
  • Install MemoryManager allocator hooks in MemoryManager::Start/Stop
  • Rerun benchmark body up to the skip
  • Benchmark TearDown

That said, if you think it's not worth the branch, that's fine, happy to revert.

I see now that RunProfilerManager right below has the same unguarded behaviour. We could skip that too.

dmah42
dmah42 previously approved these changes Nov 12, 2026
@dmah42

dmah42 commented Nov 12, 2026

Copy link
Copy Markdown
Member

i think this is useful for consistency across the performance and memory runs.

Comment thread src/benchmark_runner.cc
memory_result = RunMemoryManager(memory_iterations);
}

if (profiler_manager != nullptr) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So what about this one then?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes i just saw that in the note above. we should do the same.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mhansen do you want to add the profiler manager skip into this too?

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants