You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[CGData] Lazy loading support for stable function map
The stable function map could be huge for a large application. Fully
loading it is slow and consumes a significant amount of memory, which
is unnecessary and drastically slows down compilation especially for
non-LTO and distributed-ThinLTO setups. This patch introduces an
opt-in lazy loading support for the stable function map. The detailed
changes are:
- `StableFunctionMap`
- The map now stores entries in an `EntryStorage` struct, which
includes offsets for serialized entries and a `std::once_flag`
for thread-safe lazy loading.
- The underlying map type is changed from `DenseMap` to
`std::unordered_map` for compatibility with `std::once_flag`.
- `contains()`, `size()` and `at()` are implemented to only
load requested entries on demand.
- Lazy Loading Mechanism
- When reading indexed codegen data, if the newly-introduced
`-indexed-codegen-data-lazy-loading` flag is set, the stable
function map is not fully deserialized up front. The binary format
for the stable function map now includes offsets and sizes to
support lazy loading.
- The safety of lazy loading is guarded by the once flag per function
hash. This guarantees that even in a multi-threaded environment, the
deserialization for a given function hash will happen exactly once.
The first thread to request it performs the load, and subsequent
threads will wait for it to complete before using the data. For
single-threaded builds, the overhead is negligible (a single check
on the once flag). For multi-threaded scenarios, users can omit the
flag to retain the previous eager-loading behavior.
0 commit comments