As Lily Tomlin would say, neVERmind.
Simon P-J asked me, in email, whether the deforestation was the thing
that actually made the program faster or whether it was just the thing
that made me think about how to solve the problem. I realized that my
fast program had *another* difference from the earlier, slower program:
it was based on an algorithm that was specifically designed to clip
polygons to rectangles, whereas OGR just had a function to compute the
intersection between two arbitrary polygons.
So I threw together a version that accumulated all the vertices of the
clipped polygon in a list and then iterated through the list to compute
the centroid--i.e., preserving everything from my fast program except
the deforestation--and it ran at almost exactly the same speed as the
deforested program. (Actually, it ran 2% faster, but that could be just
random variation from things like the load on the database server.)
"The tragedy of science: a beautiful theory slain by an ugly fact."
"T. H. Huxley said it first."