Use cache during walk
Currently we'll call `evalPartial` three times during `walk` which is quite slow in large package. By using cache we'll improve `eval` speed greatly.
Closes #189
https://github.com/cuelang/cue/pull/189
GitOrigin-RevId: 42ecbb12fffd0e9e4ce0eb491884c82934d7bed1
Change-Id: I80b99f7754797b5f8a98ca1b90907f16f7204256
Reviewed-on: https://cue-review.googlesource.com/c/cue/+/4180
Reviewed-by: Marcel van Lohuizen <mpvl@golang.org>
diff --git a/cue/types.go b/cue/types.go
index 2c7eef1..e62d628 100644
--- a/cue/types.go
+++ b/cue/types.go
@@ -649,7 +649,10 @@
if v.path == nil {
return v, false
}
- u := v.path.v.evalPartial(v.ctx())
+ u := v.path.cache
+ if u == nil {
+ u = v.path.v.evalPartial(v.ctx())
+ }
x := v.ctx().manifest(u)
if x != u {
return remakeValue(v, x), true
@@ -675,7 +678,11 @@
if v.path == nil {
return BottomKind
}
- k := v.path.v.evalPartial(v.ctx()).kind()
+ c := v.path.cache
+ if c == nil {
+ c = v.path.v.evalPartial(v.ctx())
+ }
+ k := c.kind()
if k.isGround() {
switch {
case k.isAnyOf(nullKind):