From: Nathan Bossart <nathandbossart@gmail.com>
To: John Naylor <john.naylor@enterprisedb.com>
Cc: Andres Freund <andres@anarazel.de>
Cc: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Jelte Fennema <Jelte.Fennema@microsoft.com>
Cc: pgsql-hackers@postgresql.org <pgsql-hackers@postgresql.org>
Cc: Merlin Moncure <mmoncure@gmail.com>
Cc: Andrew Dunstan <andrew.dunstan@2ndquadrant.com>
Cc: Stephen Frost <sfrost@snowman.net>
Subject: Re: [PATCH] Optimize json_lex_string by batching character copying
Date: Thu, 25 Aug 2022 20:14:37 -0700
Message-ID: <20220826031437.GA1466128@nathanxps13> (raw)
In-Reply-To: <CAFBsxsFV4v802idV0-Bo=V7wLMHRbOZ4er0hgposhyGCikmVGA@mail.gmail.com>
References: <20220819204215.GA397534@nathanxps13>
<20220821054733.GA780295@nathanxps13>
<CAFBsxsH93DNy=x5Jiu37qFRyq==kz0fJbGjx835ZFyj-DMSXuw@mail.gmail.com>
<20220822212229.GA1129243@nathanxps13>
<20220823033236.GA1204962@nathanxps13>
<CAFBsxsEDR6GctRTayurcGyR6d3GDjv0XGBqArPvrbO3H38T6Jg@mail.gmail.com>
<20220823171546.GA1207981@nathanxps13>
<CAFBsxsHRJ0xxToXNxseBpt00jZZ2CqZW1sZ7-P82DRKp2_erKA@mail.gmail.com>
<20220824165603.GA1302810@nathanxps13>
<CAFBsxsFV4v802idV0-Bo=V7wLMHRbOZ4er0hgposhyGCikmVGA@mail.gmail.com>
On Thu, Aug 25, 2022 at 01:35:45PM +0700, John Naylor wrote:
> - For the following comment, pgindent will put spaced operands on a
> separate line which is not great for readability. and our other
> reference to the Stanford bithacks page keeps the in-page link, and I
> see no reason to exclude it -- if it goes missing, the whole page will
> still load. So I put back those two details.
>
> + * To find bytes <= c, we can use bitwise operations to find
> bytes < c+1,
> + * but it only works if c+1 <= 128 and if the highest bit in v
> is not set.
> + * Adapted from
> + * https://graphics.stanford.edu/~seander/bithacks.html#HasLessInWord
This was just unnecessary fiddling on my part, sorry about that.
> +test_lfind8_internal(uint8 key)
> +{
> + uint8 charbuf[LEN_WITH_TAIL(Vector8)];
> + const int len_no_tail = LEN_NO_TAIL(Vector8);
> + const int len_with_tail = LEN_WITH_TAIL(Vector8);
> +
> + memset(charbuf, 0xFF, len_with_tail);
> + /* search tail to test one-byte-at-a-time path */
> + charbuf[len_with_tail - 1] = key;
> + if (key > 0x00 && pg_lfind8(key - 1, charbuf, len_with_tail))
> + elog(ERROR, "pg_lfind8() found nonexistent element <= '0x%x'", key - 1);
> + if (key < 0xFF && !pg_lfind8(key, charbuf, len_with_tail))
> + elog(ERROR, "pg_lfind8() did not find existing element <= '0x%x'", key);
> + if (key < 0xFE && pg_lfind8(key + 1, charbuf, len_with_tail))
> + elog(ERROR, "pg_lfind8() found nonexistent element <= '0x%x'", key + 1);
> +
> + memset(charbuf, 0xFF, len_with_tail);
> + /* search with vector operations */
> + charbuf[len_no_tail - 1] = key;
> + if (key > 0x00 && pg_lfind8(key - 1, charbuf, len_no_tail))
> + elog(ERROR, "pg_lfind8() found nonexistent element <= '0x%x'", key - 1);
> + if (key < 0xFF && !pg_lfind8(key, charbuf, len_no_tail))
> + elog(ERROR, "pg_lfind8() did not find existing element <= '0x%x'", key);
> + if (key < 0xFE && pg_lfind8(key + 1, charbuf, len_no_tail))
> + elog(ERROR, "pg_lfind8() found nonexistent element <= '0x%x'", key + 1);
> +}
nitpick: Shouldn't the elog() calls use "==" instead of "<=" for this one?
Otherwise, 0001 looks good to me.
--
Nathan Bossart
Amazon Web Services: https://aws.amazon.com
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-hackers@postgresql.org
Cc: nathandbossart@gmail.com, john.naylor@enterprisedb.com, andres@anarazel.de, tgl@sss.pgh.pa.us, Jelte.Fennema@microsoft.com, mmoncure@gmail.com, andrew.dunstan@2ndquadrant.com, sfrost@snowman.net
Subject: Re: [PATCH] Optimize json_lex_string by batching character copying
In-Reply-To: <20220826031437.GA1466128@nathanxps13>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox