Skip to content

Commit 1d78b31

Browse files
paroskiEvergreen Agent
authored andcommitted
SERVER-83528 Improve perf of ByteCode::allocStack()
1 parent 3c8f683 commit 1d78b31

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

src/mongo/db/exec/sbe/vm/vm.cpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -214,16 +214,15 @@ int Instruction::stackOffset[Instruction::Tags::lastInstruction] = {
214214
-1, // valueBlockApplyLambda
215215
};
216216

217-
void ByteCode::allocStack(size_t size) noexcept {
218-
invariant(size > 0);
219-
auto newSizeDelta = size * sizeOfElement;
217+
void ByteCode::allocStackImpl(size_t newSizeDelta) noexcept {
218+
invariant(newSizeDelta > 0);
219+
220220
auto oldSize = _argStackEnd - _argStack;
221-
if (_argStackEnd <= _argStackTop + newSizeDelta) {
222-
auto oldTop = _argStackTop - _argStack;
223-
_argStack = reinterpret_cast<uint8_t*>(mongoRealloc(_argStack, oldSize + newSizeDelta));
224-
_argStackEnd = _argStack + oldSize + newSizeDelta;
225-
_argStackTop = _argStack + oldTop;
226-
}
221+
auto oldTop = _argStackTop - _argStack;
222+
223+
_argStack = reinterpret_cast<uint8_t*>(mongoRealloc(_argStack, oldSize + newSizeDelta));
224+
_argStackEnd = _argStack + oldSize + newSizeDelta;
225+
_argStackTop = _argStack + oldTop;
227226
}
228227

229228
std::string CodeFragment::toString() const {

src/mongo/db/exec/sbe/vm/vm.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2276,7 +2276,15 @@ class ByteCode {
22762276
_argStackTop = _argStack - sizeOfElement;
22772277
}
22782278

2279-
void allocStack(size_t size) noexcept;
2279+
MONGO_COMPILER_ALWAYS_INLINE_OPT void allocStack(size_t size) noexcept {
2280+
auto newSizeDelta = size * sizeOfElement;
2281+
if (_argStackEnd <= _argStackTop + newSizeDelta) {
2282+
allocStackImpl(newSizeDelta);
2283+
}
2284+
}
2285+
2286+
void allocStackImpl(size_t newSizeDelta) noexcept;
2287+
22802288
void swapStack();
22812289

22822290
// The top entry in '_argStack', or one element before the stack when empty.

0 commit comments

Comments
 (0)