This can be simplified to:
if ($this->isObjectNew() && (bool)$this->getData(EavAttributeInterface::IS_USED_IN_GRID)
|| !$this->isObjectNew() && $this->dataHasChangedFor(EavAttributeInterface::IS_USED_IN_GRID)
) {
$this->_getResource()->addCommitCallback([$this, 'invalidate']);
}