I am running 8.0.0 locally for testing and I find the former query very fast on my system. One possibility is that since
it's a function the plan may have been created before you analyzed and just has a poor plan. In any case it would be interesting to see the explain analyze output for both versions to try to understand what's going on.