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

Unexpected long cue export time (~73 sec) #2500

Open
bozaro opened this issue Jul 22, 2023 · 2 comments
Open

Unexpected long cue export time (~73 sec) #2500

bozaro opened this issue Jul 22, 2023 · 2 comments

Comments

@bozaro
Copy link
Contributor

bozaro commented Jul 22, 2023

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

$ cue version

cue version v0.0.0-20230628071453-b6a32da097fc

go version go1.20.6
      -buildmode exe
       -compiler gc
     CGO_ENABLED 1
          GOARCH amd64
            GOOS linux
         GOAMD64 v1
             vcs git
    vcs.revision b6a32da097fce5f9c960ad0a02da51efb18de2fd
        vcs.time 2023-06-28T07:14:53Z
    vcs.modified false

Does this issue reproduce with the latest stable release?

Yes. Also checked on:

What did you do?

cue export for single file:

package issue

#Context: {
	cluster: #ClusterInfo
}

#ContextForCluster: #Context & {
	#env:     string
	#cluster: string
	let env = #env
	let name = #cluster
	cluster: #ClusterInfo & {
		#env:  env
		#name: name
	}
}

#ConfigForCluster: #AppConfig & {
	#env:     string
	#cluster: string

	let env = #env
	let cluster = #cluster
	#context: #ContextForCluster & {
		#env:     env
		#cluster: cluster
	}
}

#AppInstanceConfigView: #AppConfigView & {
	#env:     string
	#cluster: string

	let env = #env
	let cluster = #cluster

	#config: #ConfigForCluster & {
		#env:     env
		#cluster: cluster
	}
}

#ClusterInfo: {
	#env:  "dev" | "stage" | "production"
	#name: string

	dev_env_version: number | *0
	env:             #env
	name:            #name

	if #env == "production" {
		dev_env_version: 0
	}
	if #env != "production" {
		dev_env_version: 42
	}
}

#ConfigBase: {
	#env:     string
	#cluster: string
	#context: #Context

	context: #context
	...
}

#AppConfig: #ConfigBase
#AppConfig: {
	#context: #Context

	application: {
		env:     #context.cluster.env
		cluster: #context.cluster.name
	}
	context: #context
	db:      string

	if #context.cluster.env == "production" {
		db: "app"
	}
	if #context.cluster.env == "dev" {
		let _context = #context
		db: "app_\(_context.cluster.env)"
	}
}

#AppConfigView: {
	#config: #ConfigBase

	let config = #config
	foo: #AppConfigFoo & {
		#config: config
	}
}

#AppConfigFoo1: {
	#config: #ConfigBase
	foo1:    1
	...
}

#AppConfigFoo2: {
	#config: #ConfigBase
	foo2:    2
	...
}

#AppConfigFoo3: {
	#config: #ConfigBase
	foo3:    3
	...
}

#AppConfigFoo: #AppConfigFoo1
#AppConfigFoo: #AppConfigFoo2
#AppConfigFoo: #AppConfigFoo3

issue: #AppInstanceConfigView & {
	#env:     "production"
	#cluster: ""
}

What did you expect to see?

I expect milliseconds export time and result like:

{
    "issue": {
        "foo": {
            "foo1": 1,
            "foo2": 2,
            "foo3": 3
        }
    }
}

What did you see instead?

time CUE_STATS_FILE=- cue export .
{
    "issue": {
        "foo": {
            "foo1": 1,
            "foo2": 2,
            "foo3": 3
        }
    }
}
{
    "CUE": {
        "Unifications": 493,
        "Disjuncts": 273499,
        "Conjuncts": 296180,
        "Freed": 273358,
        "Reused": 76737,
        "Allocs": 196622,
        "Retained": 617
    },
    "Go": {
        "AllocBytes": 20144851920,
        "AllocObjects": 721155138
    }
}
cue export ./issue  73,23s user 0,68s system 139% cpu 52,970 total
@bozaro bozaro added NeedsInvestigation Triage Requires triage/attention labels Jul 22, 2023
@bozaro
Copy link
Contributor Author

bozaro commented Jul 22, 2023

It looks interesting that in this example, line https://github.com/cue-lang/cue/blob/v0.6.0-alpha.2/internal/core/adt/context.go#L577-L579 is executed 28 385 504 times...

@mvdan mvdan added roadmap/performance and removed Triage Requires triage/attention labels Jul 22, 2023
@mvdan
Copy link
Member

mvdan commented Jul 22, 2023

Given that you don't import any standard library packages nor make use of many comprehensions, I think this is likely #2002 - although it's worthwhile to keep this issue open for the sake of the test case and to keep it open in case that ends up not being the case.

As you can see on #2335, v0.7 will focus on performance - where one of the main issues is disjunctions. Once the planned changes start landing in master, we can try again to see whether those help your example or not.

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