From: Markus Armbruster <armbru@redhat.com>
To: Peter Maydell <peter.maydell@linaro.org>
Cc: qemu-devel@nongnu.org, kwolf@redhat.com, hreitz@redhat.com
Subject: Re: [RFC PATCH] qobject: Rewrite implementation of QDict for in-order traversal
Date: Thu, 07 Jul 2022 16:27:35 +0200 [thread overview]
Message-ID: <87zghlatgo.fsf@pond.sub.org> (raw)
In-Reply-To: <CAFEAcA-xaQSOGWixtnq0XosSsdt2VKACxgCK5KpdkNscBPD-wA@mail.gmail.com> (Peter Maydell's message of "Thu, 7 Jul 2022 13:57:22 +0100")
Peter Maydell <peter.maydell@linaro.org> writes:
> On Tue, 5 Jul 2022 at 10:54, Markus Armbruster <armbru@redhat.com> wrote:
>>
>> QDict is implemented as a simple hash table of fixed size. Observe:
>>
>> * Slow for large n. Not sure this matters.
>>
>> * A QDict with n entries takes 4120 + n * 32 bytes on my box. Wastes
>> space for small n, which is a common case.
>>
>> * Order of traversal depends on the hash function and on insertion
>> order, because it iterates first over buckets, then collision
>> chains.
>>
>> * Special code ensures qdict_size() takes constant time.
>>
>> Replace the hash table by a linked list. Observe:
>>
>> * Even slower for large n. Might be bad enough to matter.
>>
>> * A QDict with n entries takes 32 + n * 24 bytes.
>>
>> * Traversal is in insertion order.
>>
>> * qdict_size() is linear in the number of entries.
>>
>> This is an experiment. Do not commit to master as is.
>>
>> The change of traversal order affects expected test output. I updated
>> only the tests covered by "make check" so far. I expect some more to
>> hide under tests/qemu-iotests/.
>
> Seems to fix the 'rocker' device regression, at least in that
> it no longer gives an error message on startup.
>
> The amount of patching you had to do to expected-output files
> in 'tests' suggests we have quite a lot of test cases that
> are currently implicitly reliant on the hash table traversal
> order, which is not guaranteed to remain stable.
Correct.
I expect to find a few more in tests not run by "make check".
> Regardless of
> what we do with this patch it would probably be a good idea
> for whatever is outputting the text these tests are comparing
> against to be made to use a stable output order (alphabetical??).
Traversal order before the patch depends on the (fixed) size of the hash
table and the has function for (string) keys. Both have remained
unchanged since the initial commit (2009), which is why we've gotten
away with relying on it in tests.
Traversal order after the patch depends on insertion order. I think
this is already an improvement for the tests: now the expected output
depends on what the test does, not on how qdict.c does its job.
If we think this still isn't good enough, we can investigate how to get
test output where the keys are in alphabetical order.
next prev parent reply other threads:[~2022-07-07 14:28 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-05 9:54 [RFC PATCH] qobject: Rewrite implementation of QDict for in-order traversal Markus Armbruster
2022-07-06 11:35 ` Markus Armbruster
2022-07-06 11:49 ` Mark Cave-Ayland
2022-07-08 11:01 ` Daniel P. Berrangé
2022-07-11 10:32 ` Peter Maydell
2022-07-11 11:09 ` Daniel P. Berrangé
2022-07-11 11:15 ` Peter Maydell
2022-07-18 10:45 ` Markus Armbruster
2022-07-07 12:57 ` Peter Maydell
2022-07-07 14:27 ` Markus Armbruster [this message]
2022-07-07 15:07 ` Daniel P. Berrangé
2022-07-07 14:43 ` Daniel P. Berrangé
2022-07-07 15:37 ` Daniel P. Berrangé
2022-07-07 15:52 ` Alex Bennée
2022-07-08 10:19 ` Markus Armbruster
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=87zghlatgo.fsf@pond.sub.org \
--to=armbru@redhat.com \
--cc=hreitz@redhat.com \
--cc=kwolf@redhat.com \
--cc=peter.maydell@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.