Cache UDF definitions

We call this method a bunch of times and it is a fairly intensive
operation. UDFDs change pretty rarely so this seem like a good place to
start.
Reduce instance-building database queries

It takes about 60ms to build and execute a query that returns an
instance - since we already do it at the start of the execution cycle we
can reuse it.

Same with "has_itree_region"

Also reduces user loading.