mirror of
https://github.com/apple/swift-nio.git
synced 2026-05-20 20:30:36 +00:00
abe4f1bcb6
Motivation: Public static lets can serve a bunch of roles, but one of them is to store simple constants: integers, and other trivial types, for example. This is a nice pattern and for internal and private static lets it works well, but for public ones it produces some inefficient code. In particular, it has two downsides. First, it allocates storage for that value. We don't actually need to allocate a few hundred extra megabytes for the various integers we want to store. Secondly, it forces calling code to access the address and call the dispatch_once code in order to get hold of the value. For trivial types we don't need that cost: they can just know what the value is directly. Inlinable computed vars avoid all of these costs: they have no size overhead for storage, and they are visible to all clients so their values can be directly assembled. While I'm here, I added a bunch of other inlinable annotations for a few trivial data types I stumbled onto. Modifications: - Added loads of inlinables. Like, loads. - Swapped many static lets to static vars. Result: Better codegen, smaller memory footprints, more attributes.