Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Pre-reserve object dynamic properties when unserializing
  • Loading branch information
jjergus committed Jun 30, 2020
1 parent 1107228 commit c1c4bb0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
5 changes: 5 additions & 0 deletions hphp/runtime/base/object-data.cpp
Expand Up @@ -342,6 +342,11 @@ Array& ObjectData::reserveProperties(int numDynamic /* = 2 */) {
return dynPropArray();
}

auto const allocsz = MixedArray::computeAllocBytesFromMaxElms(numDynamic);
if (UNLIKELY(allocsz > kMaxSmallSize && tl_heap->preAllocOOM(allocsz))) {
check_non_safepoint_surprise();
}

return setDynPropArray(
Array::attach(MixedArray::MakeReserveMixed(numDynamic))
);
Expand Down
1 change: 1 addition & 0 deletions hphp/runtime/base/variable-unserializer.cpp
Expand Up @@ -552,6 +552,7 @@ void VariableUnserializer::unserializeProp(ObjectData* obj,
// Unserialize as a dynamic property. If this is the first, we need to
// pre-allocate space in the array to ensure the elements don't move during
// unserialization.
obj->reserveDynProps(nProp);
t = obj->makeDynProp(realKey.get());
} else {
// We'll check if this doesn't violate the type-hint once we're done
Expand Down

0 comments on commit c1c4bb0

Please sign in to comment.