Skip to content

Commit 443ff63

Browse files
committed
MutationLog: Perf: Don't initialise buffers until needed
Optimize the construction of MutationLog::iterator to not create the buffer objects until they are actually used. In the case of an end() iterator; we were pointlessly creating (and initializing) buffers which were never used. In Debug build types, this significantly reduces the runtime of the DurabilityWarmupTests: Before: [----------] 1 test from FullOrValue/DurabilityWarmupTest [ RUN ] FullOrValue/DurabilityWarmupTest.ReplicaCommittedAndPendingSyncDelete/persistent_value_only [ OK ] FullOrValue/DurabilityWarmupTest.ReplicaCommittedAndPendingSyncDelete/persistent_value_only (2370 ms) [----------] 1 test from FullOrValue/DurabilityWarmupTest (2370 ms total) After: [----------] 1 test from FullOrValue/DurabilityWarmupTest [ RUN ] FullOrValue/DurabilityWarmupTest.ReplicaCommittedAndPendingSyncDelete/persistent_value_only [ OK ] FullOrValue/DurabilityWarmupTest.ReplicaCommittedAndPendingSyncDelete/persistent_value_only (122 ms) [----------] 1 test from FullOrValue/DurabilityWarmupTest (122 ms total) Change-Id: Ie62c72d8d1613ea069d377e071740fcabfddffcb Reviewed-on: http://review.couchbase.org/113379 Tested-by: Build Bot <[email protected]> Reviewed-by: Jim Walker <[email protected]>
1 parent e084c73 commit 443ff63

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

engines/ep/src/mutation_log.cc

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -724,9 +724,6 @@ void MutationLog::writeEntry(MutationLogEntry *mle) {
724724

725725
MutationLog::iterator::iterator(const MutationLog* l, bool e)
726726
: log(l),
727-
entryBuf(LOG_ENTRY_BUF_SIZE),
728-
buf(log->header().blockSize()),
729-
p(buf.begin()),
730727
offset(l->header().blockSize() * l->header().blockCount()),
731728
items(0),
732729
isEnd(e) {
@@ -781,6 +778,7 @@ void MutationLog::iterator::prepItem() {
781778
}
782779
}
783780

781+
entryBuf.resize(LOG_ENTRY_BUF_SIZE);
784782
std::copy_n(p, copyLen, entryBuf.begin());
785783
}
786784

@@ -948,6 +946,7 @@ void MutationLog::iterator::nextBlock() {
948946
"log is enabled and not open");
949947
}
950948

949+
buf.resize(log->header().blockSize());
951950
ssize_t bytesread = pread(log->fd(), buf.data(), buf.size(), offset);
952951
if (bytesread < 1) {
953952
isEnd = true;

0 commit comments

Comments
 (0)