internal/core/adt: cache containsDefID results
Judson's project in Unity was spending about 70% of CPU time
in containsDefIDRec, because the evaluator made over 700 million calls
to containsDefID, where over half were repeated in terms of the
node and child pair of defID parameters.
With this change, the wall time of exporting Judson's config
drops from ~22s to ~15s, and containsDefIDRec drops from taking
70% of CPU time to just over 50%.
Note that there is some added overhead due to the caching;
out of the new 20s of CPU time spent, about 1.2s is spent reading
and writing to the cache map. However, this seems well worthwhile,
given that we save 7s even with this overhead.
Signed-off-by: Daniel Martí <mvdan@mvdan.cc>
Change-Id: If1bb69febb515f03e97f0f82c72ee1e784b1adef
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1224497
Reviewed-by: Marcel van Lohuizen <mpvl@gmail.com>
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>