This is a test post to preview how different markdown features render.
Headings
Third level
Fourth level
Text formatting
This is a paragraph with bold text, italic text, and inline code. Here’s a link to GitHub and some strikethrough text.
This is a blockquote. It can span multiple lines and is useful for highlighting important information or quoting someone.
Code blocks
@attached(peer, names: arbitrary)
public macro Modifier() = #externalMacro(
module: "ModifierMacroMacros",
type: "ModifierMacro"
)
public struct ModifierMacro: PeerMacro {
public static func expansion(
of node: AttributeSyntax,
providingPeersOf declaration: some DeclSyntaxProtocol,
in context: some MacroExpansionContext
) throws -> [DeclSyntax] {
guard let varDecl = declaration.as(VariableDeclSyntax.self) else {
return []
}
return [DeclSyntax(stringLiteral: "// generated")]
}
}def generate_large_macro(num_modifiers: int):
content = "import ModifierMacro\n\nstruct Button {\n"
for i in range(num_modifiers):
content += f" @Modifier private var modifier{i}: Double = 0.0\n"
content += "}\n"
return contentLists
Unordered:
- First item
- Second item with a longer description that wraps to the next line
- Third item
- Nested item
- Another nested item
Ordered:
- Clone the repo
- Run
swift build -c release - Execute the benchmark
- Check
results.json
Table
| Scenario | Files | Modifiers | Time |
|---|---|---|---|
| Default | 1 | 1 | 0.42s |
| Macro | 1 | 1 | 0.89s |
| Large Default | 1 | 2000 | 3.21s |
| Large Macro | 1 | 2000 | 4.67s |
| Multi-file | 100 | 20 each | 5.12s |
| Multi-file Macro | 100 | 20 each | 7.34s |
Mermaid diagram
graph LR
A[Source Code] --> B[SourceKit]
B --> C[Module Interface]
C --> D[SwiftSyntax Rewriter]
D --> E[Interface Module]Horizontal rule
Image
Task list
- Set up blog
- Customize theme
- Write first real post
- Cross-post to Medium
Footnote
Swift macros expand at compile time1, which means their cost is paid on every build.
Footnotes
-
See the Swift Evolution proposal SE-0389 for details on the macro system. ↩