[Spice-devel] [PATCH spice-server] image-encoders: Initialize Zlib lazily
Christophe Fergeau
cfergeau at redhat.com
Mon Jan 28 12:30:41 UTC 2019
On Wed, Jan 23, 2019 at 07:46:16PM +0000, Frediano Ziglio wrote:
> Zlib structure take up more than 1MB and it is rarely used nowadays
> as it is not much effective.
> Initialise it only when necessary saving some memory in the normal
> case.
>
> Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
> ---
> server/image-encoders.c | 18 ++++++++++--------
> 1 file changed, 10 insertions(+), 8 deletions(-)
>
> diff --git a/server/image-encoders.c b/server/image-encoders.c
> index 88073a3e..6af1dc94 100644
> --- a/server/image-encoders.c
> +++ b/server/image-encoders.c
> @@ -451,12 +451,6 @@ static void image_encoders_init_zlib(ImageEncoders *enc)
> {
> enc->zlib_data.usr.more_space = zlib_usr_more_space;
> enc->zlib_data.usr.more_input = zlib_usr_more_input;
> -
> - enc->zlib = zlib_encoder_create(&enc->zlib_data.usr, ZLIB_DEFAULT_COMPRESSION_LEVEL);
> -
> - if (!enc->zlib) {
> - spice_critical("create zlib encoder failed");
> - }
> }
>
> void image_encoders_init(ImageEncoders *enc, ImageEncoderSharedData *shared_data)
> @@ -494,8 +488,10 @@ void image_encoders_free(ImageEncoders *enc)
> lz4_encoder_destroy(enc->lz4);
> enc->lz4 = NULL;
> #endif
> - zlib_encoder_destroy(enc->zlib);
> - enc->zlib = NULL;
> + if (enc->zlib) {
> + zlib_encoder_destroy(enc->zlib);
> + enc->zlib = NULL;
> + }
> pthread_mutex_destroy(&enc->glz_drawables_inst_to_free_lock);
> }
>
> @@ -1261,6 +1257,12 @@ bool image_encoders_compress_glz(ImageEncoders *enc,
> if (!enable_zlib_glz_wrap || (glz_size < MIN_GLZ_SIZE_FOR_ZLIB)) {
> goto glz;
> }
> + if (!enc->zlib) {
> + enc->zlib = zlib_encoder_create(&enc->zlib_data.usr, ZLIB_DEFAULT_COMPRESSION_LEVEL);
> + if (!enc->zlib) {
This used to be a spice_critical(), I'd add some kind of log here to
make it easier to spot something went wrong.
Christophe
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <https://lists.freedesktop.org/archives/spice-devel/attachments/20190128/31f57dad/attachment.sig>
More information about the Spice-devel
mailing list