Skip to content

Commit d896480

Browse files
mkruskal-googlecopybara-github
authored andcommitted
Add weak attribute to GetClassData to speed up clang builds.
This results in roughly a 2x speedup and memory reduction, which recovers a big chunk of the 4x regression observed in Chromium after some of our refactorings over the last few years. PiperOrigin-RevId: 746158016
1 parent 1c87ac3 commit d896480

File tree

5 files changed

+100
-43
lines changed

5 files changed

+100
-43
lines changed

src/google/protobuf/compiler/cpp/message.cc

+18-2
Original file line numberDiff line numberDiff line change
@@ -4178,7 +4178,15 @@ void MessageGenerator::GenerateClassData(io::Printer* p) {
41784178
$pbi$::ClassDataFull $classname$_class_data_ =
41794179
$classname$::InternalGenerateClassData_();
41804180
4181-
const $pbi$::ClassData* $nonnull$ $classname$::GetClassData() const {
4181+
//~ This function needs to be marked as weak to avoid significantly
4182+
//~ slowing down compilation times. This breaks up LLVM's SCC
4183+
//~ in the .pb.cc translation units. Large translation units see a
4184+
//~ reduction of roughly 50% of walltime for optimized builds.
4185+
//~ Without the weak attribute all the messages in the file, including
4186+
//~ all the vtables and everything they use become part of the same
4187+
//~ SCC.
4188+
PROTOBUF_ATTRIBUTE_WEAK const $pbi$::ClassData* $nonnull$
4189+
$classname$::GetClassData() const {
41824190
$pin_weak_descriptor$;
41834191
$pbi$::PrefetchToLocalCache(&$classname$_class_data_);
41844192
$pbi$::PrefetchToLocalCache($classname$_class_data_.tc_table);
@@ -4221,7 +4229,15 @@ void MessageGenerator::GenerateClassData(io::Printer* p) {
42214229
const $pbi$::ClassDataLite<$type_size$> $classname$_class_data_ =
42224230
$classname$::InternalGenerateClassData_();
42234231
4224-
const $pbi$::ClassData* $nonnull$ $classname$::GetClassData() const {
4232+
//~ This function needs to be marked as weak to avoid significantly
4233+
//~ slowing down compilation times. This breaks up LLVM's SCC
4234+
//~ in the .pb.cc translation units. Large translation units see a
4235+
//~ reduction of roughly 50% of walltime for optimized builds.
4236+
//~ Without the weak attribute all the messages in the file, including
4237+
//~ all the vtables and everything they use become part of the same
4238+
//~ SCC.
4239+
PROTOBUF_ATTRIBUTE_WEAK const $pbi$::ClassData* $nonnull$
4240+
$classname$::GetClassData() const {
42254241
return $classname$_class_data_.base();
42264242
}
42274243
)cc");

src/google/protobuf/compiler/java/java_features.pb.cc

+4-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/google/protobuf/compiler/plugin.pb.cc

+8-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/google/protobuf/cpp_features.pb.cc

+2-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)