[libcxx-commits] [PATCH] D157298: [RFC][libc++] Reduce the size of translation units
Mark de Wever via Phabricator via libcxx-commits
libcxx-commits at lists.llvm.org
Mon Aug 7 10:12:24 PDT 2023
Mordante created this revision.
Herald added a project: All.
Mordante requested review of this revision.
Herald added a reviewer: jdoerfert.
Herald added subscribers: libcxx-commits, jplehr, sstefan1.
Herald added a project: libc++.
Herald added a reviewer: libc++.
The C++ standard library adds new features in every C++ version. To
implement these new features libc++ adds more includes to a header. This
means the number of transitive includes grows with newer language version.
The growing size is an issue for users. This change is motivated by a
report of the Chromium team where properly enabling C++23's
std::formatter<std::vector<bool>::reference> had a significant impact on
their build time.
In D149543 <https://reviews.llvm.org/D149543> Hans Wennborg reported the following
In Chromium we noticed that this almost doubled the preprocessed size
of <vector>, from ca 1.6 MB to 3.2 MB. Since it's a widely included
header, that results in ca 8 GB (2.5%) of extra code to compile during a
full build.
This is an experiment to see how libc++ can reduce this size by only
"enabling" headers per language version. This is mainly done at the level
of the granularized includes, since they often have features for one or a
limited set of minimum language versions.
The compare header is an exception, its inclusion is often mandated by the
standard so this header is entirely guarded by C++20 or newer.
At the moment the removed transitive includes are not conditionally
restored like we usually do; this is intentional for the RFC. It gives a
good view what changes.
For this patch only vector is adjusted and mainly based on what I recall
being based on a language version.
I did some testing with the size of a preprocessed file that contains
#include <vector>
I used the following command
clang++ -E test.cpp -nostdinc++ -I <build>/include/c++/v1" -I -std=$std |wc -l
| Version | Before | After |
| ---------+--------+------- |
| C++03 | 53153 | 38721 |
| C++11 | 55665 | 40914 |
| C++14 | 56709 | 41896 |
| C++17 | 60591 | 44957 |
| C++20 | 75905 | 75863 |
| C++23 | 61867 | 61828 |
| C++26 | 61867 | 61828 |
|
The interesting value is C++23 (before) there the size drops a lot. In
C++23 some transitive includes are removed unconditionally. These can be
removed with a build option. The Chromimum team uses this option. This is
done by the following command
clang++ -E test.cpp -nostdinc++ -I <build>/include/c++/v1" -I -std=$std -D_LIBCPP_REMOVE_TRANSITIVE_INCLUDES |wc -l
| Version | Before | After |
| ---------+--------+------- |
| C++03 | 45883 | 18482 |
| C++11 | 48366 | 19352 |
| C++14 | 49352 | 19745 |
| C++17 | 51590 | 22331 |
| C++20 | 61259 | 61217 |
| C++23 | 61867 | 61828 |
| C++26 | 61867 | 61828 |
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D157298
Files:
libcxx/include/__algorithm/lexicographical_compare_three_way.h
libcxx/include/__concepts/same_as.h
libcxx/include/__format/enable_insertable.h
libcxx/include/__format/formatter.h
libcxx/include/__format/formatter_bool.h
libcxx/include/__memory_resource/polymorphic_allocator.h
libcxx/include/__ranges/access.h
libcxx/include/__ranges/concepts.h
libcxx/include/__ranges/container_compatible_range.h
libcxx/include/__ranges/from_range.h
libcxx/include/__ranges/size.h
libcxx/include/compare
libcxx/test/libcxx/transitive_includes/cxx03.csv
libcxx/test/libcxx/transitive_includes/cxx11.csv
libcxx/test/libcxx/transitive_includes/cxx14.csv
libcxx/test/libcxx/transitive_includes/cxx17.csv
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D157298.547836.patch
Type: text/x-patch
Size: 24703 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20230807/f2f18c45/attachment-0001.bin>
More information about the libcxx-commits
mailing list