All of lore.kernel.org
 help / color / mirror / Atom feed
From: Markus Armbruster <armbru@redhat.com>
To: Bin Guo <guobin@linux.alibaba.com>
Cc: qemu-devel@nongnu.org,  philmd@linaro.org,
	Paolo Bonzini <pbonzini@redhat.com>
Subject: Re: [PATCH v2] qobject/json-writer: preallocate output buffer
Date: Wed, 03 Jun 2026 09:24:42 +0200	[thread overview]
Message-ID: <871peodr2d.fsf@pond.sub.org> (raw)
In-Reply-To: <20260603022538.92780-1-guobin@linux.alibaba.com> (Bin Guo's message of "Wed, 3 Jun 2026 10:25:38 +0800")

Bin Guo <guobin@linux.alibaba.com> 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.
>
> Preallocate JSON_WRITER_INITIAL_SIZE (4096) bytes.  This covers
> most QMP responses without any reallocation.  The JSONWriter is a
> short-lived object so the preallocation does not accumulate.
>
> Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> Reviewed-by: Markus Armbruster <armbru@redhat.com>
> Signed-off-by: Bin Guo <guobin@linux.alibaba.com>

Thanks!

Paolo, perhaps you can merge this together with your JSON parser
patches.



      reply	other threads:[~2026-06-03  7:25 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-03  2:25 [PATCH v2] qobject/json-writer: preallocate output buffer Bin Guo
2026-06-03  7:24 ` Markus Armbruster [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=871peodr2d.fsf@pond.sub.org \
    --to=armbru@redhat.com \
    --cc=guobin@linux.alibaba.com \
    --cc=pbonzini@redhat.com \
    --cc=philmd@linaro.org \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.