From e87e1ea73f6242c7f8a0dfd7aebb96b01f57689d Mon Sep 17 00:00:00 2001 From: Julian Brost Date: Mon, 12 Dec 2022 14:27:16 +0100 Subject: [PATCH] Freeze globals namespace during config load This allows for a faster config load due to less locking required. The change is slightly backwards-incompatible. Before, you could manipulate the globals namespace at a later stage, but disallowing this feels reasonable for the performance benefit alone (which especially shows on many-core machines). Apart from that, it's doubtful if doing so is even useful at all as the DSL provides no mechanism for you to synchronize your operations that may run in parallel. The data structures itself are protected from race conditions, but anything implemented on top of this may still be subject to race conditions. And even if some user has a good reason for doing this, there's a feasible workaround by creating your own namespace like globals.mutable and using that instead. --- lib/cli/daemonutility.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/cli/daemonutility.cpp b/lib/cli/daemonutility.cpp index bb951b17d..9e910f313 100644 --- a/lib/cli/daemonutility.cpp +++ b/lib/cli/daemonutility.cpp @@ -247,6 +247,11 @@ bool DaemonUtility::LoadConfigFiles(const std::vector& configs, return false; } + // After evaluating the top-level statements of the config files (happening in ValidateConfigFiles() above), + // prevent further modification of the global scope. This allows for a faster execution of the following steps + // as Freeze() disables locking as it's not necessary on a read-only data structure anymore. + ScriptGlobal::GetGlobals()->Freeze(); + WorkQueue upq(25000, Configuration::Concurrency); upq.SetName("DaemonUtility::LoadConfigFiles"); bool result = ConfigItem::CommitItems(ascope.GetContext(), upq, newItems);