From: | John Naylor <john(dot)naylor(at)postgresql(dot)org> |
---|---|
To: | pgsql-committers(at)lists(dot)postgresql(dot)org |
Subject: | pgsql: Add fast path for validating UTF-8 text |
Date: | 2021-12-20 14:10:07 |
Message-ID: | E1mzJMd-0007LH-5j@gemulon.postgresql.org |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-committers |
Add fast path for validating UTF-8 text
Our previous validator used a traditional algorithm that performed
comparison and branching one byte at a time. It's useful in that
we always know exactly how many bytes we have validated, but that
precision comes at a cost. Input validation can show up prominently
in profiles of COPY FROM, and future improvements to COPY FROM such
as parallelism or faster line parsing will put more pressure on input
validation. Hence, add fast paths for both ASCII and multibyte UTF-8:
Use bitwise operations to check 16 bytes at a time for ASCII. If
that fails, use a "shift-based" DFA on those bytes to handle the
general case, including multibyte. These paths are relatively free
of branches and thus robust against all kinds of byte patterns. With
these algorithms, UTF-8 validation is several times faster, depending
on platform and the input byte distribution.
The previous coding in pg_utf8_verifystr() is retained for short
strings and for when the fast path returns an error.
Review, performance testing, and additional hacking by: Heikki
Linakangas, Vladimir Sitnikov, Amit Khandekar, Thomas Munro, and
Greg Stark
Branch
------
master
Details
-------
https://git.postgresql.org/pg/commitdiff/911588a3f816d875261d8f7d89e2517978831cd5
Modified Files
--------------
src/common/wchar.c | 215 +++++++++++++++++++++++++++++++
src/include/mb/pg_wchar.h | 53 ++++++++
src/test/regress/expected/conversion.out | 169 ++++++++++++++++++++++++
src/test/regress/sql/conversion.sql | 133 +++++++++++++++++++
4 files changed, 570 insertions(+)
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2021-12-20 19:16:05 | pgsql: Add a \getenv command to psql. |
Previous Message | Peter Eisentraut | 2021-12-20 10:22:01 | pgsql: pg_dump: Refactor getIndexes() |