Skip to content

Commit a01ba7c

Browse files
authored
Optimize CcInfo computation (#4020)
This shows up around 4% of buildbuddy analysis phase <img width="1728" alt="image" src="https://github.com/user-attachments/assets/18344d22-ea21-4dbf-8542-2cf2763fa2ba"> After this change, it goes away. It seems like Bazel is able to make this lazy, which is good since it's only used for building LINKMODE_C_ARCHIVE/LINKMODE_C_SHARED which is fairly rare. **What type of PR is this?** Performance improvement **What does this PR do? Why is it needed?** Avoid computing CcInfo for every intermediate library when it's not needed **Which issues(s) does this PR fix?** Fixes # **Other notes for review**
1 parent aa96a11 commit a01ba7c

File tree

6 files changed

+312
-303
lines changed

6 files changed

+312
-303
lines changed

docs/go/core/rules.md

Lines changed: 37 additions & 37 deletions
Large diffs are not rendered by default.

go/private/common.bzl

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -172,12 +172,6 @@ def as_tuple(v):
172172
return tuple(v.to_list())
173173
fail("as_tuple failed on {}".format(v))
174174

175-
_STRUCT_TYPE = type(struct())
176-
177-
def is_struct(v):
178-
"""Returns true if v is a struct."""
179-
return type(v) == _STRUCT_TYPE
180-
181175
def count_group_matches(v, prefix, suffix):
182176
"""Counts reluctant substring matches between prefix and suffix.
183177

go/private/context.bzl

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ load(
4949
"COVERAGE_OPTIONS_DENYLIST",
5050
"GO_TOOLCHAIN",
5151
"as_iterable",
52-
"is_struct",
5352
)
5453
load(
5554
":mode.bzl",
@@ -282,7 +281,6 @@ def _library_to_source(go, attr, library, coverage_instrumented):
282281
"cxxopts": _expand_opts(go, "cxxopts", getattr(attr, "cxxopts", [])),
283282
"clinkopts": _expand_opts(go, "clinkopts", getattr(attr, "clinkopts", [])),
284283
"cgo_exports": [],
285-
"cc_info": None,
286284
"pgoprofile": getattr(attr, "pgoprofile", None),
287285
}
288286

@@ -310,11 +308,10 @@ def _library_to_source(go, attr, library, coverage_instrumented):
310308
# sources. compilepkg will catch these instead.
311309
if f.extension in ("c", "cc", "cxx", "cpp", "hh", "hpp", "hxx"):
312310
fail("source {} has C/C++ extension, but cgo was not enabled (set 'cgo = True')".format(f.path))
311+
313312
if library.resolve:
314313
library.resolve(go, attr, source, _merge_embed)
315314

316-
source["cc_info"] = _collect_cc_infos(attr_deps + generated_deps, source["cdeps"])
317-
318315
return GoSource(**source)
319316

320317
def _collect_runfiles(go, data, deps):
@@ -327,19 +324,6 @@ def _collect_runfiles(go, data, deps):
327324
[get_source(t).runfiles for t in deps],
328325
)
329326

330-
def _collect_cc_infos(deps, cdeps):
331-
cc_infos = []
332-
for dep in cdeps:
333-
if CcInfo in dep:
334-
cc_infos.append(dep[CcInfo])
335-
for dep in deps:
336-
# dep may be a struct, which doesn't support indexing by providers.
337-
if is_struct(dep):
338-
continue
339-
if GoSource in dep:
340-
cc_infos.append(dep[GoSource].cc_info)
341-
return cc_common.merge_cc_infos(cc_infos = cc_infos)
342-
343327
def _check_binary_dep(go, dep, edge):
344328
"""Checks that this rule doesn't depend on a go_binary or go_test.
345329

go/private/providers.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
# A represenatation of the inputs to a go package.
15+
# A representation of the inputs to a go package.
1616
# This is a configuration independent provider.
1717
# You must call resolve with a mode to produce a GoSource.
1818
# See go/providers.rst#GoLibrary for full documentation.

0 commit comments

Comments
 (0)