Details
Description
array_star() makes use of pools of objects for re-use instead of creating objects with each evaluation of the function. For example:
// few objects will be allocated to accommodate
|
// the input list, the two objects, and the fields in those two objects
|
array_star([{"x1": 1, "x2": {"y1": 4}}, {"x1": 5, "x2": {"y1": 8}}]);
|
// previously allocated objects will be used but few more objects will be allocated to accommodate
|
// any extra elements, fields, e.g. the third object in the array, the extra fields "y2", "x3", ... etc
|
array_star([{"x1": 1, "x2": {"y1": 4}}, {"x1": 5, "x2": {"y1": 8}}, {"x1": 0, "x2": {"y1": 8, "y2": 9}, "x3": true}]);
|
While using pools in functions avoids objects creation, there are several problems:
- these pools always grow in number of objects as the demand for objects grow, but can never shrink back (to at least a defined number of objects).
- these pools have no cap.
- if such functions are used in the ingestion pipeline, they stay live for the life of the ingestion pipeline holding memory for these pools of objects. In cases where documents change and grow in structure, the pools will grow to accommodate any extra elements in arrays, fields in objects, ... etc if needed. For queries, the problem is less since the memory will be reclaimed as soon as the query finishes.
Also, for array_star(), it seems that some pools could be eliminated.