Skip to content

Commit d9a948f

Browse files
committed
Optimize TSpan methods to prevent unneeded object construction KIKIMR-15449
1 parent 00eda0e commit d9a948f

File tree

4 files changed

+29
-14
lines changed

4 files changed

+29
-14
lines changed

ydb/core/blobstorage/backpressure/queue.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,9 +203,9 @@ void TBlobStorageQueue::SendToVDisk(const TActorContext& ctx, const TActorId& re
203203
++*QueueItemsSent;
204204

205205
// send item
206-
item.Span.Event("SendToVDisk", {{
206+
item.Span && item.Span.Event("SendToVDisk", {
207207
{"VDiskOrderNumber", vdiskOrderNumber}
208-
}});
208+
});
209209
item.Event.SendToVDisk(ctx, remoteVDisk, item.QueueCookie, item.MsgId, item.SequenceId, sendMeCostSettings,
210210
item.Span.GetTraceId(), ClientId, item.ProcessingTimer);
211211

ydb/core/blobstorage/vdisk/huge/blobstorage_hullhuge.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ LWTRACE_USING(BLOBSTORAGE_PROVIDER);
193193
"Writer: bootstrap: id# %s chunkId# %u offset# %u storedBlobSize# %u "
194194
"writtenSize# %u", HugeSlot.ToString().data(), chunkId, offset,
195195
storedBlobSize, writtenSize));
196-
Span.Event("Send_TEvChunkWrite", NWilson::TKeyValueList{{{"ChunkId", chunkId}, {"Offset", offset}, {"WrittenSize", writtenSize}}});
196+
Span && Span.Event("Send_TEvChunkWrite", {{"ChunkId", chunkId}, {"Offset", offset}, {"WrittenSize", writtenSize}});
197197
auto ev = std::make_unique<NPDisk::TEvChunkWrite>(HugeKeeperCtx->PDiskCtx->Dsk->Owner,
198198
HugeKeeperCtx->PDiskCtx->Dsk->OwnerRound, chunkId, offset,
199199
partsPtr, Cookie, true, GetWritePriority(), false);

ydb/core/tablet_flat/flat_executor_txloglogic.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,9 @@ TLogicRedo::TCommitRWTransactionResult TLogicRedo::CommitRWTransaction(
188188

189189
Batch->Commit->FirstTx->TxSpan.Attribute("BatchSize", batchSize);
190190

191-
seat->TxSpan.Attribute("Batched", true);
192-
seat->TxSpan.Link(Batch->Commit->FirstTx->GetTxTraceId(), {});
191+
seat->TxSpan
192+
.Attribute("Batched", true)
193+
.Link(Batch->Commit->FirstTx->GetTxTraceId());
193194
}
194195

195196
Batch->Commit->PushTx(seat.Get());

ydb/library/actors/wilson/wilson_span.h

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -159,29 +159,32 @@ namespace NWilson {
159159
return *this;
160160
}
161161

162-
TSpan& Name(TString name) {
162+
template<typename T>
163+
TSpan& Name(T&& name) {
163164
if (Y_UNLIKELY(*this)) {
164-
Data->Span.set_name(std::move(name));
165+
Data->Span.set_name(std::forward<T>(name));
165166
} else {
166167
VerifyNotSent();
167168
}
168169
return *this;
169170
}
170171

171-
TSpan& Attribute(TString name, TAttributeValue value) {
172+
template<typename T, typename T1>
173+
TSpan& Attribute(T&& name, T1&& value) {
172174
if (Y_UNLIKELY(*this)) {
173-
SerializeKeyValue(std::move(name), std::move(value), Data->Span.add_attributes());
175+
SerializeKeyValue(std::forward<T>(name), std::forward<T1>(value), Data->Span.add_attributes());
174176
} else {
175177
VerifyNotSent();
176178
}
177179
return *this;
178180
}
179181

180-
TSpan& Event(TString name, TKeyValueList attributes) {
182+
template<typename T, typename T1 = std::initializer_list<std::pair<TString, TAttributeValue>>>
183+
TSpan& Event(T&& name, T1&& attributes) {
181184
if (Y_UNLIKELY(*this)) {
182185
auto *event = Data->Span.add_events();
183186
event->set_time_unix_nano(TimeUnixNano());
184-
event->set_name(std::move(name));
187+
event->set_name(std::forward<T>(name));
185188
for (auto&& [key, value] : attributes) {
186189
SerializeKeyValue(std::move(key), std::move(value), event->add_attributes());
187190
}
@@ -191,7 +194,13 @@ namespace NWilson {
191194
return *this;
192195
}
193196

194-
TSpan& Link(const TTraceId& traceId, TKeyValueList attributes) {
197+
template<typename T>
198+
TSpan& Event(T&& name) {
199+
return Event(std::forward<T>(name), {});
200+
}
201+
202+
template<typename T = std::initializer_list<std::pair<TString, TAttributeValue>>>
203+
TSpan& Link(const TTraceId& traceId, T&& attributes) {
195204
if (Y_UNLIKELY(*this)) {
196205
auto *link = Data->Span.add_links();
197206
link->set_trace_id(traceId.GetTraceIdPtr(), traceId.GetTraceIdSize());
@@ -205,6 +214,10 @@ namespace NWilson {
205214
return *this;
206215
}
207216

217+
TSpan& Link(const TTraceId& traceId) {
218+
return Link(traceId, {});
219+
}
220+
208221
void EndOk() {
209222
if (Y_UNLIKELY(*this)) {
210223
auto *status = Data->Span.mutable_status();
@@ -215,11 +228,12 @@ namespace NWilson {
215228
}
216229
}
217230

218-
void EndError(TString error) {
231+
template<typename T>
232+
void EndError(T&& error) {
219233
if (Y_UNLIKELY(*this)) {
220234
auto *status = Data->Span.mutable_status();
221235
status->set_code(NTraceProto::Status::STATUS_CODE_ERROR);
222-
status->set_message(std::move(error));
236+
status->set_message(std::forward<T>(error));
223237
End();
224238
} else {
225239
VerifyNotSent();

0 commit comments

Comments
 (0)