-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Memory issue #29
Comments
I try on linux too same result
env
|
The bug actually comes from |
This would be my approach to fix it: indy2kro@9115d66 |
This help for big file, but the memory issue is still present Without gc_collect_cycles(); (output_tests_without_gc.csv With gc_collect_cycles(); (output_tests.csv) This is my new tests file using tests file from the repo <?php
require 'vendor/autoload.php';
use lsolesen\pel\PelJpeg;
function bytes($size) {
$unit = [
'b',
'kb',
'mb',
'gb',
'tb',
'pb'
];
return @round($size / pow(1024, ($i = floor(log($size, 1024)))), 2) . ' ' . $unit[$i];
}
$files = glob("vendor/fileeye/pel/test/imagetests/*.jpg");
$csv = fopen('output_tests.csv', 'w');
for($i = 0; $i <= 100; $i++) {
echo "Pass: " . $i . PHP_EOL;
foreach($files as $imagePath) {
//echo "Processing file: " . $imagePath . PHP_EOL;
try {
// Load the JPEG file
$jpeg = new PelJpeg($imagePath);
gc_collect_cycles();
} catch(Exception $e) {
echo 'Error: ' . $e->getMessage() . PHP_EOL;
}
fputcsv($csv, [
$i,
microtime(true),
basename($imagePath),
memory_get_usage(),
memory_get_peak_usage()
]);
}
}
printf("MEM: %s\nPEAK: %s\n", bytes(memory_get_usage()), bytes(memory_get_peak_usage()));
// Save the CSV data
if(!empty($csvData)) {
fputcsv($csv, $csvData);
}
fclose($csv); I also do a test with a file_get_contents: <?php
require 'vendor/autoload.php';
function bytes($size) {
$unit = [
'b',
'kb',
'mb',
'gb',
'tb',
'pb'
];
return @round($size / pow(1024, ($i = floor(log($size, 1024)))), 2) . ' ' . $unit[$i];
}
$files = glob("vendor/fileeye/pel/test/imagetests/*.jpg");
$csv = fopen('output_tests.csv', 'w');
for($i = 0; $i <= 100; $i++) {
echo "Pass: " . $i . PHP_EOL;
foreach($files as $imagePath) {
//echo "Processing file: " . $imagePath . PHP_EOL;
try {
// Load the JPEG file
//$jpeg = new PelJpeg($imagePath);
$jpeg = file_get_contents($imagePath);
gc_collect_cycles();
} catch(Exception $e) {
echo 'Error: ' . $e->getMessage() . PHP_EOL;
}
fputcsv($csv, [
$i,
microtime(true),
basename($imagePath),
memory_get_usage(),
memory_get_peak_usage()
]);
}
}
printf("MEM: %s\nPEAK: %s\n", bytes(memory_get_usage()), bytes(memory_get_peak_usage()));
// Save the CSV data
if(!empty($csvData)) {
fputcsv($csv, $csvData);
}
fclose($csv); PS: The code for the graph gen ( https://gist.github.com/dansleboby/68b93c34fad8d6e23bd65068f05be84d ) |
Well, that is kind of to be expected since basically both of the snippets of code end up doing the same thing - file_get_contents and indeed calling manually garbage collector doesn't seem to do any anything in reality.
The stream functionality should work by default with the same code - from my tests the difference is quite easy to notice. |
{
"require": {
"fileeye/pel": "dev-master"
},
"repositories": [
{
"type": "vcs",
"url": "https://github.com/indy2kro/pel"
}
]
} I'm already on your fork :) If I use the "fileeye/pel": "0.11.0" with same code as the last test with manual GC I get MEM: 38.46 mb So the stream made a huge global improvement, but the issue still present |
That behavior comes from the way exceptions are handled inside E.g. this works fine for me:
|
@dansleboby @indy2kro 0.12 is released. Can we close this? |
Hi,
Here is my test script:
I also try to add
But it change nothing
I think the issue is coming from the clone class, but I'm not shure:
pel/src/PelDataWindow.php
Line 209 in a43d242
Test env ( also test : (8.4.1, 8.2.26) )
Thanks for time and help
The text was updated successfully, but these errors were encountered: