diff options
| author | Martin Hořeňovský | 2025-07-17 13:13:08 +0200 |
|---|---|---|
| committer | Martin Hořeňovský | 2025-07-17 13:47:44 +0200 |
| commit | c22096846c98211e0bcd23dbbd155698fbd718b3 (patch) | |
| tree | 0d30b3d6a826cd277f559bcb8a217c3e103de444 /src/catch2/internal | |
| parent | ae33e5b99af6f58840f78e1986051b0c6a5823e4 (diff) | |
| download | catch3-c22096846c98211e0bcd23dbbd155698fbd718b3.tar.gz | |
Let reporters opt into fast path in RunContext::assertionStarting
The fast path allows `RunContext` to skip disabling output redirect,
and notifying the reporters, turning `RunContext::notifyAssertionStarted`
into a no-op. This improves the overall performance of assertion handling
significantly, and also prepares ground for future changes around
assertion handling and thread safety.
For simple 10M assertion run, this improves the running time by ~30%
in Debug build and ~40% in Release build.
For backwards-compatibility reasons, the fast path is disabled
by default. However, none of the first party reporters use the
`assertionStarting` event, so all first party reporters are opted-in.
Diffstat (limited to 'src/catch2/internal')
| -rw-r--r-- | src/catch2/internal/catch_run_context.cpp | 7 | ||||
| -rw-r--r-- | src/catch2/internal/catch_run_context.hpp | 3 |
2 files changed, 8 insertions, 2 deletions
diff --git a/src/catch2/internal/catch_run_context.cpp b/src/catch2/internal/catch_run_context.cpp index b23c2146..df40d445 100644 --- a/src/catch2/internal/catch_run_context.cpp +++ b/src/catch2/internal/catch_run_context.cpp @@ -172,6 +172,7 @@ namespace Catch { m_lastKnownLineInfo("DummyLocation", static_cast<size_t>(-1)), m_outputRedirect( makeOutputRedirect( m_reporter->getPreferences().shouldRedirectStdOut ) ), m_abortAfterXFailedAssertions( m_config->abortAfter() ), + m_reportAssertionStarting( m_reporter->getPreferences().shouldReportAllAssertionStarts ), m_includeSuccessfulResults( m_config->includeSuccessfulResults() || m_reporter->getPreferences().shouldReportAllAssertions ), m_shouldDebugBreak( m_config->shouldDebugBreak() ) { @@ -309,8 +310,10 @@ namespace Catch { } void RunContext::notifyAssertionStarted( AssertionInfo const& info ) { - auto _ = scopedDeactivate( *m_outputRedirect ); - m_reporter->assertionStarting( info ); + if (m_reportAssertionStarting) { + auto _ = scopedDeactivate( *m_outputRedirect ); + m_reporter->assertionStarting( info ); + } } bool RunContext::sectionStarted( StringRef sectionName, diff --git a/src/catch2/internal/catch_run_context.hpp b/src/catch2/internal/catch_run_context.hpp index ed3fda93..da320fe8 100644 --- a/src/catch2/internal/catch_run_context.hpp +++ b/src/catch2/internal/catch_run_context.hpp @@ -159,6 +159,9 @@ namespace Catch { size_t m_abortAfterXFailedAssertions; bool m_lastAssertionPassed = false; bool m_shouldReportUnexpected = true; + // Caches whether `assertionStarting` events should be sent to the reporter. + bool m_reportAssertionStarting; + // Caches whether `assertionEnded` events for successful assertions should be sent to the reporter bool m_includeSuccessfulResults; // Caches m_config->shouldDebugBreak() to avoid vptr calls/allow inlining bool m_shouldDebugBreak; |