perf(gatsby): perf problem for match-page search in large sites (#19691)
perf(gatsby): perf problem for match-page search in large sites (#19691)

The particular search here started with `pages.length == 25599` and `matchPathPages.length == 2` but because `matchPathPages` was being pushed onto inside the loop, the array grew and grew. Ultimately the inner `find` was calling its callback 72 million (!) times, causing massive build delays (this was taking 2/3rds of the total build time for this site).

In contrast, this `forEach` took 390s (seconds!) before and now takes 0.47s on my machine.

This problem is caused by inefficient routing that is sometimes necessary for proper 404 handling. This becomes a big problem as the site grows and the match-path.json grows. There are some user-land improvements we can suggest to work around other problems, but at least this one we can resolve.

Thanks to @eads for offering a real-world site in #19512 so we could profile this, and @pieh for helping with the debugging.
gatsbyjs/gatsby,gatsbyjs/gatsby,gatsbyjs/gatsby,gatsbyjs/gatsby,gatsbyjs/gatsby,gatsbyjs/gatsby