morningman commented on code in PR #69019:
URL: https://github.com/apache/doris/pull/69019#discussion_r4259532927


##########
be/src/core/value/variant/variant_field.cpp:
##########
@@ -148,13 +142,15 @@ size_t object_values_offset(VariantRef value, uint32_t 
count) {
            (static_cast<size_t>(count) + 1) * offset_width;
 }
 
-void require_valid_object(VariantRef value, uint32_t depth) {
+} // namespace
+
+void VariantPayloadValidator::require_valid_object(VariantRef value, uint32_t 
depth) {
     const uint32_t count = value.num_elements();
     const size_t values_offset = object_values_offset(value, count);
     const char* values_begin = value.value.data + values_offset;
     const size_t values_size = value.value.size - values_offset;
-    std::vector<ObjectValueSpan> spans;
-    spans.reserve(count);
+    // Entries below base belong to the ancestors of this object; see 
_object_spans.
+    const size_t base = _object_spans.size();

Review Comment:
   Fixed in 54c9572e943. `require_valid_object()` reserves the object's `base + 
count` spans before it checks the fields, taking at least twice the current 
capacity. A fresh validator therefore allocates once for a flat object (1000 
fields: one allocation of 1000 instead of growing 1, 2, 4, ..., 1024). Taking 
at least twice the capacity matters for siblings: with an exact `base + count`, 
a root of 26 objects of 30 fields would reallocate for every sibling once `k + 
30` passes the capacity; this grows 26 -> 52 -> 104.
   
   `VariantFieldTest.FreshValidatorReservesAnObjectOnce` pins both: capacity 
1000 after the flat object and 104 after the nested one. Without the 
reservation it reads 1024 and 64, and with an exact reservation the nested case 
reads 55.
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to