Prev | Current Page 237 | Next

Brad Ediger

"Advanced Rails"

Tracing upward through the call stack
160 | Chapter 6: Performance
end
# Invalidate cache when new location is assigned
def location=(val)
@location_geometry = @location_string = nil
super
end
# Invalidate cache when record is reloaded
def reload
@location_geometry = @location_string = nil
super
end
end
Now that we have made a substantial change, it is time to reprofile and see how the
numbers compare. After running the profiler again, we see that we have managed to
push that method a few notches down the list:
Thread ID: 2057980
Total: 11.21
%self total self wait child calls name
8.56 1.38 0.96 0.00 0.42 4430 Array#each_index
7.76 2.07 0.87 0.00 1.20 4230 Array#each-1
4.19 0.74 0.47 0.00 0.27 1040 GeoRuby::SimpleFeatures::
HexEWKBParser#decode_hex
We have cut the number of calls to decode_hex from 2,730 to 1,040. (This number is
still higher than 100 because there is another spatial class that we have not optimized
yet.) In addition, we have cut the total time spent in decode_hex from 1.26 seconds
to 0.47 seconds without optimizing the actual function at all. When we
benchmark these different versions of the application, we will see what kind of an
impact the optimizations have on the action as a whole.
Next, we notice from the preceding flat profile that we are spending the most time in
Array#each_index and Array#each-1 (the ruby-prof syntax indicating the first-level
recursive call to Array#each).


Pages:
225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249