From: Eric Blake <eblake@redhat.com>
To: Paolo Bonzini <pbonzini@redhat.com>, qemu-devel@nongnu.org
Cc: armbru@redhat.com
Subject: Re: [Qemu-devel] [PATCH 4/4] qjson: surprise, allocating 6 QObjects per token is expensive
Date: Fri, 20 Nov 2015 11:48:55 -0700 [thread overview]
Message-ID: <564F6B17.5040201@redhat.com> (raw)
In-Reply-To: <1448010269-21694-5-git-send-email-pbonzini@redhat.com>
[-- Attachment #1: Type: text/plain, Size: 1950 bytes --]
On 11/20/2015 02:04 AM, Paolo Bonzini wrote:
> Replace the contents of the tokens GQueue with a simple struct. This cuts
> the amount of memory allocated by tests/check-qjson from ~500MB to ~20MB,
> and the execution time from 600ms to 80ms on my laptop. Still a lot (some
> could be saved by using an intrusive list, such as QSIMPLEQ, instead of
> the GQueue), but the savings are already massive and the right thing to
> do would probably be to get rid of json-streamer completely.
>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
> include/qapi/qmp/json-streamer.h | 7 ++++
> qobject/json-parser.c | 81 +++++++++++++++++++---------------------
> qobject/json-streamer.c | 19 ++++------
> 3 files changed, 53 insertions(+), 54 deletions(-)
>
> @@ -54,15 +50,16 @@ static void json_message_process_token(JSONLexer *lexer, GString *input, JSONTok
> }
> }
>
> - dict = qdict_new();
> - qdict_put(dict, "type", qint_from_int(type));
> - qdict_put(dict, "token", qstring_from_str(input->str));
> - qdict_put(dict, "x", qint_from_int(x));
> - qdict_put(dict, "y", qint_from_int(y));
> + token = g_malloc(sizeof(JSONToken) + input->len + 1);
> + token->type = type;
> + memcpy(token->str, input->str, input->len + 1);
> + token->str[input->len] = 0;
Looks like you are writing the last byte twice. Either the +1 in the
memcpy() always copies a NUL byte and we don't need the second
assignment, or you should drop the +1.
Otherwise, looks like a sane replacement that saves a lot of memory.
Reviewed-by: Eric Blake <eblake@redhat.com>
Are we hoping to get this in 2.5 because it fixes the memory hog bug, or
are we considering that it is not a regression from 2.4 and therefore
something that should wait for 2.6?
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 604 bytes --]
next prev parent reply other threads:[~2015-11-20 18:49 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-11-20 9:04 [Qemu-devel] [PATCH 0/4] qjson: save a lot of memory Paolo Bonzini
2015-11-20 9:04 ` [Qemu-devel] [PATCH 1/4] qjson: replace QString in JSONLexer with GString Paolo Bonzini
2015-11-20 18:23 ` Eric Blake
2015-11-20 20:16 ` Paolo Bonzini
2015-11-20 9:04 ` [Qemu-devel] [PATCH 2/4] qjson: do not save/restore contexts Paolo Bonzini
2015-11-20 18:28 ` Eric Blake
2015-11-20 20:17 ` Paolo Bonzini
2015-11-20 9:04 ` [Qemu-devel] [PATCH 3/4] qjson: store tokens in a GQueue Paolo Bonzini
2015-11-20 18:40 ` Eric Blake
2015-11-20 9:04 ` [Qemu-devel] [PATCH 4/4] qjson: surprise, allocating 6 QObjects per token is expensive Paolo Bonzini
2015-11-20 18:48 ` Eric Blake [this message]
2015-11-20 20:19 ` Paolo Bonzini
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=564F6B17.5040201@redhat.com \
--to=eblake@redhat.com \
--cc=armbru@redhat.com \
--cc=pbonzini@redhat.com \
--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.