Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 14 additions & 23 deletions ydb/core/base/logoblob.cpp
Original file line number Diff line number Diff line change
@@ -1,35 +1,26 @@
#include "logoblob.h"
#include <ydb/core/protos/base.pb.h>
#include <util/string/printf.h>

namespace NKikimr {

TString TLogoBlobID::ToString() const {
return Sprintf(
"[%" PRIu64 ":%" PRIu32 ":%" PRIu32 ":%" PRIu32 ":%" PRIu32 ":%" PRIu32 ":%" PRIu32 "]",
TabletID(),
Generation(),
Step(),
Channel(),
Cookie(),
BlobSize(),
PartId()).data();
TString str;
str.reserve(64);
TStringOutput outStr(str);
Out(outStr);
return str;
}

void TLogoBlobID::Out(IOutputStream &o) const {
char buf[240];
snprintf(buf, sizeof(buf),
"[%" PRIu64 ":%" PRIu32 ":%" PRIu32 ":%" PRIu32 ":%" PRIu32 ":%" PRIu32 ":%" PRIu32 "]",
TabletID(),
Generation(),
Step(),
Channel(),
Cookie(),
BlobSize(),
PartId()
);

o << buf;
o << '['
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

15 виртуальных вызовов нам для этого нужно :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ну как мы любим, пусть разработчики компиляторов и процессоров делают свою работу и оптимизируют виртуальные вызовы

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

побенчили с Сашей, получилось, что новая версия строго быстрее

ToString(Sprintf): 5.345924s
Out(snprintf): 5.017919s
ToString(stream): 3.712372s
Out(stream): 3.966677s

<< TabletID() << ':'
<< Generation() << ':'
<< Step() << ':'
<< Channel() << ':'
<< Cookie() << ':'
<< BlobSize() << ':'
<< PartId()
<< ']' ;
}

void TLogoBlobID::Out(IOutputStream &o, const TVector<TLogoBlobID> &vec) {
Expand Down
13 changes: 6 additions & 7 deletions ydb/core/base/traceid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,15 @@ TTraceID TTraceID::GenerateNew() {
}

TString TTraceID::ToString() const {
TString result;
TStringOutput out(result);
Out(out);
return result;
TString str;
str.reserve(128);
TStringOutput outStr(str);
Out(outStr);
return str;
}

void TTraceID::Out(IOutputStream &o) const {
char buf[240];
snprintf(buf, sizeof(buf), "[ID:%" PRIu64 ", Created: %s]", RandomID, TInstant::MicroSeconds(CreationTime).ToRfc822StringLocal().data());
o << buf;
o << "[ID: " << RandomID << ", " << "Created: " << TInstant::MicroSeconds(CreationTime).ToRfc822StringLocal() << "]";
}

bool TTraceID::operator<(const TTraceID &x) const {
Expand Down