[postgis-tickets] [PostGIS] #4264: Consider dropping pfree calls in liblwgeom

PostGIS trac at osgeo.org
Mon Dec 3 01:25:54 PST 2018


#4264: Consider dropping pfree calls in liblwgeom
-------------------------+---------------------------
 Reporter:  Algunenano   |      Owner:  Algunenano
     Type:  enhancement  |     Status:  assigned
 Priority:  medium       |  Milestone:  PostGIS 3.0.0
Component:  postgis      |    Version:  trunk
 Keywords:               |
-------------------------+---------------------------
 Recently I became aware that Postgresql deletes the memory context per
 tuple, not per function. With that in mind, it doesn't make sense for the
 library to be calling pfree since waiting it's going to wait until the
 memory context is freed anyway.


 Rough Patch:
 {{{
 diff --git a/libpgcommon/lwgeom_pg.c b/libpgcommon/lwgeom_pg.c
 index 1ee41f0cb..2733d3cbe 100644
 --- a/libpgcommon/lwgeom_pg.c
 +++ b/libpgcommon/lwgeom_pg.c
 @@ -113,7 +113,7 @@ pg_realloc(void *mem, size_t size)
  static void
  pg_free(void *ptr)
  {
 -  pfree(ptr);
 +  //  pfree(ptr);
  }
 }}}

 I decided to test this patch to generate polygon MVTs, and I see a 5-10%
 improvement in the slowest cases (the ones that do the whole process).

 3 main thoughts:
 - Check that there isn't any function is requesting a lot of memory. This
 might mean redesigning some functions (none come to mind) to avoid
 allocating in a loop or recursively, but that by itself is a win.
 - Check that it's only applied to liblwgeom when working as a library, and
 not to external libraries (GEOS, PROJ, etc.): I think this is already
 true, but I have to make sure.
 - I don't intend to apply this to the extensions code itself (yet).


 Any comments are very welcome.

-- 
Ticket URL: <https://trac.osgeo.org/postgis/ticket/4264>
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