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

chore: speed up resolveResourceReferences #625

Merged

Conversation

crenshaw-dev
Copy link
Member

@crenshaw-dev crenshaw-dev commented Sep 10, 2024

Sitting at the airport with nothing better to do than micro-optimize stuff.

before: Benchmark_resolveResourceReferences-16           4676506               252.4 ns/op            82 B/op          3 allocs/op
after: Benchmark_resolveResourceReferences-16            8308146               143.6 ns/op            82 B/op          3 allocs/op

I didn't commit the benchmark code, because it's trivial and shouldn't be needed in the future. Here it is for inspection:

func Benchmark_resolveResourceReferences(b *testing.B) {
	manifest := []byte(`
apiVersion: extensions/v1beta2
kind: Deployment
metadata:
  name: nginx-deployment
  labels:
    foo: bar
  uid: '123'
  ownerReferences:
  - apiVersion: apps/v1
    kind: StatefulSet
    name: sw-broker
    uid: '456'
`)
	obj := unstructured.Unstructured{}
	err := yaml.Unmarshal(manifest, &obj.Object)
	require.NoError(b, err)

	c := clusterCache{}

	b.ResetTimer()

	for i := 0; i < b.N; i++ {
		c.resolveResourceReferences(&obj)
	}
}

Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com>
Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com>
@crenshaw-dev
Copy link
Member Author

Argo CD tests passed, merging. Thanks, Alex!

@crenshaw-dev crenshaw-dev merged commit 3d9aab3 into argoproj:master Sep 16, 2024
2 checks passed
@crenshaw-dev crenshaw-dev deleted the faster-resolveResourceReferences branch September 16, 2024 20:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants