{"action":"created","issue":{"url":"https://api.github.com/repos/mapnik/mapnik/issues/2937","labels_url":"https://api.github.com/repos/mapnik/mapnik/issues/2937/labels{/name}","comments_url":"https://api.github.com/repos/mapnik/mapnik/issues/2937/comments","events_url":"https://api.github.com/repos/mapnik/mapnik/issues/2937/events","html_url":"https://github.com/mapnik/mapnik/issues/2937","id":92229431,"number":2937,"title":"text-spacing causes 100% CPU usage and rendering never finishes","user":{"login":"pnorman","id":1190866,"avatar_url":"https://avatars.githubusercontent.com/u/1190866?v=3","gravatar_id":"","url":"https://api.github.com/users/pnorman","html_url":"https://github.com/pnorman","followers_url":"https://api.github.com/users/pnorman/followers","following_url":"https://api.github.com/users/pnorman/following{/other_user}","gists_url":"https://api.github.com/users/pnorman/gists{/gist_id}","starred_url":"https://api.github.com/users/pnorman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pnorman/subscriptions","organizations_url":"https://api.github.com/users/pnorman/orgs","repos_url":"https://api.github.com/users/pnorman/repos","events_url":"https://api.github.com/users/pnorman/events{/privacy}","received_events_url":"https://api.github.com/users/pnorman/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":{"url":"https://api.github.com/repos/mapnik/mapnik/milestones/15","html_url":"https://github.com/mapnik/mapnik/milestones/Mapnik%203.0.0","labels_url":"https://api.github.com/repos/mapnik/mapnik/milestones/15/labels","id":45615,"number":15,"title":"Mapnik 3.0.0","description":"Major new release.\r\n\r\nFirst release to leverage C++11 standard.\r\n","creator":{"login":"artemp","id":59056,"avatar_url":"https://avatars.githubusercontent.com/u/59056?v=3","gravatar_id":"","url":"https://api.github.com/users/artemp","html_url":"https://github.com/artemp","followers_url":"https://api.github.com/users/artemp/followers","following_url":"https://api.github.com/users/artemp/following{/other_user}","gists_url":"https://api.github.com/users/artemp/gists{/gist_id}","starred_url":"https://api.github.com/users/artemp/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/artemp/subscriptions","organizations_url":"https://api.github.com/users/artemp/orgs","repos_url":"https://api.github.com/users/artemp/repos","events_url":"https://api.github.com/users/artemp/events{/privacy}","received_events_url":"https://api.github.com/users/artemp/received_events","type":"User","site_admin":false},"open_issues":5,"closed_issues":365,"state":"open","created_at":"2011-10-11T15:50:50Z","updated_at":"2015-07-01T00:52:23Z","due_on":"2016-06-02T07:00:00Z","closed_at":null},"comments":6,"created_at":"2015-07-01T00:14:16Z","updated_at":"2015-07-01T01:55:42Z","closed_at":null,"body":"Adding `text-spacing: 400;` to [openstreetmap-carto admin text](https://github.com/gravitystorm/openstreetmap-carto/blob/master/admin.mss#L119-L127) causes Mapnik to take 100% CPU and never finish rendering.\r\n\r\nThe original MSS is\r\n```mss\r\n#admin-text[zoom >= 16] {\r\n  text-name: \"[name]\";\r\n  text-face-name: @book-fonts;\r\n  text-fill: @admin-boundaries;\r\n  text-halo-radius: 1.0;\r\n  text-halo-fill: rgba(255,255,255,0.6);\r\n  text-placement: line;\r\n  text-dy: -10;\r\n}\r\n```\r\n\r\nAdding `text-spacing: 400;` works fine in 2.2.0.\r\n\r\nIs my best approach of attack to profile to see where it's stuck, or work on the style side?\r\n"},"comment":{"url":"https://api.github.com/repos/mapnik/mapnik/issues/comments/117391183","html_url":"https://github.com/mapnik/mapnik/issues/2937#issuecomment-117391183","issue_url":"https://api.github.com/repos/mapnik/mapnik/issues/2937","id":117391183,"user":{"login":"pnorman","id":1190866,"avatar_url":"https://avatars.githubusercontent.com/u/1190866?v=3","gravatar_id":"","url":"https://api.github.com/users/pnorman","html_url":"https://github.com/pnorman","followers_url":"https://api.github.com/users/pnorman/followers","following_url":"https://api.github.com/users/pnorman/following{/other_user}","gists_url":"https://api.github.com/users/pnorman/gists{/gist_id}","starred_url":"https://api.github.com/users/pnorman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pnorman/subscriptions","organizations_url":"https://api.github.com/users/pnorman/orgs","repos_url":"https://api.github.com/users/pnorman/repos","events_url":"https://api.github.com/users/pnorman/events{/privacy}","received_events_url":"https://api.github.com/users/pnorman/received_events","type":"User","site_admin":false},"created_at":"2015-07-01T01:55:42Z","updated_at":"2015-07-01T01:55:42Z","body":"So, reducing this into a good testcase has proved illuminating, if unfruitful. Attempts to only get the geometries of what's visible with a `WHERE osm_id IN (...) ...` didn't work.\r\n\r\nThe spot I was looking at is on the edge of the Vancouver and UBC POLYGONs, and fairly deep within the GVRD, British Columbia, and Canada POLYGONs, the latter which may not exist for extract-related reasons.\r\n\r\nAfter some work, I got it reproducing with `WHERE osm_id = -390867`, which is [British Columbia](https://www.openstreetmap.org/relation/390867), a relation with about 20k points. At z16, the bounding box of the polygon has a perimeter of about 4 million pixels, and the actual length is longer.\r\n\r\n## What appears to be happening\r\n\r\nWhen a tile is requested the admin-text layer returns the BC polygon, being inside BC. With text-spacing it then goes to work computing something complex that does not finish in a reasonable time. Being in the middle of BC, not on the edge, this is then thrown away, so it never impacts the appearance of the rendered tiles.\r\n\r\n## What is causing it\r\n\r\nIn 2.2, text-clip was on, so the polygon was clipped down to a square, which would be simple to label. \r\n\r\n## Is this a bug?\r\nEither in Mapnik or the stylesheet. It is, at the very least, not obvious to me that adding text-spacing to a polygon can have a huge performance impact.\r\n\r\nThere exist workarounds\r\n\r\n* Turn on text-clip\r\n* For PostGIS data sources, do a WHERE check turning the polygon into a multilinestring and checking if it ST_Intersects the bounding box. This will exclude the polygon from the results except at edges"}}