Skip to content

Commit

Permalink
Merge pull request #18706 from ghalliday/issue31953
Browse files Browse the repository at this point in the history
HPCC-31953 Avoid memory allocation when reading an index node

Reviewed-By: Richard Chapman <[email protected]>
Merged-by: Gavin Halliday <[email protected]>
  • Loading branch information
ghalliday authored May 31, 2024
2 parents c8c0b4e + 485be94 commit 758edb9
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion system/jhtree/jhtree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1244,8 +1244,17 @@ const CJHTreeNode *CDiskKeyIndex::loadNode(cycle_t * fetchCycles, offset_t pos,
nodesLoaded++;
if (!useIO) useIO = io;
unsigned nodeSize = keyHdr->getNodeSize();

//Use alloca() to allocate a buffer on the stack if the node size is small enough.
//Often the data could be read directly from the input files's buffer and not even be copied.
//Should we have a io->peek(pos, size) which returns a pointer if supported?
constexpr const size_t maxStackSize = 8192; // Default node size
MemoryAttr ma;
char *nodeData = (char *) ma.allocate(nodeSize);
char *nodeData;
if (nodeSize <= maxStackSize)
nodeData = (char *) alloca(nodeSize);
else
nodeData = (char *) ma.allocate(nodeSize);
assertex(nodeData);

CCycleTimer fetchTimer(fetchCycles != nullptr);
Expand Down

0 comments on commit 758edb9

Please sign in to comment.