Daniel P. Berrangé <[email protected]> writes:

> On Tue, Jun 02, 2026 at 10:34:43AM +0200, Markus Armbruster wrote:
>> Bin Guo <[email protected]> writes:
>> 
>> > json_writer_new() creates the output GString with g_string_new(NULL),
>> > which starts at the GLib default of 64 bytes.  Serializing typical
>> > QMP responses then requires multiple reallocations as the buffer
>> > grows -- for query-qmp-schema the GString is reallocated 12+ times.
>> 
>> That's an extreme case.  Most responses are *much* smaller.  Still,
>> starting with a larger buffer makes sense.
>> 
>> > Preallocate JSON_WRITER_INITIAL_SIZE (4096) bytes.  This covers
>> > most QMP responses without any reallocation.  4096 is one page on
>> > most systems, which is efficient for the allocator.
>> 
>> I doubt "one page" matters.  How many QMP commands get executed in
>> practice?  A couple of hundred during startup, then tens per second?
>> Probably less than that.
>
> NB tens per second, repeated across possibly 100's or even 1000's of
> VMs on the single host though.
>
> If we want an arbitrary moderately size buffer, one page feels like
> a reasonable place to aim for

I think 4KiB is a reasonable initial size regardless of the host's page
size.  That was my argument.

If we care, we can instrument QEMU to gather response size statistics.

[...]


Reply via email to