Buffered output to a file is painfully slow

chromatic chromatic at wgz.org
Mon Feb 9 18:11:02 UTC 2009


On Monday 09 February 2009 07:58:14 Patrick R. Michaud wrote:

> Comments and suggestions welcomed,

I wanted to measure the overhead of the calls to the FileHandle PMC's puts() 
method, so I changed the relevant ops (print_p_i and print_p_sc) to call 
Parrot_io_write_buffer() directly.  The benchmark runs over five times faster.

The culprit, as usual, is that converting between C calling conventions and 
Parrot's calling conventions is slow.  The unmodified benchmark generates 
3,049,533 new PMCs.  The modified benchmark generates 2,655 new PMCs.  For 
reference, "Hello, world!" in PIR generates 1,454 new PMCs.

That's 2539 times the amount of rapidly churned garbage, just for the 
privilege of writing a PMC's method in C.

(The problem isn't in the garbage collector, however.  The GC runs 454 times 
for the modified benchmark and 2793 times for the unmodified benchmark -- only 
6.5 times more for the slow benchmark, despite there being 2500 times more 
garbage to collect.  This benchmark is actually really easy on the GC, because 
it's a tight loop where almost everything is garbage -- walking the anchored 
set is easy because it's *tiny*.)

-- c


More information about the parrot-dev mailing list