33 0.00 0.05 77550 String#gsub
Most of these values are fairly reasonable (we are doing a lot of necessary data processing
in Ruby, and it is reasonable that Array#each_index would be a significant
component of this). However, we are spending a lot of time in GeoRuby::
SimpleFeatures::HexEWKBParser#decode_hex. The %Self value of 9.93 means that we are
spending nearly 10% of the total request time inside this method. We should investigate
this by looking for that method??™s block in the graph profile (see Figure 6-3).
Figure 6-3. The decode_hex method dominates our request time
Rails Optimization Example | 159
Now, we may want to examine the source of these calls to decode_hex. This function
has only one caller, HexEWKBParser#parse. Clicking on that line takes us to its own
block (see Figure 6-4).
Following this chain of callers upward, we find that these calls are coming from the
spatial_adapter plugin that we use to interface with the PostGIS database. These
functions are doing a particularly computationally intensive form of type casting;
they are converting the hex strings coming from PostGIS to Ruby objects such as
points and polygons (EWKB is the extended well-known binary format that PostGIS
uses to represent geometrical objects).
The decode_hex function is pure Ruby. It could probably be rewritten with C,
OCaml, or another high-performance extension language, which would likely
improve performance substantially.
Pages:
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247