Optimize attr fetching

Assign duplicate calls to variables, especially computed dict keys or default values for dict.get().