Skip to content

Commit 1a7e2f0

Browse files
authored
[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.
1 parent eba4c68 commit 1a7e2f0

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

sycl/source/detail/persistent_device_code_cache.hpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -208,21 +208,23 @@ class PersistentDeviceCodeCache {
208208
const ur_program_handle_t &NativePrg);
209209

210210
/* Sends message to std:cerr stream when SYCL_CACHE_TRACE environemnt is set*/
211-
static void trace(const std::string &msg, std::string path = "") {
211+
static void trace(const std::string &msg, const std::string &path = "") {
212212
static const bool traceEnabled =
213213
SYCLConfig<SYCL_CACHE_TRACE>::isTraceDiskCache();
214214
if (traceEnabled) {
215-
std::replace(path.begin(), path.end(), '\\', '/');
216-
std::cerr << "[Persistent Cache]: " << msg << path << std::endl;
215+
auto outputPath = path;
216+
std::replace(outputPath.begin(), outputPath.end(), '\\', '/');
217+
std::cerr << "[Persistent Cache]: " << msg << outputPath << std::endl;
217218
}
218219
}
219220
static void trace_KernelCompiler(const std::string &msg,
220-
std::string path = "") {
221+
const std::string &path = "") {
221222
static const bool traceEnabled =
222223
SYCLConfig<SYCL_CACHE_TRACE>::isTraceKernelCompiler();
223224
if (traceEnabled) {
224-
std::replace(path.begin(), path.end(), '\\', '/');
225-
std::cerr << "[kernel_compiler Persistent Cache]: " << msg << path
225+
auto outputPath = path;
226+
std::replace(outputPath.begin(), outputPath.end(), '\\', '/');
227+
std::cerr << "[kernel_compiler Persistent Cache]: " << msg << outputPath
226228
<< std::endl;
227229
}
228230
}

0 commit comments

Comments
 (0)