Always check the source. In this instance View.java
https://github.com/android/platform_frameworks_base/blob/master/core/java/android/view/View.java#L7424-L7425
public void setVisibility(@Visibility int visibility) {
setFlags(visibility, VISIBILITY_MASK);
}
Calls setFlags
:
https://github.com/android/platform_frameworks_base/blob/master/core/java/android/view/View.java#L10538
This checks if the flag has changed, if it hasn't it returns quickly:
...
int old = mViewFlags;
mViewFlags = (mViewFlags & ~mask) | (flags & mask);
int changed = mViewFlags ^ old;
if (changed == 0) {
return;
}
...
So although I haven't got numbers for you in terms of performance, I would say the difference is negligible because it will not change if you set it to its already current value.
Also contrary to that getVisibility
doesn't do much either:
https://github.com/android/platform_frameworks_base/blob/master/core/java/android/view/View.java#L7413-L7415
public int getVisibility() {
return mViewFlags & VISIBILITY_MASK;
}