From a03cdcb2578d79d37440606add42676bd55c3c33 Mon Sep 17 00:00:00 2001 From: Alan Guo Xiang Tan Date: Tue, 6 Feb 2024 07:43:15 +0800 Subject: [PATCH] PERF: Use `-O2` gcc compilation flag for imagemagick (#768) Why this change? We have noticed that our compiled imagemagick binary is slower than the distributed binaries in the same environment and started debugging why. One thing I noticed is that distributed binaries usually include the `-O2` gcc compilation flag. When applying it locally, I saw significant speed up. Without -O2 flag: ``` root@1d7277f72a4f:/# time convert -limit memory 10GiB -limit disk 10GiB -size $(seq 8000 8500 | shuf | head -n1)x9000 xc:"rgb($(shuf -i 0-255 -n1),$(shuf -i 0-255 -n1),$(shuf -i 0-255 -n1))" random_image.png real 0m3.376s user 0m6.355s sys 0m0.410s root@1d7277f72a4f:/# time identify -format "%Q" random_image.png 92 real 0m1.018s user 0m0.883s sys 0m0.135s ``` With -O2 flag: ``` root@0779afa71102:/# time convert -limit memory 10GiB -limit disk 10GiB -size $(seq 8000 8500 | shuf | head -n1)x9000 xc:"rgb($(shuf -i 0-255 -n1),$(shuf -i 0-255 -n1),$(shuf -i 0-255 -n1))" random_image.png real 0m1.118s user 0m1.555s sys 0m1.680s root@0779afa71102:/# time identify -format "%Q" random_image.png 92 real 0m0.330s user 0m0.197s sys 0m0.133s ``` --- image/base/install-imagemagick | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/image/base/install-imagemagick b/image/base/install-imagemagick index 911e719..41e7039 100755 --- a/image/base/install-imagemagick +++ b/image/base/install-imagemagick @@ -40,7 +40,7 @@ echo "$IMAGE_MAGICK_HASH $WDIR/ImageMagick.tar.gz" | sha256sum -c IMDIR=$WDIR/$(tar tzf $WDIR/ImageMagick.tar.gz --wildcards "ImageMagick-*/configure" |cut -d/ -f1) tar zxf $WDIR/ImageMagick.tar.gz -C $WDIR cd $IMDIR -PKG_CONF_LIBDIR=$PREFIX/lib LDFLAGS=-L$PREFIX/lib CFLAGS=-I$PREFIX/include ./configure \ +PKG_CONF_LIBDIR=$PREFIX/lib LDFLAGS=-L$PREFIX/lib CFLAGS='-O2 -I$PREFIX/include' ./configure \ --prefix=$PREFIX \ --enable-static \ --enable-bounds-checking \ -- 2.25.1