Workaround the global quark cache

The global quark cache causes heavy contention for the global lock.
This workaround introduces a per-thread cache that gets checked when
doing a definition lookup.