Opened 8 years ago

Closed 8 years ago

Last modified 8 years ago

#28024 closed Cleanup/optimization (fixed)

GEOSCoordSeq performance could be improved significantly by avoiding superfluous checks

Reported by: Sergey Fedoseev Owned by: Sergey Fedoseev
Component: GIS Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

For proof of concept I added reworked tuple version as tuple_fast property.

In [14]: ls = LineString([(x, x) for x in range(1000)])

In [15]: %timeit ls.tuple
10 loops, best of 3: 43.5 ms per loop

In [16]: %timeit ls.tuple_fast
10 loops, best of 3: 16.8 ms per loop

Change History (10)

comment:1 by Sergey Fedoseev, 8 years ago

Owner: changed from nobody to Sergey Fedoseev
Status: newassigned

comment:2 by Tim Graham, 8 years ago

Triage Stage: UnreviewedAccepted

comment:3 by Sergey Fedoseev, 8 years ago

Has patch: set

PR

Here's benchmarks:

python -mtimeit -s "from django.contrib.gis.geos import LineString as LS; ls = LineString([(x, x) for x in range(1000)])" "ls.tuple"
42.3 msec => 15.2 msec per loop

python -mtimeit -s "from django.contrib.gis.geos import LineString; ls = LineString((0, 0), (1, 1))" "ls[0]"
51.7 usec => 42.4 usec per loop

python -mtimeit -s "from django.contrib.gis.geos import LineString; ls = LineString((0, 0), (1, 1))" "ls[0] = (0, 0)"
62.4 usec => 51.4 usec per loop

Last edited 8 years ago by Sergey Fedoseev (previous) (diff)

comment:4 by Tim Graham, 8 years ago

Triage Stage: AcceptedReady for checkin

comment:5 by Tim Graham <timograham@…>, 8 years ago

In d453dfb1:

Refs #28024 -- Optimized GEOSCoordSeq.tuple by avoiding superfluous index and dimension checks.

comment:6 by Tim Graham <timograham@…>, 8 years ago

In a296a433:

Refs #28024 -- Optimized GEOSCoordSeq.getitem() by avoiding superfluous index and dimension checks.

comment:7 by Tim Graham <timograham@…>, 8 years ago

In ebaa08b3:

Refs #28024 -- Optimized GEOSCoordSeq.setitem() by avoiding superfluous index and dimension checks.

comment:8 by Tim Graham, 8 years ago

Resolution: fixed
Status: assignedclosed

comment:9 by Sergey Fedoseev, 8 years ago

Another related PR for LineString.__init__() optimization.
Benchmark:
python -mtimeit -s "from django.contrib.gis.geos import LineString" "LineString([(x, x) for x in range(1000)])"
31.4 msec => 13.3 msec per loop

Last edited 8 years ago by Sergey Fedoseev (previous) (diff)

comment:10 by Sergey Fedoseev <fedoseev.sergey@…>, 8 years ago

In 6d5bb6a:

Refs #28024 -- Optimized LineString.init() by avoiding superfluous index and dimension checks.

Note: See TracTickets for help on using tickets.
Back to Top