[postgis-tickets] [PostGIS] #4368: Reorder struct layouts to minimize padding
PostGIS
trac at osgeo.org
Mon Apr 8 09:39:10 PDT 2019
#4368: Reorder struct layouts to minimize padding
-------------------------+---------------------------
Reporter: Algunenano | Owner: Algunenano
Type: enhancement | Status: assigned
Priority: medium | Milestone: PostGIS 3.0.0
Component: postgis | Version: trunk
Keywords: |
-------------------------+---------------------------
The current LWGEOM structs have too much padding which makes them bigger
than what they could be.
For example, currently they look like this:
{{{
typedef struct
{
uint8_t type;
uint8_t flags;
GBOX *bbox;
int32_t srid;
void *data;
}
LWGEOM;
}}}
When you build them in a 64 bit machine which I'm considering the default,
the struct looks like this:
{{{
{
uint8_t type; /* 1 byte */
uint8_t flags; /* 1 byte */
/* 6 bytes padding */
GBOX *bbox; /* 8 bytes */
int32_t srid; /* 4 bytes */
/* 4 bytes padding */
void *data; /* 8 bytes */
}
}}}
For a total of 32 bytes.
I'm proposing to use this instead:
{{{
{
GBOX *bbox; /* 8 bytes */
void *data; /* 8 bytes */
int32_t srid; /* 4 bytes */
uint8_t type; /* 1 byte */
uint8_t flags; /* 1 byte */
char pad[2]; /* 2 bytes of padding */
}
}}}
So the new way uses 24 bytes instead (25% less). I expect this to have a
impact in big multigeometries as it reduces their memory footprint which
should improve performance. OTOH, I want to test it first as changing the
position of certain elements might be harmful in certain scenarios.
--
Ticket URL: <https://trac.osgeo.org/postgis/ticket/4368>
PostGIS <http://trac.osgeo.org/postgis/>
The PostGIS Trac is used for bug, enhancement & task tracking, a user and developer wiki, and a view into the subversion code repository of PostGIS project.
More information about the postgis-tickets
mailing list