PHPExcel_Worksheet->garbageCollect performance

Oct 2, 2008 at 4:07 PM

Hello, I have a script whose job is to read excel file, insert some data and write the resulting excel file using PHPExcel. 

I did some profiling using XDebug and find out that for my worksheet(32 columns, 288 rows) there are ~ 400 000 calls of various getHashCode() methods, a lot of them are from PHPExcel_Worksheet->garbageCollect(). Just inserting "return" in the first line of PHPExcel_Worksheet->garbageCollect() let the script run 2-3 times faster, without any visible impact on result. 

What is this method for, is it important? 

Developer
Oct 3, 2008 at 3:04 AM
What does your profiling say about memory usage? I think memory might get exhausted if you eliminate those statements. But I'm not sure. I'm not really into that part of the code.
Coordinator
Oct 3, 2008 at 7:22 AM
The garbage collect method is not that important, but removing it might indeed lead to higher memory usage and eventually Excel documents with too much data like unused style information and such.
Oct 3, 2008 at 8:04 AM
Edited Oct 3, 2008 at 8:26 AM

Te code is

echo date('H:i:s')."<br>";

$objReader = PHPExcel_IOFactory::createReader('Excel2007');
$objPHPExcel = $objReader->load("holton-anketa2.xlsx");

$objPHPExcel->setActiveSheetIndex(0);
$objPHPExcel->getActiveSheet()->setCellValue('F11', '123');

echo date('H:i:s') . " Write to Excel2007 format\n";

$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$objWriter->save('ha.xlsx');

echo date('H:i:s') . " Peak memory usage: " . (memory_get_peak_usage(true) / 1024 / 1024) . " MB\r\n";

Results:


Stylesheet 1 (32x288, xlsx->xlsx, 1 image, some border styling)

Garbage collector disabled: read - 6s, write -15s, memory - 53.25 MB

Garbage collector enabled: read - 13s, write - 49s, memory -53.25 MB


Stylesheet 2 (52x55, xls->xlsx, 1 image, some border and bg color styling)

Garbage collector disabled: read - 2s, write -6s, memory - 35 MB

Garbage collector enabled: read - 2s, write - 18s, memory -35 MB


Stylesheet 2 (52x55, xls->xls, 1 image, some border and bg color styling)

Garbage collector disabled: read - 2s, write - 4s, memory - 35.75 MB

Garbage collector enabled: read - 2s, write - 8s, memory -35.75 MB


If other profiling results are similar, I think it will be good to make garbageCollect() optional, and maybe in default "disabled" state.