aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Engelbrecht <[email protected]>2026-03-22 19:01:36 +0100
committerGitHub Enterprise <[email protected]>2026-03-22 19:01:36 +0100
commit1bf5d5a48c0ac762b483fd0867b838a312da47e1 (patch)
treeb0f527bd532437ce831114fcf665c5f2614f6d7d
parentS3 hydration backend for hub mode (#873) (diff)
downloadzen-1bf5d5a48c0ac762b483fd0867b838a312da47e1.tar.xz
zen-1bf5d5a48c0ac762b483fd0867b838a312da47e1.zip
improve zenserver startup time (#879)
- Improvement: Lazy initialize CpuSampler - reduces startup time by ~600 ms - Bugfix: Don't try to wipe .sentry-native folder at missing manifest - sentry is already running. Reduces startup time by ~450 ms when data folder is empty
-rw-r--r--CHANGELOG.md2
-rw-r--r--src/zencore/system.cpp32
-rw-r--r--src/zenserver/storage/zenstorageserver.cpp2
3 files changed, 24 insertions, 12 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index b768a097c..ba334dfed 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -61,6 +61,7 @@
- Multi-select with bulk hibernate/wake/deprovision and select-all
- Pagination at 50 lines per page
- Inline fold-out panel per row with human-readable process metrics
+- Improvement: Lazy initialize CpuSampler - reduces startup time by ~600 ms when `--no-sentry` is enabled
- Bugfix: Fixed sentry-native build to allow LTO on Windows
- Bugfix: Minor test stability fixes (flaky hash collisions, per-thread RNG seeds)
- Bugfix: Handle long paths in the project store
@@ -68,6 +69,7 @@
- Bugfix: Retry OIDC token refresh once on failure before propagating the error
- Bugfix: Handle HTTP 501 (Not Implemented) from Jupiter as a signal to fall back from multi-range to single-range requests
- Bugfix: Fixed shutdown event not being cleared after the server process exits in `ZenServerInstance::Shutdown()`, which could cause stale state on reuse
+- Bugfix: Don't try to wipe .sentry-native folder at missing manifest - sentry is already running. Reduces startup time by ~450 ms when data folder is empty
## 5.7.23
- Bugfix: Crash at startup if a log message was emitted before logging is properly initialized
diff --git a/src/zencore/system.cpp b/src/zencore/system.cpp
index 8985a8a76..23178814c 100644
--- a/src/zencore/system.cpp
+++ b/src/zencore/system.cpp
@@ -445,23 +445,15 @@ struct CpuSampler
PDH_HQUERY QueryHandle = nullptr;
PDH_HCOUNTER CounterHandle = nullptr;
bool HasPreviousSample = false;
+ bool IsInitialized = false;
bool IsWine = false;
ProcStatCpuSampler ProcStat{"Z:\\proc\\stat"};
CpuSampler()
{
IsWine = zen::windows::IsRunningOnWine();
-
- if (!IsWine)
- {
- if (PdhOpenQueryW(nullptr, 0, &QueryHandle) == ERROR_SUCCESS)
- {
- if (PdhAddEnglishCounterW(QueryHandle, L"\\Processor(_Total)\\% Processor Time", 0, &CounterHandle) != ERROR_SUCCESS)
- {
- CounterHandle = nullptr;
- }
- }
- }
+ // PDH initialization is deferred to the first Sample() call because
+ // PdhAddEnglishCounterW can take hundreds of milliseconds on first invocation.
}
~CpuSampler()
@@ -472,6 +464,22 @@ struct CpuSampler
}
}
+ void InitializePdh()
+ {
+ if (IsInitialized)
+ {
+ return;
+ }
+ IsInitialized = true;
+ if (PdhOpenQueryW(nullptr, 0, &QueryHandle) == ERROR_SUCCESS)
+ {
+ if (PdhAddEnglishCounterW(QueryHandle, L"\\Processor(_Total)\\% Processor Time", 0, &CounterHandle) != ERROR_SUCCESS)
+ {
+ CounterHandle = nullptr;
+ }
+ }
+ }
+
float Sample()
{
if (IsWine)
@@ -479,6 +487,8 @@ struct CpuSampler
return ProcStat.Sample();
}
+ InitializePdh();
+
if (!QueryHandle || !CounterHandle)
{
return 0.0f;
diff --git a/src/zenserver/storage/zenstorageserver.cpp b/src/zenserver/storage/zenstorageserver.cpp
index d51a425a9..531853f5d 100644
--- a/src/zenserver/storage/zenstorageserver.cpp
+++ b/src/zenserver/storage/zenstorageserver.cpp
@@ -510,7 +510,7 @@ ZenStorageServer::InitializeState(const ZenStorageServerConfig& ServerOptions)
std::error_code Ec;
for (const std::filesystem::directory_entry& DirEntry : std::filesystem::directory_iterator{m_DataRoot, Ec})
{
- if (DirEntry.is_directory() && (DirEntry.path().filename() != "logs"))
+ if (DirEntry.is_directory() && DirEntry.path().filename() != "logs" && DirEntry.path().filename() != ".sentry-native")
{
ZEN_INFO("Deleting '{}'", DirEntry.path());