Can you show us your xpath and relevant parts of the domain model? There are several reasons it could take very long:
This module in particular can help you learn more about XPath optimization: https://academy.mendix.com/link/modules/385/lectures/3111/5.1-Different-Ways-to-Optimize-XPath-Queries