Skip to content

Commit

Permalink
Revert D62999476
Browse files Browse the repository at this point in the history
Summary:
This diff reverts D62999476
T202404456

Reviewed By: mdko, voorka

Differential Revision: D63203812

fbshipit-source-id: 25349121fa4efe6dcd7403d3e98d0d10b8110ecf
  • Loading branch information
generatedunixname89002005232357 authored and facebook-github-bot committed Sep 21, 2024
1 parent 3e133bd commit 56c5f56
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 20 deletions.
14 changes: 7 additions & 7 deletions hphp/runtime/ext/thrift/binary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ Variant binary_deserialize_internal(int8_t thrift_typeID,
auto const& val_spec = fieldspec.val();
hasTypeWrapper = hasTypeWrapper || val_spec.isTypeWrapped;
if (s_harray.equal(fieldspec.format)) {
DictInit arr(get_initial_array_size(size));
DictInit arr(size);
for (uint32_t i = 0; i < size; i++) {
switch (types[0]) {
case TType::T_I08:
Expand Down Expand Up @@ -208,7 +208,7 @@ Variant binary_deserialize_internal(int8_t thrift_typeID,
}
return arr.toVariant();
} else if (s_collection.equal(fieldspec.format)) {
auto obj(req::make<c_Map>(get_initial_array_size(size)));
auto obj(req::make<c_Map>(size));
for (uint32_t s = 0; s < size; ++s) {
auto key = binary_deserialize(
types[0], transport, key_spec, options, hasTypeWrapper);
Expand All @@ -218,7 +218,7 @@ Variant binary_deserialize_internal(int8_t thrift_typeID,
}
return Variant(std::move(obj));
} else {
DictInit arr(get_initial_array_size(size));
DictInit arr(size);
if (options & k_THRIFT_MARK_LEGACY_ARRAYS) {
arr.setLegacyArray();
}
Expand Down Expand Up @@ -250,7 +250,7 @@ Variant binary_deserialize_internal(int8_t thrift_typeID,
if (size == 0) {
return Variant(req::make<c_Vector>());
}
auto vec = req::make<c_Vector>(get_initial_array_size(size));
auto vec = req::make<c_Vector>(size);
int64_t i = 0;
do {
auto val = binary_deserialize(
Expand Down Expand Up @@ -280,15 +280,15 @@ Variant binary_deserialize_internal(int8_t thrift_typeID,
check_container_size(size);
auto const& val_spec = fieldspec.val();
if (s_harray.equal(fieldspec.format)) {
KeysetInit arr(get_initial_array_size(size));
KeysetInit arr(size);
for (uint32_t i = 0; i < size; i++) {
arr.add(
binary_deserialize(type, transport, val_spec, options, hasTypeWrapper)
);
}
return arr.toVariant();
} else if (s_collection.equal(fieldspec.format)) {
auto set_ret(req::make<c_Set>(get_initial_array_size(size)));
auto set_ret(req::make<c_Set>(size));
for (uint32_t s = 0; s < size; ++s) {
Variant key = binary_deserialize(
type, transport, val_spec, options, hasTypeWrapper);
Expand All @@ -301,7 +301,7 @@ Variant binary_deserialize_internal(int8_t thrift_typeID,

return Variant(std::move(set_ret));
} else {
DictInit init(get_initial_array_size(size));
DictInit init(size);
if (options & k_THRIFT_MARK_LEGACY_ARRAYS) {
init.setLegacyArray();
}
Expand Down
14 changes: 7 additions & 7 deletions hphp/runtime/ext/thrift/compact.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1118,7 +1118,7 @@ struct CompactReader {
const uint32_t size,
bool& hasTypeWrapper
) {
DictInit arr(get_initial_array_size(size));
DictInit arr(size);
switch (keyType) {
case TType::T_I08:
case TType::T_I16:
Expand Down Expand Up @@ -1163,7 +1163,7 @@ struct CompactReader {
const uint32_t size,
bool& hasTypeWrapper
) {
auto map(req::make<c_Map>(get_initial_array_size(size)));
auto map(req::make<c_Map>(size));
if (spec.key().adapter == nullptr && spec.val().adapter == nullptr &&
typeIs16to64Int(keyType) && typeIs16to64Int(valueType)) {
hasTypeWrapper = hasTypeWrapper || spec.key().isTypeWrapped || spec.val().isTypeWrapped;
Expand All @@ -1190,7 +1190,7 @@ struct CompactReader {
} else if (s_collection.equal(spec.format)) {
return readMapCollection(spec, keyType, valueType, size, hasTypeWrapper);
} else {
DictInit arr(get_initial_array_size(size));
DictInit arr(size);
if (options & k_THRIFT_MARK_LEGACY_ARRAYS) {
arr.setLegacyArray();
}
Expand Down Expand Up @@ -1260,7 +1260,7 @@ struct CompactReader {
readCollectionEnd();
return Variant(req::make<c_Vector>());
}
auto vec = req::make<c_Vector>(get_initial_array_size(size));
auto vec = req::make<c_Vector>(size);
if (spec.val().adapter == nullptr && typeIs16to64Int(valueType)) {
readIntList(
[&, i = 0LL](int64_t val) mutable {
Expand Down Expand Up @@ -1307,22 +1307,22 @@ struct CompactReader {
readListBegin(valueType, size);

if (s_harray.equal(spec.format)) {
KeysetInit arr(get_initial_array_size(size));
KeysetInit arr(size);
for (uint32_t i = 0; i < size; i++) {
arr.add(readField(spec.val(), valueType, hasTypeWrapper));
}
readCollectionEnd();
return arr.toVariant();
} else if (s_collection.equal(spec.format)) {
auto set_ret = req::make<c_Set>(get_initial_array_size(size));
auto set_ret = req::make<c_Set>(size);
for (uint32_t i = 0; i < size; i++) {
Variant value = readField(spec.val(), valueType, hasTypeWrapper);
set_ret->add(value);
}
readCollectionEnd();
return Variant(std::move(set_ret));
} else {
DictInit ainit(get_initial_array_size(size));
DictInit ainit(size);
if (options & k_THRIFT_MARK_LEGACY_ARRAYS) {
ainit.setLegacyArray();
}
Expand Down
8 changes: 2 additions & 6 deletions hphp/runtime/ext/thrift/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,11 @@ inline bool is_value_type_default(int8_t thrift_typeID, const Variant& value) {
}
}

inline uint32_t get_initial_array_size(const uint32_t size) {
inline Array initialize_array(const uint32_t size) {
// Reserve up to 16k entries for perf - but after that use "normal"
// array expansion so that we ensure the data is actually there before
// allocating massive arrays.
return std::min(16384u, size);
}

inline Array initialize_array(const uint32_t size) {
return Array::attach(VanillaVec::MakeReserveVec(get_initial_array_size(size)));
return Array::attach(VanillaVec::MakeReserveVec(std::min(16384u, size)));
}

inline void check_container_size(const uint32_t size) {
Expand Down

0 comments on commit 56c5f56

Please sign in to comment.