Are .gameObject and .transform both using GetComponent() in the background?

I know .transform usage should be cached for optimization. I can get around that by directly storing the Transform of the object so I can just say:

var myObject : Transform;
myObject.position = Vector3.zero;

However, if I also need to access the GameObject (in this case, to set it as active/inactive), does using myObject.gameObject also use a hidden GetComponent lookup as .transform does, or is .gameObject a special case?

A GameObject is not a component (it’s a container for components), so no, there is no possibility of using GetComponent in that case. The .transform shortcut is not actually using GetComponent either…there are three levels, in order of slowest to fastest: 1) GetComponent(Transform), 2) .transform, and 3) cached Transform such as your code example. Although “slowest” is relative; in reality there’s not a huge difference, and while caching it certainly doesn’t hurt, it may not result in any noticeable gains, unless you’re really accessing that component a lot.