Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cache getSRSbySRID #557

Closed
wants to merge 3 commits into from
Closed

Conversation

Algunenano
Copy link
Member

Trac: https://trac.osgeo.org/postgis/ticket/4672

For ST_AsX3D remove it altogether since it was never part of the output (so no point on calculating it and passing through functions).

Measurements:

- 683788 Points (1 vertex on avg)
-- EXPLAIN ANALYZE Select ST_AsGML(the_geom, 8) from benchmark_7773a711c8441d4b494a51fd9feebeac7a9b9c734619398620293;
-- Latency avg before: 8286.371 ms
-- Latency avg with cache: 388.738 ms
-- Perf: 21.31x


-- EXPLAIN ANALYZE Select ST_AsX3D(the_geom, 8) from benchmark_7773a711c8441d4b494a51fd9feebeac7a9b9c734619398620293;
-- Latency avg before: 38299.269 ms
-- Latency avg with cache: 408.281 ms
-- Perf: 93.80x

-- EXPLAIN ANALYZE Select ST_AsGeoJSON(the_geom, 8, 2) from benchmark_7773a711c8441d4b494a51fd9feebeac7a9b9c734619398620293;
-- Latency avg before: 7720.442 ms
-- Latency avg with cache: 192.258 ms
-- Perf: 40.15x

It was never used and amounted to 90% of the time
@Algunenano
Copy link
Member Author

Since we are here, cache also getSRIDbySRS for a 40x in ST_GeomfromGeoJSON (or the equivalent '{}'::geometry):

-- On top of previous change
EXPLAIN ANALYZE Select ST_AsGeoJSON(the_geom, 8, 2)::geometry from benchmark_7773a711c8441d4b494a51fd9feebeac7a9b9c734619398620293;
-- Latency avg before: 32311.245 ms
-- Latency avg with cache: 738.984 ms
-- Perf: 43.72x


PG_FREE_IF_COPY(geom, 0);
PG_RETURN_TEXT_P(geojson);
PG_RETURN_TEXT_P(lwgeom_to_geojson(lwgeom, srs, precision, output_bbox));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lwgeom_free(lwgeom); ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably okay since we're just before leaving a function and context is going to die anyway, but I nervously rechecked it's in postgis/ and not lwgeom/.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Anything except index support functions you get the free "deallocation on exit".

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I've been doing this lately in multiple postgis functions (the ones were liblwgeom now returns a lwvarlena_t object). I think it keeps things cleaner and it's good for performance as it's faster to wait for the deallocation of the context.

@strk strk closed this in 07ca520 May 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants