Skip to content

Commit f35b110

Browse files
committed
[Runtime] Support precomputed protocol conformances in the shared cache.
When available, take advantage of precomputed protocol conformances in the shared cache on Darwin platforms to accelerate conformance lookups and cut down on memory usage. We consult the precomputed conformances before doing the runtime's standard conformance lookup. When a conformance is precomputed, this avoids the slow linear scan of all loaded conformances for the first access, and it avoids the memory cost of storing the conformance in the cache. When the shared cache has no images overridden (the normal case), then we can also skip scanning conformances in the shared cache in all circumstances, because the precomputed conformances will always cover those results. This greatly speeds up the slow linear scan for the initial lookup of anything that doesn't have a conformance in the shared cache, including lookups with conformances in apps or app frameworks, and negative lookups. A validation mode is available by setting the SWIFT_DEBUG_VALIDATE_SHARED_CACHE_PROTOCOL_CONFORMANCES environment variable. When enabled, results from the precomputed conformances are compared with the results from a slow scan of the conformances in the shared cache. This extremely slow, but good at catching bugs in the system. When the calls for precomputed conformances are unavailable, the new code is omitted and we remain in the same situation as before, with the runtime performing all lookups by scanning conformance sections in all loaded Swift images. rdar://71128983
1 parent ffeb1d5 commit f35b110

File tree

2 files changed

+349
-41
lines changed

2 files changed

+349
-41
lines changed

stdlib/public/runtime/EnvironmentVariables.def

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,12 @@ VARIABLE(SWIFT_DEBUG_ENABLE_MALLOC_SCRIBBLE, bool, false,
4747
VARIABLE(SWIFT_DEBUG_ENABLE_COW_CHECKS, bool, false,
4848
"Enable internal checks for copy-on-write operations.")
4949

50+
#if defined(__APPLE__) && defined(__MACH__)
51+
52+
VARIABLE(SWIFT_DEBUG_VALIDATE_SHARED_CACHE_PROTOCOL_CONFORMANCES, bool, false,
53+
"Validate shared cache protocol conformance results against the "
54+
"lists of conformances in the shared cache images.")
55+
56+
#endif
57+
5058
#undef VARIABLE

0 commit comments

Comments
 (0)