Instead of retrieving first then checking for empty it is more efficient to first check for empty then retrieve.
Excessive retrieves can reduce performance. For more information check part 6 from https://www.kinetechcloud.com/kinetech/9-tips-for-starting-w-mendix
Non-compliant example:
Compliant example: