KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Comparing Compression Modes in COMPRESS BLOB Command
PRODUCT: 4D | VERSION: 19 | PLATFORM: Mac & Win
Published On: October 24, 2022

There are four compression modes that can be inserted into the compression parameter of the COMPRESS BLOB command:


  • Compact

  • Fast

  • GZIP Best

  • GZIP Fast


This tech tip will take a look at the space and time differences between the four compression modes and figure out the best mode for each aspect. To execute this experiment, 4D reads an image file, converts this picture into a blob, then compresses it.

To compare the differences in space, a small pool of 6 images, all of fairly large sizes, will be tested on. To get the size difference, 4D measures the BLOB SIZE before and after the COMPRESS BLOB command and takes the difference. The results will then be analyzed to see which mode compresses the most space.

To compare the differences in time, the same image will be processed over ten rounds.
Similar to obtaining the size difference, the time difference is taken by measuring two timestamps, using the MILLISECONDS function, and calculating the difference. The results are then analyzed to find the compression mode with the least average execution time.


Code to read picture file, convert to blob, and compress
// read picture file
$path:=Get 4D folder(Database folder)
READ PICTURE FILE($path+"stock.jpeg"; $pictureFile)

// convert picture to blob
PICTURE TO BLOB($pictureFile; $pictureBlob; ".jpeg")

// get start size and timestamp
$startSize:=BLOB size($pictureBlob)
$startTime:=Milliseconds

// compress blob
COMPRESS BLOB($compact; Compact compression mode) // choose 1 of 4 modes

// get size and time difference
$timeDiff:=Milliseconds-$startTime
$sizeDiff:=$startSize-BLOB size($pictureBlob)


Size Difference

* size in bytes

With a small sample size, the four modes cover a range of results. Some modes even enlarge the blob from its original size. In general, however, the GZIP modes fare much better than the compact and fast modes. The decision between the two GZIP compression modes can depend on the blobs being compressed, but the GZIP Fast Compression Mode offers a faster execution time. For this reason, the GZIP Fast Compression Mode is recommended for general cases.

Time Difference

The Fast Compression Mode exceeds the other modes by a ballpark with an average execution time of 57.2 milliseconds. If speed is a significant aspect in your application, Fast Compression Mode is the way to go.