From: Jacob Champion <pchampion@vmware.com>
To: john.naylor@enterprisedb.com <john.naylor@enterprisedb.com>
To: michael@paquier.xyz <michael@paquier.xyz>
Cc: peter.eisentraut@enterprisedb.com <peter.eisentraut@enterprisedb.com>
Cc: pavel.stehule@gmail.com <pavel.stehule@gmail.com>
Cc: laurenz.albe@cybertec.at <laurenz.albe@cybertec.at>
Cc: pgsql-hackers@postgresql.org <pgsql-hackers@postgresql.org>
Cc: horikyota.ntt@gmail.com <horikyota.ntt@gmail.com>
Subject: Re: badly calculated width of emoji in psql
Date: Fri, 20 Aug 2021 00:05:19 +0000
Message-ID: <39db2e88a680c5c0c113eb1977db90fa19f97155.camel@vmware.com> (raw)
In-Reply-To: <CAFBsxsEX8+K4fvvUEJYTqbhpj9ENenWwYm9SrMXZ1P2cPG8P+Q@mail.gmail.com>
References: <9e3c847108bac6041f50e86d08d8835f5cf7cd78.camel@vmware.com>
<YPUtzT0J8cZByTkD@paquier.xyz>
<f6a06ecdf378b50ed871e363aa9ac7e706101ab6.camel@cybertec.at>
<c2a556a0158b642d6c597508d2a47059091e4d56.camel@vmware.com>
<2f7ca10c7847f69267685beca7b5aa92dd876259.camel@vmware.com>
<CAFj8pRCuaHgxa8M_FxmhGDg46qWp4yF-Xz_Xkj5NZT-F9fkQ1w@mail.gmail.com>
<CAFBsxsEW0oAD2gdWQ9OQ8dS52iz476kWK2pqV1xmGuVjaygZTA@mail.gmail.com>
<bedc833c3f60bbcd72ce613fc6a677be609d19dd.camel@vmware.com>
<CAFBsxsGZTwzDnTs=TVM38CCTPP3Y0D3=h+UiWt8M83D5THHf9A@mail.gmail.com>
<CAFBsxsFQ=scF=hgvrUWwDBzf1ZSkdmq1XRN4NJPMtniqNfpBCQ@mail.gmail.com>
<YRnRFIe5ycU3GYaX@paquier.xyz>
<CAFBsxsG39ZQNKDQpE3Yu6rytemsCk8naJ9ib=WyiSUia24_3qw@mail.gmail.com>
<CAFBsxsEX8+K4fvvUEJYTqbhpj9ENenWwYm9SrMXZ1P2cPG8P+Q@mail.gmail.com>
On Thu, 2021-08-19 at 13:49 -0400, John Naylor wrote:
> I had a couple further thoughts:
>
> 1. The coding historically used normal comparison and branching for
> everything, but recently it only does that to detect control
> characters, and then goes through a binary search (and with this
> patch, two binary searches) for everything else. Although the
> performance regression of the current patch seems negligible,
If I'm reading the code correctly, ASCII characters don't go through
the binary searches; they're already short-circuited at the beginning
of mbbisearch(). On my machine that's enough for the patch to be a
performance _improvement_ for ASCII, not a regression.
Does adding another short-circuit at the top improve the
microbenchmarks noticeably? I assumed the compiler had pretty well
optimized all that already.
> we could use almost the same branches to fast-path printable ascii
> text, like this:
>
> + /* fast path for printable ASCII characters */
> + if (ucs >= 0x20 || ucs < 0x7f)
> + return 1;
Should be && instead of ||, I think.
> +
> /* test for 8-bit control characters */
> if (ucs == 0)
> return 0;
>
> - if (ucs < 0x20 || (ucs >= 0x7f && ucs < 0xa0) || ucs > 0x0010ffff)
> + if (ucs < 0xa0 || ucs > 0x0010ffff)
> return -1;
>
> 2. As written, the patch adds a script that's very close to an
> existing one, and emits a new file that has the same type of contents
> as an existing one, both of which are #included in one place. I
> wonder if we should consider having just one script that ingests both
> files and emits one file. All we need is for mbinterval to encode the
> character width, but we can probably do that with a bitfield like the
> normprops table to save space. Then, we only do one binary search.
> Opinions?
I guess it just depends on what the end result looks/performs like.
We'd save seven hops or so in the worst case?
--Jacob
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 from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-hackers@postgresql.org
Cc: pchampion@vmware.com, john.naylor@enterprisedb.com, michael@paquier.xyz, peter.eisentraut@enterprisedb.com, pavel.stehule@gmail.com, laurenz.albe@cybertec.at, horikyota.ntt@gmail.com
Subject: Re: badly calculated width of emoji in psql
In-Reply-To: <39db2e88a680c5c0c113eb1977db90fa19f97155.camel@vmware.com>
References: <9e3c847108bac6041f50e86d08d8835f5cf7cd78.camel@vmware.com> <YPUtzT0J8cZByTkD@paquier.xyz> <f6a06ecdf378b50ed871e363aa9ac7e706101ab6.camel@cybertec.at> <c2a556a0158b642d6c597508d2a47059091e4d56.camel@vmware.com> <2f7ca10c7847f69267685beca7b5aa92dd876259.camel@vmware.com> <CAFj8pRCuaHgxa8M_FxmhGDg46qWp4yF-Xz_Xkj5NZT-F9fkQ1w@mail.gmail.com> <CAFBsxsEW0oAD2gdWQ9OQ8dS52iz476kWK2pqV1xmGuVjaygZTA@mail.gmail.com> <bedc833c3f60bbcd72ce613fc6a677be609d19dd.camel@vmware.com> <CAFBsxsGZTwzDnTs=TVM38CCTPP3Y0D3=h+UiWt8M83D5THHf9A@mail.gmail.com> <CAFBsxsFQ=scF=hgvrUWwDBzf1ZSkdmq1XRN4NJPMtniqNfpBCQ@mail.gmail.com> <YRnRFIe5ycU3GYaX@paquier.xyz> <CAFBsxsG39ZQNKDQpE3Yu6rytemsCk8naJ9ib=WyiSUia24_3qw@mail.gmail.com> <CAFBsxsEX8+K4fvvUEJYTqbhpj9ENenWwYm9SrMXZ1P2cPG8P+Q@mail.gmail.com> <39db2e88a680c5c0c113eb1977db90fa19f97155.camel@vmware.com>
* 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