Skip to content

[PluginMessageHandling] Cache decoded StaticBuildConfiguration - #3468

Merged
rintaro merged 1 commit into
swiftlang:mainfrom
rintaro:cache-static-build-config-decode
Oct 9, 2026
Merged

rintaro merged 1 commit into
swiftlang:mainfrom
rintaro:cache-static-build-config-decode

Conversation

@rintaro

@rintaro rintaro commented Oct 8, 2026

Copy link
Copy Markdown
Member

PluginProviderMessageHandler decoded the static build configuration JSON for every expandFreestandingMacro / expandAttachedMacro message, even though a compiler sends the same configuration for the whole compile.

This change keeps the decoded configurations in a small LRUCache keyed by their JSON representation, so a configuration is decoded once and reused for later messages that carry the same JSON. A single handler can serve multiple compiler instances with different configurations, so the cache keeps more than the most recent one:

Configurations that fail to decode still produce nil and are not cached.

Related: swiftlang/swift#93083, which builds the configuration and its JSON once per ASTContext.

rdar://189539737

PluginProviderMessageHandler decoded the static build configuration
JSON for every expandFreestandingMacro and expandAttachedMacro message,
even though a compiler sends the same configuration for the whole
compile. Keep the decoded configurations in a small LRU cache keyed by
their JSON representation.

A single handler can serve multiple compiler instances with different
configurations, e.g. through SourceKit's shared plugin registry or the
process-wide in-process plugin server, so the cache keeps more than
the most recent configuration.

rdar://189539737
@rintaro

rintaro commented Oct 8, 2026

Copy link
Copy Markdown
Member Author

@swift-ci Please test

@rintaro

rintaro commented Oct 8, 2026

Copy link
Copy Markdown
Member Author

@swift-ci Please test macOS

@rintaro

rintaro commented Oct 8, 2026

Copy link
Copy Markdown
Member Author

@swift-ci Please test Linux

@hamishknight hamishknight left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Depending on how expensive this is, I wonder if it would be worth seeing if we could hash the configuration on the compiler side, and send that hash along with the configuration? That way the plugin is still a pure function but doesn't have to keep re-hashing the same (potentially quite large) string

@rintaro

rintaro commented Oct 8, 2026

Copy link
Copy Markdown
Member Author

@swift-ci Please test Linux

@rintaro

rintaro commented Oct 8, 2026

Copy link
Copy Markdown
Member Author

swiftlang/swift#93092
@swift-ci Please test Linux

@rintaro

rintaro commented Oct 8, 2026

Copy link
Copy Markdown
Member Author

swiftlang/swift#93092
@swift-ci Please test Windows

@rintaro
rintaro merged commit be54987 into swiftlang:main Oct 9, 2026
42 checks passed
@rintaro
rintaro deleted the cache-static-build-config-decode branch October 9, 2026 20:54
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.

2 participants