xref: /openbmc/bmcweb/HEADERS.md (revision f263e09c)
1# bmcweb headers
2
3**Why does bmcweb use so many headers? My build times are slow!**
4
5TL;DR, History
6
7bmcweb at one point was a crow-based project. Evidence of this can still be seen
8in the http/.hpp files that still contain references to the crow namespaces.
9Crow makes heavy use of headers and template meta programming, and doesn't ship
10any cpp or implementation files, choosing to put everything in include once
11headers. As bmcweb evolved, it needed more capabilities, so the core was ported
12to Boost Beast, and what remains has very little similarity to crow anymore.
13Boost::beast at the time we ported took the same opinion, relying on header
14files and almost no implementation compile units. A large amount of the compile
15time is taken up in boost::beast template instantiations, specifically for
16boost::beast::http::message (ie Request and Response).
17
18The initial solution that gets proposed is to just move everything as it exists
19to separate compile units, making no other changes. This has been proposed and
20implemented 3-4 times in the project, the latest of which is below. The intent
21of this document is largely to save effort for the next person, so they can at
22least start from the existing prior attempts.
23
24<https://gerrit.openbmc.org/c/openbmc/bmcweb/+/49039>
25
26Moving to cpp files without handling any architecture has the net result of
27making total compilation slower, not faster, as the slowest-to-compile parts end
28up getting compiled multiple times, then the duplicates deleted at link time.
29This isn't great for the end result.
30
31To actually effect the result that we'd like to see from multiple compile units,
32there have been proposed a few ideas might provide some relief;
33
34- Moving the Request and Response containers to opaque structures, so a majority
35  of code only needs to #include the interface, not any of the template code.
36  <https://gerrit.openbmc.org/c/openbmc/bmcweb/+/37445> Doing this exposed a
37  number of mediocre practices in the route handlers, where routes made copies
38  of requests/responses, relied on APIs that should've been internal, and other
39  practices that make this migration less straightforward, but is still being
40  pursued by maintainers over time.
41- Moving the internals of Request/Response/Connection to rely on something like
42  [http::proto](https://github.com/CPPAlliance/http_proto) which, written by the
43  same author as boost::beast, claims to have significant reduction in compile
44  time templates, and might not require abstracting the Request/Response
45  objects.
46- Reduce the bmcweb binary size to the point where link time optimization is not
47  required for most usages. About half of the bmcweb build time is spent doing
48  link time optimization, which, as of this time is required to keep bmcweb code
49  small enough to deploy on an actual BMCs (See DEVELOPING.md for details). One
50  could theoretically determine the source of where LTO decreases the binary
51  size the most, and ensure that those were all in the same compile unit, such
52  that they got optimized without requiring LTO.
53