--- author: '' category: '' date: 2008/08/11 10:34 description: '' link: '' priority: '' slug: BB731 tags: programming, python title: Pickling can be expensive type: text updated: 2008/08/11 10:34 url_type: '' --- When trying to serialize python data, often the first thing we look at is pickle. Well, sometimes pickle can be very expensive! Here Post is an elixir class, which means it's an object mapped to a relational database, and comparing its properties to something is pretty much a piece of a SQL WHERE statement. .. code-block:: python >>> print Post.important==True posts.important = ? What happens when we pickle it? .. code-block:: python >>> print len(pickle.dumps(Post.important==True)) 27287 >>> print pickle.loads(s) posts.important = :important_1 Yikes. What's a better solution? .. code-block:: python >>> print eval('Post.important==True') posts.important = ? As long as we are sure no weird data will get into the eval...