euske/pdfminer — pull request #16 by jcushman (2012-06-22 21:24:53+00:00)
Title: 2x faster group_textboxes function.

This patch optimizes the line that (after my other pull request) was taking the most time when getting a layout. It changes two things:

- Using "n for n in dists" instead of "(c,d,obj1,obj2) for (c,d,obj1,obj2) in dists" avoids a lot of copying.
- Using "in plane._objs" instead of "plane" is ugly, but avoids a weirdly slow layer of indirection.

I tried a bunch of other optimizations for this line -- filter(), "for" loop and temp variable, set(n[2],n[3]) <= plane, etc. -- and this was the fastest, but someone else might be able to find something better. The result is really good, though. On my system, analyzing a complex page went from 10 seconds to 5 seconds total.

(Note: the time to analyze that page was 25 seconds before applying my other patch. So if you apply both patches, get_layout should go roughly five times as fast as it did before. I'm curious whether other people get the same results.)