Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

A year spent in artificial intelligence is enough to make one believe in God.


devel / comp.lang.python / Re: Best practice for caching hash

SubjectAuthor
o Re: Best practice for caching hash2QdxY4RzWzUUiLuE

1
Re: Best practice for caching hash

<mailman.282.1647120965.2329.python-list@python.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=17486&group=comp.lang.python#17486

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: 2QdxY4Rz...@potatochowder.com
Newsgroups: comp.lang.python
Subject: Re: Best practice for caching hash
Date: Sat, 12 Mar 2022 16:16:03 -0500
Lines: 27
Message-ID: <mailman.282.1647120965.2329.python-list@python.org>
References: <CABbU2U9CwzB=ko_2n-QCG32MC3kn6R7R-m-TcOJZPPMWsULGxw@mail.gmail.com>
<Yi0NkyBuovs3vf5G@scrozzle>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
X-Trace: news.uni-berlin.de O005IRFwcixZ3vivfWcdJQ3yRDQBI0EjbL4Lc6irFVuw==
Return-Path: <2QdxY4RzWzUUiLuE@potatochowder.com>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=none reason="no signature";
dkim-adsp=none (unprotected policy); dkim-atps=neutral
X-Spam-Status: OK 0.027
X-Spam-Evidence: '*H*': 0.95; '*S*': 0.00; 'received:78': 0.09;
'typeerror:': 0.09; 'memory': 0.15; '(i.e.,': 0.16; 'caching':
0.16; 'from:addr:2qdxy4rzwzuuilue': 0.16;
'from:addr:potatochowder.com': 0.16; 'hand,': 0.16; 'int)': 0.16;
'message-id:@scrozzle': 0.16; 'received:136.243': 0.16;
'received:78.46': 0.16; 'received:78.46.172': 0.16;
'received:www458.your-server.de': 0.16; 'received:your-server.de':
0.16; 'wrote:': 0.16; 'to:addr:python-list': 0.20; "what's": 0.22;
'received:de': 0.23; 'object': 0.26; 'leave': 0.27; 'error': 0.29;
'think': 0.32; 'received:136': 0.32; 'but': 0.32; 'subject:for':
0.33; 'header:In-Reply-To:1': 0.34; 'trying': 0.35; 'using': 0.37;
'use': 0.39; 'advantage': 0.40; 'situation': 0.40; 'try': 0.40;
'once': 0.63; 'pass': 0.64; 'time.': 0.66; 'time,': 0.67; 'per':
0.68; 'times': 0.69; 'little': 0.73; 'extra': 0.84; 'benefit.':
0.84; 'sulla': 0.84
Mail-Followup-To: python-list@python.org
Content-Disposition: inline
In-Reply-To: <CABbU2U9CwzB=ko_2n-QCG32MC3kn6R7R-m-TcOJZPPMWsULGxw@mail.gmail.com>
X-Authenticated-Sender: 2QdxY4RzWzUUiLuE@potatochowder.com
X-Virus-Scanned: Clear (ClamAV 0.103.5/26479/Sat Mar 12 10:43:29 2022)
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.39
Precedence: list
List-Id: General discussion list for the Python programming language
<python-list.python.org>
List-Unsubscribe: <https://mail.python.org/mailman/options/python-list>,
<mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive: <https://mail.python.org/pipermail/python-list/>
List-Post: <mailto:python-list@python.org>
List-Help: <mailto:python-list-request@python.org?subject=help>
List-Subscribe: <https://mail.python.org/mailman/listinfo/python-list>,
<mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID: <Yi0NkyBuovs3vf5G@scrozzle>
X-Mailman-Original-References: <CABbU2U9CwzB=ko_2n-QCG32MC3kn6R7R-m-TcOJZPPMWsULGxw@mail.gmail.com>
 by: 2QdxY4Rz...@potatochowder.com - Sat, 12 Mar 2022 21:16 UTC

On 2022-03-12 at 21:45:56 +0100,
Marco Sulla <Marco.Sulla.Python@gmail.com> wrote:

[ ... ]

> So if I do not cache if the object is unhashable, I save a little
> memory per object (1 int) and I get a better error message every time.

> On the other hand, if I leave the things as they are, testing the
> unhashability of the object multiple times is faster. The code:
>
> try:
> hash(o)
> except TypeError:
> pass
>
> execute in nanoseconds, if called more than 1 time, even if o is not
> hashable. Not sure if this is a big advantage.

Once hashing an object fails, why would an application try again? I can
see an application using a hashable value in a hashable situation again
and again and again (i.e., taking advantage of the cache), but what's
the use case for *repeatedly* trying to use an unhashable value again
and again and again (i.e., taking advantage of a cached failure)?

So I think that caching the failure is a lot of extra work for no
benefit.

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor