Skip to content

Use strings.Builder for querybuilder build method - #5007

Merged
vito merged 2 commits into
dagger:mainfrom
matiasinsaurralde:querybuilder-improvement
Apr 24, 2023
Merged

vito merged 2 commits into
dagger:mainfrom
matiasinsaurralde:querybuilder-improvement

Conversation

@matiasinsaurralde

Copy link
Copy Markdown
Contributor

It's a minor improvement to querybuilder performance, given this benchmark:

func BenchmarkBuilder(b *testing.B) {
	for i := 0; i < b.N; i++ {
		var contents string
		root := Query().
			Select("foo").
			Select("bar").Arg("hello", "world").
			Select("field").Arg("test", "test").Bind(&contents)
		root.build(context.Background())
		_, _ = Query().
			Select("a").Arg("arg", "one").
			Select("b").Arg("arg", "two").
			build(context.Background())
	}
}

benchcmp results:

% benchcmp old new 
benchcmp is deprecated in favor of benchstat: https://pkg.go.dev/golang.org/x/perf/cmd/benchstat
benchmark                      old ns/op     new ns/op     delta
BenchmarkBuilder-8     11363         10839         -4.61%

benchmark                      old allocs     new allocs     delta
BenchmarkBuilder-8     88             76             -13.64%

benchmark                      old bytes     new bytes     delta
BenchmarkBuilder-8     3232          2849          -11.85%

@matiasinsaurralde
matiasinsaurralde force-pushed the querybuilder-improvement branch from 27d371e to 34c1beb Compare April 24, 2023 20:23
@matiasinsaurralde
matiasinsaurralde force-pushed the querybuilder-improvement branch from 13f21b4 to dbf97c6 Compare April 24, 2023 20:25

@vito vito left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks! 🎉

@vito
vito merged commit e42b05b into dagger:main Apr 24, 2023
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