unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Lars Magne Ingebrigtsen <larsi@gnus.org>
To: Paul Eggert <eggert@cs.ucla.edu>
Cc: emacs-devel@gnu.org
Subject: Re: trunk r113947: * image.c: Fix animation cache signature memory leak.
Date: Mon, 19 Aug 2013 17:22:01 +0200	[thread overview]
Message-ID: <m3r4dpg0yu.fsf@stories.gnus.org> (raw)
In-Reply-To: <E1VBJTG-0003rv-7A@vcs.savannah.gnu.org> (Paul Eggert's message of "Mon, 19 Aug 2013 07:01:46 +0000")

Paul Eggert <eggert@cs.ucla.edu> writes:

>   * image.c: Fix animation cache signature memory leak.

Thank you for fixing that.

However:

>   Fix some other minor performance problems while we're at it.
>   (imagemagick_create_cache): Clear just the members that
>   need clearing.

This is the fix -- not to call xzalloc, because then we ... just don't
have to set update_time and signature twice.

> -  struct animation_cache *cache = xzalloc (sizeof *cache);
> +  struct animation_cache *cache = xmalloc (sizeof *cache);
>    cache->signature = signature;
> -  cache->update_time = current_emacs_time ();
> +  cache->wand = 0;
> +  cache->index = 0;
> +  cache->next = 0;

That's a major speedup -- creating an animation cache entry is done once
per animated image.  Instead you make the code more fragile and longer,
so that it'll have to be updated if we add more fields.

Seriously?  That's a performance problem?  I repeat, once per animated
image.  You'll be lucky if that happens once per hour.

>   (imagemagick_prune_animation_cache, imagemagick_get_animation_cache):
>   Simplify by using pointer-to-pointer instead of a prev pointer.

Yeah, that was a lot simpler:

> -  if (! cache)
> -    {
> -      animation_cache = imagemagick_create_cache (signature);
> -      return animation_cache;
> -    }
> -
> -  while (strcmp(signature, cache->signature) &&
> -	 cache->next)
> -    cache = cache->next;
> -
> -  if (strcmp(signature, cache->signature))
> -    {
> -      cache->next = imagemagick_create_cache (signature);
> -      return cache->next;
> +  for (pcache = &animation_cache; *pcache; pcache = &cache->next)
> +    {
> +      cache = *pcache;
> +      if (! cache)
> +	{
> +	  *pcache = cache = imagemagick_create_cache (signature);
> +	  break;
> +	}
> +      if (strcmp (signature, cache->signature) == 0)
> +	{
> +	  DestroyString (signature);
> +	  break;
> +	}

The new code is no shorter, but it's more difficult to understand.  The
pointer to a pointer thing is quite clever.  Perhaps too clever, because
you obviously didn't understand it yourself, and you didn't test it,
because it segfaulted the first time it was called.

imagemagick_prune_animation_cache was an improvement, though.

But my point is:  Seriously?  Are you doing these rewrites just to
create maximum obfuscation or something?  If it sounds like I'm pissed,
it's because I am, because I had to spend an hour debugging this
segfault instead of getting on with my job.

-- 
(domestic pets only, the antidote for overdose, milk.)
  No Gnus T-Shirt for sale: http://ingebrigtsen.no/no.php
  and http://lars.ingebrigtsen.no/2013/08/twenty-years-of-september.html



       reply	other threads:[~2013-08-19 15:22 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <E1VBJTG-0003rv-7A@vcs.savannah.gnu.org>
2013-08-19 15:22 ` Lars Magne Ingebrigtsen [this message]
2013-08-19 16:16   ` trunk r113947: * image.c: Fix animation cache signature memory leak Paul Eggert
2013-08-19 16:19     ` Lars Magne Ingebrigtsen
2013-08-19 16:24       ` Paul Eggert
2013-08-19 16:40         ` Lars Magne Ingebrigtsen
2013-08-19 16:56           ` Paul Eggert
2013-08-19 17:04             ` Lars Magne Ingebrigtsen
2013-08-19 19:46               ` Paul Eggert
2013-08-19 19:51                 ` Lars Magne Ingebrigtsen
2013-08-19 20:52                   ` Paul Eggert
2013-08-19 20:56                     ` Lars Magne Ingebrigtsen
2013-08-19 20:55                   ` Lars Magne Ingebrigtsen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=m3r4dpg0yu.fsf@stories.gnus.org \
    --to=larsi@gnus.org \
    --cc=eggert@cs.ucla.edu \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).