From 1a7e2f0269dc4542a5c62825c33bcc2da4aafb7b Mon Sep 17 00:00:00 2001 From: Artur Gainullin Date: Mon, 13 Jan 2025 04:38:03 -0800 Subject: [PATCH] [SYCL] Don't copy string when tracing is not enabled (#16596) Currently we pass by value and always copy the path even if tracing is not enabled which is expensive. Fix to pass by reference and do the copy/modification only if tracing is enabled. --- .../source/detail/persistent_device_code_cache.hpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/sycl/source/detail/persistent_device_code_cache.hpp b/sycl/source/detail/persistent_device_code_cache.hpp index 48ef6e15b6fce..9346461c9229f 100644 --- a/sycl/source/detail/persistent_device_code_cache.hpp +++ b/sycl/source/detail/persistent_device_code_cache.hpp @@ -208,21 +208,23 @@ class PersistentDeviceCodeCache { const ur_program_handle_t &NativePrg); /* Sends message to std:cerr stream when SYCL_CACHE_TRACE environemnt is set*/ - static void trace(const std::string &msg, std::string path = "") { + static void trace(const std::string &msg, const std::string &path = "") { static const bool traceEnabled = SYCLConfig::isTraceDiskCache(); if (traceEnabled) { - std::replace(path.begin(), path.end(), '\\', '/'); - std::cerr << "[Persistent Cache]: " << msg << path << std::endl; + auto outputPath = path; + std::replace(outputPath.begin(), outputPath.end(), '\\', '/'); + std::cerr << "[Persistent Cache]: " << msg << outputPath << std::endl; } } static void trace_KernelCompiler(const std::string &msg, - std::string path = "") { + const std::string &path = "") { static const bool traceEnabled = SYCLConfig::isTraceKernelCompiler(); if (traceEnabled) { - std::replace(path.begin(), path.end(), '\\', '/'); - std::cerr << "[kernel_compiler Persistent Cache]: " << msg << path + auto outputPath = path; + std::replace(outputPath.begin(), outputPath.end(), '\\', '/'); + std::cerr << "[kernel_compiler Persistent Cache]: " << msg << outputPath << std::endl; } }