Nick Coghlan added the comment:

Ah, but that's the other trick: we *don't know* if we need to recalculate our 
whole cache when the object graph changes.

1. Some of the cached entries may never be accessed again, so recalculating 
them will be a waste
2. The object graph may change again before they're next accessed, so 
recalculating any entries at all will be waste

The cache invalidation design in the ABCs is a smart compromise, since it 
leaves recreating the cache entries to the last possible moment: the next time 
a type is looked up after the object graph has changed. It doesn't matter if 
there is one graph change or a thousand in that time, we only do the fresh 
lookup once. And if the type is never looked up again, we don't even need to do 
that much.

In a typical application, the expected usage model for both ABCs and generic 
functions is the same:

1. During startup, the object graph and dispatch resolution results are 
changing rapidly as concrete classes and implementations get registered with 
ABCs and generic functions. Actual instance checks and generic function 
dispatch operations are rare, so the caches mostly remain cold.
2. Once the application is up and running, the object graph stabilises, and the 
caches of significance to the application start to become populated through 
actual use. Absent live code reloading, the caches then remain valid for the 
lifetime of the application.

The ABC design takes the view that the extra runtime check for cache validity 
in the absence of direct inheritance or registration is worth it to avoid 
repeated cache clearing during application startup for ABCs that may never even 
be used by the application.

I believe exactly the same reasoning holds true for generic functions: 
triggering callbacks when the object graph changes means we may end up doing a 
lot of work clearing caches that the application isn't even using. Delaying the 
check to call time means that only the caches that matter will ever be touched.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue16832>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to