Optimize call to get_id()

Calls to ObjectDefinition.get_id() are relatively expensive,

This patch cheats a little and caches the result, so multiple calls
to get_id() on the same object are not calculated every time.