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

Some small optimisations #3261

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

peterebden
Copy link
Member

Reduces one allocation in provideFor and a few other things in paths of varying temperatures (notably getting rid of fmt.Sprintf which isn't the most efficient way to put strings together, although it is fairly concise).
Before:

INFO: Run 1 of 5
INFO: Complete in 9.62s, using 6172140 KB
INFO: Run 2 of 5
INFO: Complete in 9.18s, using 5655136 KB
INFO: Run 3 of 5
INFO: Complete in 9.62s, using 6437840 KB
INFO: Run 4 of 5
INFO: Complete in 9.68s, using 6682404 KB
INFO: Run 5 of 5
INFO: Complete in 9.61s, using 6525640 KB
INFO: Complete, median time: 9.62s, median mem: 6437840.00 KB

After:

INFO: Run 1 of 5
INFO: Complete in 9.42s, using 6408832 KB
INFO: Run 2 of 5
INFO: Complete in 9.30s, using 6354172 KB
INFO: Run 3 of 5
INFO: Complete in 9.18s, using 6287200 KB
INFO: Run 4 of 5
INFO: Complete in 9.28s, using 5919368 KB
INFO: Run 5 of 5
INFO: Complete in 9.40s, using 6682712 KB
INFO: Complete, median time: 9.30s, median mem: 6354172.00 KB

@toastwaffle
Copy link
Contributor

What benchmark are you running in your before/after?

@@ -108,10 +108,19 @@ func resolvePluginValue(values []string, subrepo string) []string {
continue // I guess it wasn't a build label. Leave it alone.
}
// Force the full build label including empty subrepo so this is portable
v = fmt.Sprintf("///%v//%v:%v", l.Subrepo, l.PackageName, l.Name)
var buf strings.Builder
Copy link
Contributor

Choose a reason for hiding this comment

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

This is pretty unwieldy. Are we really calling this so frequently that it's worth making the code that much more complicated?

I'd expect under most circumstances the vast majority of wall-clock time to be spent on the build steps themselves, rather than anything to do with parsing BUILD files?

Copy link
Contributor

Choose a reason for hiding this comment

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

Or even just using string concatenation:

v = `///`+l.Subrepo+`//`+l.PackageName+`:`+l.Name

But this won't call into the Stringer interface if any of these variables aren't a string.

Copy link
Member Author

Choose a reason for hiding this comment

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

It's called a lot more often than you'd expect. The way subrepos + plugins work with go_repo each being their own subrepo, it's called often.

I'd expect under most circumstances the vast majority of wall-clock time to be spent on the build steps themselves, rather than anything to do with parsing BUILD files?

Well it depends what you're doing. Things like plz query changes are usually blocked by parsing files.

@peterebden
Copy link
Member Author

What benchmark are you running in your before/after?

The performance one we run after merge (//tools/performance:parse_perf_test)

@@ -108,10 +108,19 @@ func resolvePluginValue(values []string, subrepo string) []string {
continue // I guess it wasn't a build label. Leave it alone.
}
// Force the full build label including empty subrepo so this is portable
v = fmt.Sprintf("///%v//%v:%v", l.Subrepo, l.PackageName, l.Name)
var buf strings.Builder
Copy link
Contributor

Choose a reason for hiding this comment

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

Add a comment here (or at the top of the file) to explain why you're not using fmt.Sprintf

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.

3 participants