Ticket #1749 (closed bug: fixed)
readall method on open FileHandle is inefficient
|Reported by:||pmichaud||Owned by:|
Using readall on an open filehandle appears to be extremely inefficient. Some simple tests reading a 10,000 line file can end up taking several seconds to complete. Notably, reading the filehandle line-at-a-time via 'read' is far more efficient than 'readall'.
Looking at the filehandle.pmc code, it appears that 'readall' turns on line buffering on the input filehandle, and then does successive string concatenations to produce the resulting string. That involves a lot of string allocations, iiuc, which is probably part of the slowness.
I'm not sure why it chooses to use line buffering -- it seems like some other strategy would be far more efficient.