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

FillPath Performance Declines Linearly #899

Open
cueckoo opened this issue Jul 3, 2021 · 2 comments
Open

FillPath Performance Declines Linearly #899

cueckoo opened this issue Jul 3, 2021 · 2 comments

Comments

@cueckoo
Copy link
Collaborator

cueckoo commented Jul 3, 2021

Originally opened by @rawkode in cuelang/cue#899

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

0.3.2

Problem

FillPath performance starts really strong, at 27µs. However, as the number of increases, FillPath takes around 500ms at 1k entries. Sporadically throughout there are 1-2s FillPath calls also.

Video

https://i.rawko.de/jkuLe9l9

Reproduction

package main

import (
	"fmt"
	"os"
	"os/signal"
	"time"

	"cuelang.org/go/cue"
)

func main() {
	var cueRuntime cue.Runtime
	cueInstance, err := cueRuntime.Compile("", "")
	if err != nil {
		panic("No Cue Runtime")
	}
	cueValue := cueInstance.Value()

	c := make(chan os.Signal, 1)
	signal.Notify(c, os.Interrupt)

	go func() {
		for _ = range c {
			fmt.Println(cueValue)
			panic("Done")
		}
	}()

	i := 0
	for {
		start := time.Now()
		cueValue = cueValue.FillPath(cue.ParsePath(fmt.Sprintf("i_%!d(MISSING)", i)), i)
		now := time.Now()
		elapsed := now.Sub(start)
		fmt.Printf("FillPath %!d(MISSING) took %!v(MISSING)\n", i, elapsed)
		i++
	}
}
@cueckoo
Copy link
Collaborator Author

cueckoo commented Jul 3, 2021

Original reply by @rawkode in cuelang/cue#899 (comment)

Relevant #804 ?

@cueckoo
Copy link
Collaborator Author

cueckoo commented Jul 3, 2021

Original reply by @mpvl in cuelang/cue#899 (comment)

FTR: this comment already exists in internal/core/adt/closed.go and is related to exactly this issue:

	// TODO(perf): more aggressively determine whether a struct is open or
	// closed: open structs do not have to be checked, yet they can particularly
	// be the ones with performance issues, for instanced as a result of
	// embedded for comprehensions.

It basically is quadratic slowdown, thought the constant is higher than I expected.

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

4 participants