public inbox for gentoo-portage-dev@lists.gentoo.org
 help / color / mirror / Atom feed
From: David James <davidjames@google.com>
To: gentoo-portage-dev@lists.gentoo.org
Subject: Re: [gentoo-portage-dev] [PATCH] portdbapi: Add cache to avoid repeated failing os.access calls
Date: Tue, 18 Feb 2014 13:35:46 -0800	[thread overview]
Message-ID: <CAGNm6eykwBOWTfpuff4Lv2A3m6mufQJ2cVg33t-VGzWbjZeH-w@mail.gmail.com> (raw)
In-Reply-To: <1392757337-26882-2-git-send-email-SebastianLuther@gmx.de>

[-- Attachment #1: Type: text/plain, Size: 2512 bytes --]

On Tue, Feb 18, 2014 at 1:02 PM, Sebastian Luther <SebastianLuther@gmx.de>wrote:

> ---
>  pym/portage/dbapi/porttree.py | 13 +++++++++++++
>  1 file changed, 13 insertions(+)
>
> diff --git a/pym/portage/dbapi/porttree.py b/pym/portage/dbapi/porttree.py
> index 590e3c5..2dc406b 100644
> --- a/pym/portage/dbapi/porttree.py
> +++ b/pym/portage/dbapi/porttree.py
> @@ -254,6 +254,7 @@ class portdbapi(dbapi):
>
>                 self._aux_cache = {}
>                 self._broken_ebuilds = set()
> +               self._findname2_cache = {}
>
>         @property
>         def _event_loop(self):
> @@ -372,6 +373,14 @@ class portdbapi(dbapi):
>                 the file we wanted.
>                 If myrepo is not None it will find packages from this
> repository(overlay)
>                 """
> +               cache_key = (mycpv, mytree, myrepo)
> +               try:
> +                       return self._findname2_cache[cache_key]
> +               except KeyError:
> +                       self._findname2_cache[cache_key] = (None, 0)
>

To me, it seems potentially error-prone to cache a (potentially) incorrect
value and then correct it later. Would it be possible to refactor your
patch so that we only cache the value when we know the final answer?


> +               except TypeError:
>

In what circumstances does it happen that mytree / myrepo are unhashable
types? Can you add a comment to explain this?

+                       cache_key = None
> +
>                 if not mycpv:
>                         return (None, 0)
>
> @@ -383,6 +392,8 @@ class portdbapi(dbapi):
>                 mysplit = mycpv.split("/")
>                 psplit = pkgsplit(mysplit[1])
>                 if psplit is None or len(mysplit) != 2:
> +                       if cache_key:
> +                               del self._findname2_cache[cache_key]

                        raise InvalidPackageName(mycpv)
>
>                 # For optimal performace in this hot spot, we do manual
> unicode
> @@ -402,6 +413,8 @@ class portdbapi(dbapi):
>                         filename = x + _os.sep + relative_path
>                         if _os.access(_unicode_encode(filename,
>                                 encoding=encoding, errors=errors),
> _os.R_OK):
> +                               if cache_key:
> +                                       self._findname2_cache[cache_key] =
> (filename, x)
>                                 return (filename, x)
>                 return (None, 0)
>
> --
> 1.8.3.2
>
>
>

[-- Attachment #2: Type: text/html, Size: 3811 bytes --]

  reply	other threads:[~2014-02-18 21:36 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-02-18 21:02 [gentoo-portage-dev] Avoid repeated failing os.access Sebastian Luther
2014-02-18 21:02 ` [gentoo-portage-dev] [PATCH] portdbapi: Add cache to avoid repeated failing os.access calls Sebastian Luther
2014-02-18 21:35   ` David James [this message]
2014-02-19 19:01     ` Sebastian Luther

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

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

  git send-email \
    --in-reply-to=CAGNm6eykwBOWTfpuff4Lv2A3m6mufQJ2cVg33t-VGzWbjZeH-w@mail.gmail.com \
    --to=davidjames@google.com \
    --cc=gentoo-portage-dev@lists.gentoo.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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox