22 Jul 2010 01:27
Optimizations around Mapnik's projection code
Recently I noticed the large number of:
#ifdef MAPNIK_THREADSAFE
mutex::scoped_lock lock(mutex_);
#endif
wrapping the proj4 code in proj_transform.cpp and projections.cpp.
Proj4 has thread safety issues so this makes sense:
1) Projection initialization in not thread safe (when creating from epsg code)
2) Usage of prj_errno is not thread safe (error code pointer)
3) in rarer cases pj_transform is also not threadsafe (when transforming coordinates)
My thoughts were:
#1 As of proj 4.7 locking is done by proj4, so no need to duplicate locking in mapnik as far as I can tell
#2 is not a problem currently for mapnik because we don't attempt to do anything with errors (but we may in the
future - http://trac.mapnik.org/wiki/BoundsClipping)
#3 - can't do much about this.
So, I set out to deal with #1 and noticed a few more things:
1) there is a lock that affects proj_transform, even if we exit early because we don't need to reproject
(source == dest). What this means is that even when proj4 is not used, since we call proj_transform we're
hitting a lock for every coordinate reprojected
(http://trac.mapnik.org/browser/trunk/src/proj_transform.cpp?rev=2062#L74). Ouch.
(Continue reading)
RSS Feed