[Grok-dev] Annotations Usage Pattern

Wichert Akkerman wichert at wiggy.net
Fri Jun 5 09:53:41 EDT 2009


Previously Paul Wilson wrote:
> Hi Grokkers,
> 
> I'm writing a system that uses annotations to store metadata about my
> objects. I'm using the annotations concept as a way of providing an
> extensible metadata facility. However as I continue to read and learn about
> Zope/Grok - I'm not sure about whether I'm taking the right approach.
> Looking at code/commentries written by a prominent Grok/Zope member, they
> advocate only non-extensive usage of annotations, and in their code write a
> meta-data facility which uses containment rather than annotations to solve
> the problem.
> 
> What wisdom on this topic do you have?

It depends a bit on your application. Annotations are very convenient,
but they have one downside: annotations are not stored directly on
the object being annotated but in a BTree on that object. That means
they are not in the same ZODB object. So instead of loading one object
from the ZODB you might need to load several objects, which will
increase latency and cache pressure. Most of the time that is not
problematic. If you need to scale up to large or high performance
systems this can become an important factor.

A rule of thumb: data that is accessed often should be stored in the
ZODB object, for example via an attribute on the python object.

Wichert.

-- 
Wichert Akkerman <wichert at wiggy.net>    It is simple to make things.
http://www.wiggy.net/                   It is hard to make things simple.


More information about the Grok-dev mailing list