# Smaller debug info with constructor type homing

DevFeed: [Smaller debug info with constructor type homing](<https://devfeed.tech/articles/smaller-debug-info-with-constructor-type-homing-43079.md>)

Original publisher: [Read original article](<https://blog.llvm.org/posts/2021-04-05-constructor-homing-for-debug-info/>)

Author: Amy Huang

Published: 2021-04-05T00:00:00Z

Content type: article

Language: en

Sources: [LLVM Project](<https://devfeed.tech/sources/the-llvm-project-blog.md>)

Topics: [C++](<https://devfeed.tech/topics/c-plus-plus.md>), [clang](<https://devfeed.tech/topics/clang.md>), [Optimization](<https://devfeed.tech/topics/optimization.md>), [constructor](<https://devfeed.tech/topics/constructor.md>), [class](<https://devfeed.tech/topics/class.md>)

Tags: [c-plus-plus](<https://devfeed.tech/tags/c-plus-plus.md>), [clang](<https://devfeed.tech/tags/clang.md>), [class](<https://devfeed.tech/tags/class.md>), [constructor](<https://devfeed.tech/tags/constructor.md>), [debug](<https://devfeed.tech/tags/debug.md>), [llvm](<https://devfeed.tech/tags/llvm.md>), [optimization](<https://devfeed.tech/tags/optimization.md>)

## AI overview

This article explains constructor type homing, a Clang optimization that reduces C++ debug information by emitting class type information where constructor definitions are emitted instead of in every compilation unit. It also describes the classes to which the optimization does not apply and how it can be enabled.

## Source excerpt

Constructor type homing for debug infoBackground Class type information is a large contributor to debug info size. Clang already has a few optimizations to reduce the size of class type information based on the assumption that debug info can be spread out over multiple compilation units. So, instead of emitting class type info in every compilation unit that references a class, we only really have to emit it in one place. (For all the other references, emitting the much smaller forward declaration of the class is sufficient.) As an example, one of the existing optimizations is vtable homing, where the type info for a dynamic C++ class is only emitted when its vtable is emitted. Constructor type homing Constructor homing is a similar optimization that applies to almost all classes with constructors. It emits type information for a class wherever its constructor definition is emitted. Unlike with vtable homing, the type info for a class could be emitted more than once, but it has a large impact on debug info because it applies to a large percentage of classes. If all of a class's constructors are defined out of line, the class type information will only be emitted once. If there are constructors defined inline, the inline constructors, and therefore class type information, will be emitted in every compilation unit that calls a constructor. Constructor homing assumes that if a user wants a class to have debug info, then that class was constructed somewhere in the program. This is a reasonable assumption to make, as classes viewed in the debugger probably exist in program memory, and any class that exists in memory must have been constructed. Even though all classes have constructors, there are some types of classes that constructor homing doesn't apply to: trivial classes, aggregate classes, and classes with constexpr constructors. It's possible to create instances of these classes without emitting a constructor, so we can't guarantee that the debug info will be emitted