php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #13860 Bzip2 bzdecompress function is wery slow...
Submitted: 2001-10-28 15:34 UTC Modified: 2001-10-28 21:30 UTC
From: mcdouglas at angelfire dot com Assigned: jeroen (profile)
Status: Closed Package: Performance problem
PHP Version: 4.0.6 OS: Windows 98 SE
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
12 + 9 = ?
Subscribe to this entry?

 
 [2001-10-28 15:34 UTC] mcdouglas at angelfire dot com
I made a little decompresser script:

<?php
$efilename = "d:/pic.bz2"; //A compressed jpg image ( original size: 388kbyte, packed size: 388kbyte)
$ufilename2 = "d:/pic.jpg";

$fp = fopen($efilename, "rb");
$ecd_cont = fread($fp, filesize($efilename)); //read the compressed data from file
fclose($fp);

$fp = fopen($ufilename2,"wb");
$ecd_cont = bzdecompress($ecd_cont,1); //decompress the readed compressed data
fwrite($fp, $ecd_cont); //write the decompressed data into file
fclose($fp);

echo "<img src=\"file://d:\\pic.jpg\">"; 
?>

Ok, this is work... But it is WERY WERY slow!!! It's take 60sec to display the decompressed image, why??



I made the decompression befor with an other method:

<?php
$efilename = "d:/pic.bz2";
$ufilename2 = "d:/pic.jpg";

$bz = bzopen($efilename, "rb");
$ecd_cont = bzread($bz, 400000); // See below
bzlose($bz);

$fp = fopen($ufilename2,"wb");
fwrite($fp, $ecd_cont);
fclose($fp);

echo "<img src=\"file://d:\\pic.jpg\">";
?>

Ok this is working (And this is fast! The decompressed picture appears immediately), but there is a little problem:

In the PHP manual I read this about the bzread() function:

"If the optional parameter length is not
specified, bzread() will read 1024 (uncompressed) bytes at a time."

Ok, so it will read 1024 uncompressed bytes from my compressed file, if I not give the lenght parameter (as I did in the example). But there is a problem: if I want to be precise then I must give the lenght of the original file, but how??? I only have the compressed file, which is not equal with the original (ok, in my example it is, but only because the original jpg-compressed file), so I cant use the filesize() function, because it gave only the compressed filesize, neither the strlen() because I havnt got a string yet :)

And I think you agree with me if I dont want to write 400Mbyte to parameter... this is not a correct solution. I think the correct solution if the bzread() function is read the entire file if I dont give the lenght parameter.


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-10-28 15:57 UTC] mcdouglas at angelfire dot com
bzdecompress($ecd_cont,1);

I'm used it without the 1 parameter, i'm just tryed uot what happen if i use it...
 [2001-10-28 16:27 UTC] jeroen@php.net
Please don't but multiple issues in one report, and keep your report short. (bugs do's and don'ts)

I'm transforming this report into performance question of bzip,  open a new feature/change request on the second parameter.

you use bzdecompress(..., TRUE), i.e. you tell it to be two times slower... Then you shouldn't complain about performance, bzip is very strong compression at the cost of high memory and cpu usage. And you read the whole file in memory, decompress it, write it back to disk... that's very inefficient. So this is not a bug in PHP, but a problem with your script. Ask http://www.php.net/support.php for support questions on how to do things efficiently.

Compressing JPG's is a quite useless practice by the way... jpg is already compressed.

 [2001-10-28 20:01 UTC] mcdouglas at angelfire dot com
>you use bzdecompress(..., TRUE), i.e. you tell it to be two times slower... Then you shouldn't complain about performance, bzip is very strong compression at the cost of high memory and cpu usage.

As I said in my comment I just tried what happen if I use the True parameter. I used the script without that parameter and it was slow...

>And you read the whole file in memory, decompress it, write it back to disk... that's very inefficient.

Interesting. But I did the same in my "older" version of decompression script and it was fast... I dont sure why there is this differnece in the speed between the bzwrite() and the bzdecompress() functions. Btw I think I have a fast PC, a simple decompression like this should not take more than two or there secounds...

>Compressing JPG's is a quite useless practice by the way... jpg is already compressed.

Of course I know jpg is already compressed... but this is a wery good way to test my script... If it works i can see the result immediately (the <img> at the and of the script). Is it satisfie you if I use pic.bmp next time? :)

 [2001-10-28 20:31 UTC] jeroen@php.net
Reopened, the current implementation of bzdecompress is extremely inefficient.

Assigned to myself.
 [2001-10-28 21:30 UTC] jeroen@php.net
Fixed in CVS, will be in 4.2.0

Memory requirements are also lower now, as is for bzcompress.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 20:01:28 2024 UTC