BridgeJS: Perf-tune SwiftToSkeleton by avoiding unnecessary Syntax node allocation#577
Merged
kateinoigakukun merged 1 commit intomainfrom Feb 4, 2026
Merged
Conversation
…node allocation
`trimmedDescription` allocates two new Syntax nodes just to get the
trimmed description of a node.
```swift
extension SyntaxProtocol {
public var trimmedDescription: String {
// TODO: We shouldn't need to create to copies just to get the trimmed
// description.
return self.trimmed.description
}
public var trimmed: Self {
// TODO: Should only need one new node here
return self.with(\.leadingTrivia, []).with(\.trailingTrivia, [])
}
}
```
```
$ cat check.d.ts
export function getCanvas(x: string): HTMLCanvasElement;
$ node Plugins/BridgeJS/Sources/TS2Swift/JavaScript/bin/ts2swift.js check.d.ts -p tsconfig.json -o out.swift
$ hyperfine "./Plugins/BridgeJS/.build/debug/BridgeJSToolInternal.before emit-skeleton out.swift" "./Plugins/BridgeJS/.build/debug/BridgeJSToolInternal.after emit-skeleton out.swift"
Benchmark 1: ./Plugins/BridgeJS/.build/debug/BridgeJSToolInternal.before emit-skeleton out.swift
Time (mean ± σ): 16.531 s ± 0.317 s [User: 16.355 s, System: 0.107 s]
Range (min … max): 16.026 s … 17.252 s 10 runs
Benchmark 2: ./Plugins/BridgeJS/.build/debug/BridgeJSToolInternal.after emit-skeleton out.swift
Time (mean ± σ): 4.068 s ± 0.134 s [User: 3.976 s, System: 0.039 s]
Range (min … max): 4.000 s … 4.445 s 10 runs
Summary
./Plugins/BridgeJS/.build/debug/BridgeJSToolInternal.after emit-skeleton out.swift ran
4.06 ± 0.15 times faster than ./Plugins/BridgeJS/.build/debug/BridgeJSToolInternal.before emit-skeleton out.swift
```
MaxDesiatov
approved these changes
Feb 4, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
trimmedDescriptionallocates two new Syntax nodes just to get the trimmed description of a node.It speeds up 4x faster