Skip to content

Commit 8ea8692

Browse files
committed
src: optimize trace_name allocation in Worker::Run
1 parent 0c80bc1 commit 8ea8692

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/node_worker.cc

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -296,11 +296,13 @@ size_t Worker::NearHeapLimit(void* data, size_t current_heap_limit,
296296

297297
void Worker::Run() {
298298
std::string trace_name;
299-
// Pre-allocate space: "[worker " (8) + thread_id (20) + "]" (1) + " " (1)
300-
// + typical name (~30) = ~60 bytes. Use 64 for alignment.
301-
trace_name.reserve(64);
299+
std::string id = std::to_string(thread_id_.id);
300+
// Pre-allocate space: "[worker " (8) + thread_id + "]" (1)
301+
// + (optional: " " (1) + name)
302+
trace_name.reserve(8 + id.size() + 1 +
303+
(name_.empty() ? 0 : 1 + name_.size()));
302304
trace_name = "[worker ";
303-
trace_name += std::to_string(thread_id_.id);
305+
trace_name += id;
304306
trace_name += "]";
305307
if (!name_.empty()) {
306308
trace_name += " ";

0 commit comments

Comments
 (0)