Author ncoghlan
Recipients daniel.urban, lukasz.langa, ncoghlan, pitrou
Date 2013-05-25.16:20:41
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1369498841.87.0.12713884423.issue16832@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2013-05-25 16:20:41ncoghlansetrecipients: + ncoghlan, pitrou, daniel.urban, lukasz.langa
2013-05-25 16:20:41ncoghlansetmessageid: <1369498841.87.0.12713884423.issue16832@psf.upfronthosting.co.za>
2013-05-25 16:20:41ncoghlanlinkissue16832 messages
2013-05-25 16:20:41ncoghlancreate