[geos-devel] Ability to preallocate the WKT stringstream buffer for really large geometries?
Mats Taraldsvik
mats.taraldsvik at norkart.no
Thu Feb 21 01:22:36 PST 2013
I have now submitted pull requests for bug #310 and increased performance and preallocation on github, ready for review:
https://github.com/libgeos/libgeos/pull/5
https://github.com/libgeos/libgeos/pull/4
Locally, I have modified the WKTWriter::writeNumber(double d) method to use boost::spirit::karma::real_generator for conversion of numbers, instead of std::stringstream. This improves writing WKT by 6x-10x on my datasets (tested with linestrings with up to 10000 points). This change *is not* part of the patch for two reasons:
- I don't know whether you want to introduce a dependency on boost::spirit::karma, although it is header-only, so it might not be a large barrier.
- The precision and fixed notation parametres are changed by using policies, essentially structs with static methods that return the precision, trailing_zeros etc. I might be incorrect, but I would have to make policies (structs) for every combination of fixed and decimalPlaces and determine at runtime which of them to use, to make the approach suitable for GEOS. This is easily done, but I don't know if you think it is worth it?
Vennlig hilsen
Mats Taraldsvik
+47 901 65 934
> -----Opprinnelig melding-----
> Fra: Sandro Santilli [mailto:sandro.santilli at gmail.com] På vegne av Sandro
> Santilli
> Sendt: 8. februar 2013 13:28
> Til: Mats Taraldsvik
> Kopi: GEOS Development List
> Emne: Re: [geos-devel] Ability to preallocate the WKT stringstream buffer for
> really large geometries?
>
> On Fri, Feb 08, 2013 at 07:22:21AM +0000, Mats Taraldsvik wrote:
>
> > Have you considered this issue? Do you accept patches to solve this by
> > changing the interface (considering GEOS is a port of JTS and follows
> > it closely)? :)
>
> I'll be glad to review and apply any patch speeding up WKT writing.
> I'm fine with providing an enhanced interface for 3.4.x series, as long as the
> old one remains for backward API compatibility.
>
> If you start with that please consider taking a look at
> http://trac.osgeo.org/geos/ticket/355 and
> http://trac.osgeo.org/geos/ticket/310
>
> Please also make sure the testsuite covers enough cases.
>
> Thank you !
>
> --strk;
>
> > Regards
> >
> > Mats Taraldsvik
> >
> > > -----Opprinnelig melding-----
> > > Fra: geos-devel-bounces at lists.osgeo.org [mailto:geos-devel-
> > > bounces at lists.osgeo.org] På vegne av Mats Taraldsvik
> > > Sendt: 18. januar 2013 12:53
> > > Til: geos-devel at lists.osgeo.org
> > > Emne: [geos-devel] Ability to preallocate the WKT stringstream
> > > buffer for really large geometries?
> > >
> > > Hi,
> > >
> > > Generally, I'm very satisfied with the WKTWriter, which is really
> > > easy to use, and converts the Geometries to the WKT format. However,
> > > when converting _large_ geometries (in this case, contour lines), I
> > > get a major decrease in performance.
> > >
> > > By looking at the source code (and profiling), I believe the use of
> > > a stringstream and hence a dynamically increasing string buffer,
> > > constantly reallocating, is causing the performance penalty.
> > > Possibly also copying the large string.
> > >
> > > Is there anything I can do to improve this scenario? Do you accept
> > > contributions to fix this (e.g. passing in the expected size of the
> > > resulting WKT string)?
> > >
> > > Regards
More information about the geos-devel
mailing list