cue-lang / cue

The home of the CUE language! Validate and define text-based and dynamic configuration
https://cuelang.org
Apache License 2.0
5.14k stars 294 forks source link

evalv3: Excessive Slowness or Potential Infinite Loop During Evaluation #3208

Open massive opened 5 months ago

massive commented 5 months ago

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

$ cue version

cue version v0.9.1-0.20240610152000-475f692480d6

go version go1.21.10
      -buildmode exe
       -compiler gc
     CGO_ENABLED 1
          GOARCH arm64
            GOOS darwin
cue.lang.version v0.9.0

Does this issue reproduce with the latest stable release?

No, that outright crashes.

What did you do?

This new issue is related to the issue at https://github.com/cue-lang/cue/issues/3194.

The commit addressing the mentioned issue resolved the panic that was reported. However, the same code utilizing evalv3 is still not functioning properly. It appears that the cue code is either running extremely slowly or stuck in an infinite loop.

Without evalv3, the code completes in about 3 seconds on a M2 Mac laptop.

________________________________________________________
Executed in    2.56 secs    fish           external
   usr time    4.71 secs   51.00 micros    4.71 secs
   sys time    0.11 secs  460.00 micros    0.11 secs

With evalv3 it does not seem to finish at all, or at least in a reasonable timeframe:

time CUE_EXPERIMENT=evalv3 cue export tests/fixtures/kafka_topics.cue
^C
________________________________________________________
Executed in  331.93 secs    fish           external
   usr time  344.85 secs   89.00 micros  344.85 secs
   sys time   18.43 secs  704.00 micros   18.42 secs

The issue can be reproduced with the private code supplied to @mvdan during the investigation of #3194. I can provide also a new sample upon request.

What did you expect to see?

JSON output

What did you see instead?

Hanging process

mvdan commented 3 months ago

This appears to still occur as of c683420c0797090a1445b453e3318a4570fc4742; I gave up after one minute. Memory usage also seems to slowly grow; it had already grown to 3GiB after one minute.

matiaskakelarelex commented 2 months ago

Reproduces still with cue version v0.11.0-alpha.1

mvdan commented 4 weeks ago

Still seems to happen as of 860906a7f025d8ea766aa29623c4ce4381740f89. It seems to be some sort of infinite loop at this point, because memory usage is pretty stable - I couldn't notice a continuous increase after two minutes - whereas CPU usage remains at 100% for a single core. Just as before, I gave up after two minutes, because evalv2 still finishes after three seconds.

So, even though the bug remains, it seems like at least the memory usage problem is gone.