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
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ genrule(
plugins = {
"python": "v1.7.3",
"java": "v0.4.2",
"go": "v1.21.4",
"go": "v1.21.5",
"cc": "v0.4.0",
"shell": "v0.2.0",
"go-proto": "v0.3.0",
Expand Down
7 changes: 4 additions & 3 deletions src/core/build_target.go
Original file line number Diff line number Diff line change
Expand Up @@ -1193,7 +1193,7 @@ func (target *BuildTarget) AddProvide(language string, labels []BuildLabel) {
if target.Provides == nil {
target.Provides = map[string][]BuildLabel{language: labels}
} else {
target.Provides[language] = labels
target.Provides[language] = slices.Clip(labels) // Clip so we don't have issues appending in provideFor
}
}

Expand Down Expand Up @@ -1227,9 +1227,10 @@ func (target *BuildTarget) provideFor(other *BuildTarget) ([]BuildLabel, bool) {
for _, require := range other.Requires {
if label, present := target.Provides[require]; present {
if ret == nil {
ret = make([]BuildLabel, 0, len(other.Requires))
ret = label
} else {
ret = append(ret, label...)
}
ret = append(ret, label...)
found = true
}
}
Expand Down
21 changes: 15 additions & 6 deletions src/parse/asp/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.

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

buf.Grow(len(l.Subrepo) + len(l.PackageName) + len(l.Name) + len(annotation) + 7) // +7 for the delimiters
buf.WriteString("///")
buf.WriteString(l.Subrepo)
buf.WriteString("//")
buf.WriteString(l.PackageName)
buf.WriteByte(':')
buf.WriteString(l.Name)
if annotation != "" {
v = fmt.Sprintf("%v|%v", v, annotation)
buf.WriteByte('|')
buf.WriteString(annotation)
}
v = buf.String()
}
ret[i] = v
}
Expand Down Expand Up @@ -155,7 +164,7 @@ func pluginConfig(pluginState *core.BuildState, pkgState *core.BuildState) pyDic
continue
}

fullConfigKey := fmt.Sprintf("%v.%v", pluginName, configKey)
fullConfigKey := pluginName + "." + configKey
value, ok := extraVals[strings.ToLower(configKey)]
if !ok {
// The default values are defined in the subrepo so should be parsed in that scope
Expand Down Expand Up @@ -230,9 +239,9 @@ func toPyObject(key, val, toType string, optional bool) pyObject {
case "bool":
switch strings.ToLower(val) {
case "true", "yes", "on", "1":
return pyBool(true)
return True
case "false", "no", "off", "0":
return pyBool(false)
return False
default:
log.Fatalf("%s: invalid bool value: %v", key, val)
return pyNone{}
Expand All @@ -243,7 +252,7 @@ func toPyObject(key, val, toType string, optional bool) pyObject {
log.Fatalf("%s: invalid int value: %v", key, val)
return pyNone{}
}
return pyInt(i)
return newPyInt(i)
default:
log.Fatalf("%s: invalid plugin configuration field type: %v", key, toType)
return pyNone{}
Expand Down
Loading