playMaker

Author Topic: String compression - GZip / LZF / PHP GZip  (Read 6505 times)

dudebxl

  • Hero Member
  • *****
  • Posts: 602
String compression - GZip / LZF / PHP GZip
« on: January 14, 2016, 01:50:42 PM »
Compress/decompress actions

8 Actions:
  • LZFCompressString
  • LZFDecompressString
  • LZFCompressTexture
  • LZFDecompressTexture
  • GZipCompressString
  • GZipDecompressString
  • GZipPHPCompressString
  • GZipPHPDecompressString

Note:
LZF is fast (recommended over Gzip)
Gzip is normal
Gzip PHP is for strings encoded by PHP (i.e. base64_encode(gzencode("hello world")))
Anything that is converted to a string can be compressed (i.e ? -> bytes -> string -> compress).
You have to download https://github.com/Hitcents/Unity.IO.Compression for GZip actions (due to Unity Mono bug?).

Note: I have not moved to PM1.8 (yet) so the compression result is a string which increases the final byte size by 30% (source 1Mb -> 500kb byte compress -> final result 650kb as string). This can be solved in PM1.8 with byte array (i assume)

On ecosystem or https://snipt.net/dudebxl/

Any problems pm here. Enjoy!  :)
« Last Edit: March 10, 2016, 11:08:17 AM by dudebxl »

dudebxl

  • Hero Member
  • *****
  • Posts: 602
Re: String compression - GZip / LZF / PHP GZip
« Reply #1 on: March 01, 2016, 10:59:13 PM »
Did anybody get

GZipCompressString
GZipDecompressString
GZipPHPCompressString
GZipPHPDecompressString

.. to work (Mac / PC /Ios / Android)??? I will delete if they are not working from ecosystem..
« Last Edit: March 10, 2016, 10:38:53 AM by dudebxl »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: String compression - GZip / LZF / PHP GZip
« Reply #2 on: March 02, 2016, 01:46:13 AM »
Hi,

 What was not working? Is it not a question of http headers and server config rather then the code itself?

Bye,

 Jean

dudebxl

  • Hero Member
  • *****
  • Posts: 602
Re: String compression - GZip / LZF / PHP GZip
« Reply #3 on: March 02, 2016, 09:10:28 AM »
Hi,

Thanks for your interest in this.. Well, for android, the System.IO.Compression classes do not seem to be included in the build or is broken(see below). It is a bit weird cause the actions work in play mode in the editor.

Based on my research I found this: Unity is built on the top old version mono (v2.6) with some hacks from Unity team and have never upgraded to recent versions of mono during whole Unity lifetime. This means that Unity inherits all old mono bugs, which were fixed in the latest versions of mono. One of this bug was the bug with deflate stream Mono & DeflateStream. It has being fixed pretty fast in mono, but has not being fixed in Unity.

To workaround this bug for my Unity web application, I have to use managed implementation of Deflate stream. I decided to use Ionic.Zlib, it has the same interface as System.IO.Compression.


What is bad that it's performance roughly 3 times worse than native mono implementation, but adding ifdefs in the source resolves the performance issue at least for server code.

I converted my actions for this: https://github.com/Hitcents/Unity.IO.Compression
and now it works.. but would be nice to get some from feedback from another user, to see if it worked for them. If not then, I will delete them from the eco (not point having broken actions) and replace them with the actions that work with the github code.

Let me know what you think. Thanks.
« Last Edit: March 02, 2016, 11:04:21 PM by dudebxl »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: String compression - GZip / LZF / PHP GZip
« Reply #4 on: March 03, 2016, 03:00:07 AM »
Hi,

 I see. Isn't Unity 5 based on a new version of mono? but to play safe I think you made a good move actually.

 I would replace the actions on the Ecosystem, and wait for feedback, it's always better to have something pending for issues then nothing at all. While I haven't used your actions yet, I have them well stored in my memory for future com with REST apis and similar, so I would keep them no matter what.

Bye,

 Jean

Bye,

 Jean

dudebxl

  • Hero Member
  • *****
  • Posts: 602
Re: String compression - GZip / LZF / PHP GZip
« Reply #5 on: March 21, 2016, 09:30:39 PM »
*** update bump  - bug corrected in LZFDecompressTexture action