Skip to content

Protocol conformance cache for generic types #82818

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

DmT021
Copy link
Contributor

@DmT021 DmT021 commented Jul 5, 2025

This change adds a new type of cache (cache by type descriptor) to the protocol conformance lookup system. This optimization is particularly beneficial for generic types, where the same conformance can be reused across different instantiations of the generic type.

Key changes:

  • Add a GetOrInsertManyScope class to ConcurrentReadableHashMap for performing multiple insertions under a single lock
  • Add type descriptor-based caching for protocol conformances
  • Add environment variables for controlling and debugging the conformance cache
  • Add tests to verify the behavior of the conformance cache

The implementation is controlled by the SWIFT_DEBUG_ENABLE_CACHE_PROTOCOL_CONFORMANCES_BY_TYPE_DESCRIPTOR environment variable, which is enabled by default.

@DmT021
Copy link
Contributor Author

DmT021 commented Jul 5, 2025

@swift-ci please test

@DmT021
Copy link
Contributor Author

DmT021 commented Jul 5, 2025

@swift-ci Please benchmark

This change adds a new type of cache (cache by type descriptor) to the protocol conformance lookup system. This optimization is particularly beneficial for generic types, where the
same conformance can be reused across different instantiations of the generic type.

Key changes:
- Add a `GetOrInsertManyScope` class to `ConcurrentReadableHashMap` for performing
  multiple insertions under a single lock
- Add type descriptor-based caching for protocol conformances
- Add environment variables for controlling and debugging the conformance cache
- Add tests to verify the behavior of the conformance cache

The implementation is controlled by the `SWIFT_DEBUG_ENABLE_CACHE_PROTOCOL_CONFORMANCES_BY_TYPE_DESCRIPTOR`
environment variable, which is enabled by default.
@DmT021 DmT021 force-pushed the wp/conformance-cache-by-descriptor branch from 712d217 to 645d438 Compare July 6, 2025 03:38
@DmT021
Copy link
Contributor Author

DmT021 commented Jul 6, 2025

@swift-ci please test

@DmT021
Copy link
Contributor Author

DmT021 commented Jul 6, 2025

@swift-ci please smoke test

@DmT021
Copy link
Contributor Author

DmT021 commented Jul 6, 2025

@swift-ci please test macOS

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant