Opened 15 months ago

Closed 12 months ago

Last modified 12 months ago

#4623 closed enhancement (fixed)

Optimize functions returning a varlena buffer

Reported by: Algunenano Owned by: Algunenano
Priority: medium Milestone: PostGIS 3.1.0
Component: postgis Version: master
Keywords: Cc:


LWGEOM_asBinary calls lwgeom_to_wkb which does the task to serialize the geometry in the WKB format and then, to be able to output it as a datum, it needs to allocate another buffer and copy all the information there.

I think this could benefit from a small change in lwgeom_to_wkb to return a Datum / varlena (or an equivalent liblwgeom type) directly. We already have SIZE_SET and SIZE_GET for gserialized operations and they could be reused here.

This would only make sense if there was a noticeable impact in performance, which is what I intend to investigate in this issue.

Change History (6)

comment:1 Changed 15 months ago by Algunenano

A similar thing happens in the functions that output from a stringbuffer (ST_AsText, ST_AsKML...): the string is generated in the stringbuffer, copied for output and then copied again in cstring_to_text (which also calls strlen on the whole string, even though we already know its size).

comment:2 Changed 15 months ago by Algunenano

WIP with just ST_AsGeoJSON in

comment:3 Changed 14 months ago by Algunenano

Summary: Optimize ST_AsBinaryOptimize functions returning a varlena buffer

comment:4 Changed 12 months ago by Algunenano

Full benchmarks in the PR ( but the summary:

  • ST_AsText, ST_AsGeoJSON, ST_AsTWKB: 1-3% improvement
  • ST_AsBinary and variants: 6-22% improvement
  • ST_AsX3D, ST_AsEncodedPolyline: 3% improvement
  • ST_AsGML: 0-7% improvement
  • ST_AsSVG: 3-7% improvement

comment:5 Changed 12 months ago by Raúl Marín <git@…>

Resolution: fixed
Status: assignedclosed

In 0696fa46/git:

Optimize varlena returning functions

Closes #4623

comment:6 Changed 12 months ago by Raúl Marín <git@…>

In 591d0c6/git:

Revert incorrect "Optimize varlena returning functions"

This reverts commit 0696fa46699875fe43708d78602244fd6f257ee4.

I'm not sure what I did there, it seems like I pushed smaller commits
instead of a squashed one, and then did a revert that undid everything.

References #4623

Note: See TracTickets for help on using tickets.