Algorithm taking way too long when precision is disproportionately small
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 1.6k
- Forks
- 163
- PR merge metrics
- No merged PRs in 30d
Description
The algorithm either takes way too long to calculate the label of rectangular shapes or it runs out of memory while doing so.
I am using Polylabel to calculate the POI of GeoJSON features, from Openstreetmap.
Examples of such shapes include:
https://www.openstreetmap.org/relation/2730170
https://www.openstreetmap.org/relation/153548
https://www.openstreetmap.org/relation/12863380
https://www.openstreetmap.org/relation/7491995
https://www.openstreetmap.org/relation/7585771
https://www.openstreetmap.org/relation/7717839
The precision I'm using is 0.000001, since many times the shape is minuscule which requires high precision.
I also changed the code to change the precision according to the size of the shape(parseInt(inputFeature.properties.admin_level) <= 10 ? 0.0000475 : precision), but the fact there is an OOM error indicates a memory leak, which should be fixed.
I understand it taking longer due to the high precision, but when it runs out of memory to calculate the center of a square shape then it doesn't make sense.
The command I'm using is:
geojson-polygon-labels --precision=0.000001 --label=polylabel --style=largest example.geojson > labels.geojson

Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the issue with the geojson-polygon-labels command, --precision=0.000001, and the listed OpenStreetMap examples. Start by tracing the polylabel calculation and how rectangular GeoJSON features are processed; compare runtime and memory usage at different precisions. Done means the examples complete without exhausting memory and the performance behavior is covered by an appropriate regression check.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- performance
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100