diff options
author | Maksim Kita <kitaetoya@gmail.com> | 2023-07-04 12:07:15 +0000 |
---|---|---|
committer | maksim-kita <maksim-kita@yandex-team.com> | 2023-07-04 15:07:15 +0300 |
commit | 0c73f14a2f879efbfa04212af49f99263a94856a (patch) | |
tree | 7e5991ee107da9917c0873d812a55d0c3a8187ed | |
parent | 0a78431e3d51505091495c6a27559b1120f79b98 (diff) | |
download | ydb-0c73f14a2f879efbfa04212af49f99263a94856a.tar.gz |
SerializedCellVec improve serialization performance
SerializedCellVec improve serialization performance
Pull Request resolved: #286
-rw-r--r-- | ydb/core/scheme/scheme_tablecell.cpp | 26 | ||||
-rw-r--r-- | ydb/core/scheme/scheme_tablecell_ut.cpp | 11 |
2 files changed, 28 insertions, 9 deletions
diff --git a/ydb/core/scheme/scheme_tablecell.cpp b/ydb/core/scheme/scheme_tablecell.cpp index 48f3d402181..04c2aaf4a69 100644 --- a/ydb/core/scheme/scheme_tablecell.cpp +++ b/ydb/core/scheme/scheme_tablecell.cpp @@ -105,7 +105,7 @@ namespace { resultBufferData += sizeof(cellsSize); if (resultCells) { - resultCells->resize(cellsSize); + resultCells->resize_uninitialized(cellsSize); } for (size_t i = 0; i < cellsSize; ++i) { @@ -118,8 +118,12 @@ namespace { memcpy(resultBufferData, cell.Data(), cell.Size()); } - if (resultCells && !cell.IsNull()) { - (*resultCells)[i] = TCell(resultBufferData, cell.Size()); + if (resultCells) { + if (cell.IsNull()) { + new (resultCells->data() + i) TCell(); + } else { + new (resultCells->data() + i) TCell(resultBufferData, cell.Size()); + } } resultBufferData += cell.Size(); @@ -135,16 +139,17 @@ namespace { const char* buf = data.data(); const char* bufEnd = data.data() + data.size(); - if (bufEnd - buf < static_cast<ptrdiff_t>(sizeof(ui16))) + if (Y_UNLIKELY(bufEnd - buf < static_cast<ptrdiff_t>(sizeof(ui16)))) return false; ui16 cellsSize = ReadUnaligned<ui16>(buf); buf += sizeof(cellsSize); - resultCells.resize(cellsSize); + resultCells.resize_uninitialized(cellsSize); + TCell* resultCellsData = resultCells.data(); for (ui32 i = 0; i < cellsSize; ++i) { - if (bufEnd - buf < static_cast<ptrdiff_t>(sizeof(TCellHeader))) { + if (Y_UNLIKELY(bufEnd - buf < static_cast<ptrdiff_t>(sizeof(TCellHeader)))) { resultCells.clear(); return false; } @@ -152,12 +157,17 @@ namespace { TCellHeader cellHeader = ReadUnaligned<TCellHeader>(buf); buf += sizeof(cellHeader); - if (bufEnd - buf < static_cast<ptrdiff_t>(cellHeader.CellSize())) { + if (Y_UNLIKELY(bufEnd - buf < static_cast<ptrdiff_t>(cellHeader.CellSize()))) { resultCells.clear(); return false; } - resultCells[i] = cellHeader.IsNull() ? TCell() : TCell(buf, cellHeader.CellSize()); + if (cellHeader.IsNull()) { + new (resultCellsData + i) TCell(); + } else { + new (resultCellsData + i) TCell(buf, cellHeader.CellSize()); + } + buf += cellHeader.CellSize(); } diff --git a/ydb/core/scheme/scheme_tablecell_ut.cpp b/ydb/core/scheme/scheme_tablecell_ut.cpp index 83520a70ac5..60c7c7d9638 100644 --- a/ydb/core/scheme/scheme_tablecell_ut.cpp +++ b/ydb/core/scheme/scheme_tablecell_ut.cpp @@ -157,9 +157,18 @@ Y_UNIT_TEST_SUITE(Scheme) { } { + TInstant start = TInstant::Now(); + for (int i = 0; i < ITERATIONS; ++i) { + TSerializedCellVec vec4(vec.GetCells()); + } + TInstant finish = TInstant::Now(); + Cerr << "Cells constructor: " << finish - start << Endl; + } + + { TString buf = vec.GetBuffer(); TInstant start = TInstant::Now(); - for (int i = 0; i < ITERATIONS; ++i) { + for (int i = 0; i < ITERATIONS; ++i) { vec3.Parse(buf); } TInstant finish = TInstant::Now(); |