optimizations in context saving/restoring