staticdata: Memoize `type_in_worklist` query (#57917)
When pre-compiling `stdlib/` this cache has a 91% hit rate, so this
seems fairly profitable. It also dramatically improves some pathological
cases, a few of which have been hit in the wild (arguably due to
inference bugs)
Without this PR, this package takes exponentially long to pre-compile:
```julia
function BigType(N)
(N == 0) && return Nothing
T = BigType(N-1)
return Pair{T,T}
end
foo(::Type{T}) where T = T
precompile(foo, (Type{BigType(40)},))
```
For an in-the-wild test case hit by a customer, this reduces
pre-compilation time from over an hour to just ~two and a half minutes.
Resolves #53331.
(cherry picked from commit 89271dc5a8a3236a148413409abb019bf973f6de)