lz-string-php icon indicating copy to clipboard operation
lz-string-php copied to clipboard

long text takes very long time in compression

Open kerolos-sss opened this issue 11 years ago • 5 comments
trafficstars

I have a text of length 357813. When trying to compress it takes a very long time. I use LZString::compressToBase64 . While when trying the same string on js LZString it runs very fast.

Note: The string is a stringified JSON object.

kerolos-sss avatar Sep 08 '14 08:09 kerolos-sss

I have exactly the same problem for a JSON string of length 895726, takes very long to execute LZString::compressToBase64().

ZaDarkSide avatar Oct 12 '14 04:10 ZaDarkSide

hey guys, i've spent some time the last days to solve this problem. the problem is based on the different encodings used in the js version and the php version. current version emulates the javascript ord and charCodeAt functions in php by using the php multibyte functions "mb_*". Unfortunately these functions become very slow when faced with a huge amount data.

So for a faster implementation i think an approach with the pack and unpack funcitons should do it. Sadly or luckily i'm a full time employee and don't have that much time to put into this issue. So if some of you guys like to, feel free to fork this project!

nullpunkt avatar Oct 27 '14 15:10 nullpunkt

+1 It is unfortunate that it's too slow to decode/encode.

mrcasual avatar Dec 09 '14 18:12 mrcasual

Hello,

Does anyone found a way to speed up the process ? For 66000 characters string, it taks 24 seconds with compressToUTF16. And I would need to compress a +1million characters...

trompx avatar Jun 04 '16 18:06 trompx

Hi, Thanks for making this library. I also came on the issue of exponentially increasing complexity of compression and decomrpession depending on compressible size. I have spent a night on it and have a fix in my clone of the repo https://github.com/peetervois/lz-string-php version 71d4bf81c73bea6e1eebc848f23cae9a6ac470ac or the version master latest. I am using compression and decompression from URI safe strings. In server side is PHP and in frontend is the javascript variant. These work together. The change also affected other methods and I have not tested those.

peetervois avatar Sep 22 '20 18:09 peetervois