Skip to content

ChunkedToXContentBuilder should be removed #118647

@original-brownbear

Description

@original-brownbear

The current idea behind ChunkedToXContentBuilder is broken. We create the ChunkedToXContentBuilder which is essentially a flat stream of the chunks we're building up-front at the beginning of serialization.
This runs counter to the whole concept of ChunkedToXContent which tries to ideally be O(1) in terms of up-front heap and runtime cost by pushing all iterations down to when we actually serialize.
I get how the API looks nicer than manually building iterators but this kind of API when combined with iteration (both internally or at the start of the serialization) breaks chunking.
We see this practically and very visibly in search response (and to a lesser degree also for bulk responses) serialization slowness today and almost more importantly the approach causes stability issues on the transport layer in an unpredictable way.

I don't think the API can be fixed or that it is worthwhile to fix it. The slight improvement in readability of the code comes at the cost of unpredictable and hard to reason about performance here as would probably any solution not built on statically known iteration counts.
Marking this as >bug since I am observing an uptick in transport thread slowness from it and it's easy to construct search use cases that destabilize a cluster since its introduction into the search response handling.

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions