diff options
author | John Naylor | 2022-08-26 08:01:24 +0000 |
---|---|---|
committer | John Naylor | 2022-08-26 08:48:49 +0000 |
commit | 121d2d3d70ecdb2113b340c5f3b99a61341291af (patch) | |
tree | 2fb2e21869ca777cb79a3a9282f0e5096ca409f6 /src/common/wchar.c | |
parent | ab9717847a2b0c32b93121f873f4dff331e26eb0 (diff) |
Use SSE2 in is_valid_ascii() where available.
Per flame graph from Jelte Fennema, COPY FROM ... USING BINARY shows
input validation taking at least 5% of the profile, so it's worth trying
to be more efficient here. With this change, validation of pure ASCII is
nearly 40% faster on contemporary Intel hardware. To make this change
legible and easier to adopt to additional architectures, use helper
functions to abstract the platform details away.
Reviewed by Nathan Bossart
Discussion: https://www.postgresql.org/message-id/CAFBsxsG%3Dk8t%3DC457FXnoBXb%3D8iA4OaZkbFogFMachWif7mNnww%40mail.gmail.com
Diffstat (limited to 'src/common/wchar.c')
-rw-r--r-- | src/common/wchar.c | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/src/common/wchar.c b/src/common/wchar.c index 1e6e198bf27..fa8854d9e9f 100644 --- a/src/common/wchar.c +++ b/src/common/wchar.c @@ -1919,10 +1919,11 @@ pg_utf8_verifystr(const unsigned char *s, int len) uint32 state = BGN; /* - * Sixteen seems to give the best balance of performance across different - * byte distributions. + * With a stride of two vector widths, gcc will unroll the loop. Even if + * the compiler can unroll a longer loop, it's not worth it because we + * must fall back to the byte-wise algorithm if we find any non-ASCII. */ -#define STRIDE_LENGTH 16 +#define STRIDE_LENGTH (2 * sizeof(Vector8)) if (len >= STRIDE_LENGTH) { |