Pack struct ParsedWord more tightly.

In a 64-bit build there's an awful lot of useless pad space in
ParsedWords.  Since we may allocate large arrays of these,
it's worth some effort to reduce their size.

Here we reduce the alen field from uint32 to uint16, and then re-order
the fields to avoid unnecessary padding.  alen is only used to
remember the allocated size of the apos[] array, which is not allowed
to exceed MAXNUMPOS (256) elements, so uint16 is plenty of space for
it.  That gets us from 40 bytes to 24 on 64-bit builds, and from 20
bytes to 16 on 32-bit builds.

Per discussion of bug #18080.  Unfortunately this is an ABI break
so we can't back-patch.

Discussion: https://postgr.es/m/1146921.1695411070@sss.pgh.pa.us
pull/144/head
Tom Lane 2 years ago
parent cf1c65070a
commit 036297cf1b
  1. 6
      src/include/tsearch/ts_utils.h

@ -81,8 +81,10 @@ extern void pushOperator(TSQueryParserState state, int8 oper, int16 distance);
*/
typedef struct
{
uint16 flags; /* currently, only TSL_PREFIX */
uint16 len;
uint16 nvariant;
uint16 alen;
union
{
uint16 pos;
@ -90,13 +92,11 @@ typedef struct
/*
* When apos array is used, apos[0] is the number of elements in the
* array (excluding apos[0]), and alen is the allocated size of the
* array.
* array. We do not allow more than MAXNUMPOS array elements.
*/
uint16 *apos;
} pos;
uint16 flags; /* currently, only TSL_PREFIX */
char *word;
uint32 alen;
} ParsedWord;
typedef struct

Loading…
Cancel
Save