Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

evaluator: it looks like the result of executing functions is not reused #2566

Open
bozaro opened this issue Aug 24, 2023 · 4 comments
Open

Comments

@bozaro
Copy link
Contributor

bozaro commented Aug 24, 2023

What version of CUE are you using (cue version)?

$ cue version

cue version v0.0.0-20230816083946-7d801ba406ea

go version go1.20.7
      -buildmode exe
       -compiler gc
     CGO_ENABLED 1
          GOARCH amd64
            GOOS linux
         GOAMD64 v1
             vcs git
    vcs.revision 7d801ba406ea82923c19e66ce6aa419fdb62b2e8
        vcs.time 2023-08-16T08:39:46Z
    vcs.modified true

Does this issue reproduce with the latest stable release?

Yes

What did you do?

I evaluate cue file with breakpoint on line: https://github.com/cue-lang/cue/blob/v0.6.0/pkg/strings/pkg.go#L300

import "strings"

let foo = strings.HasPrefix("foo", "bar")
a: foo
b: foo
c: foo
d: foo
e: foo

What did you expect to see?

I expect only one interrupt at breakpoint (function strings.HasPrefix executed one time).

What did you see instead?

I got 6 interrupts at breakpoints (function strings.HasPrefix executed 6 times).

@bozaro bozaro added NeedsInvestigation Triage Requires triage/attention labels Aug 24, 2023
@bozaro bozaro changed the title It looks like the result of executing functions is not reused evaluator: it looks like the result of executing functions is not reused Aug 24, 2023
@mvdan
Copy link
Member

mvdan commented Aug 24, 2023

Perhaps related to #2243, where "chained" calls to builtins would result in increasingly slower evaluation.

@mvdan mvdan added roadmap/performance and removed Triage Requires triage/attention labels Aug 24, 2023
@bozaro
Copy link
Contributor Author

bozaro commented Aug 25, 2023

I checked behaviour before and after changeset https://review.gerrithub.io/c/cue-lang/cue/+/549247 from #2243 and got exactly same behaviour.

@bozaro
Copy link
Contributor Author

bozaro commented Aug 25, 2023

Interestingly, in this example, strings.ToLower is executed exactly once:

import "strings"

let bar = strings.ToLower("BAR")
a: strings.HasPrefix("foo1", bar)
b: strings.HasPrefix("foo2", bar)
c: strings.HasPrefix("foo3", bar)
d: strings.HasPrefix("foo4", bar)
e: strings.HasPrefix("foo5", bar)

But in this example strings.ToLower is executed six times:

import "strings"

let bar = strings.ToLower("BAR")
a: bar
b: bar
c: bar
d: bar
e: bar

@bozaro
Copy link
Contributor Author

bozaro commented Sep 11, 2023

I spent several days debugging this issue and wrote the ugly workaround:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants