Commit 81885ea
authored
BridgeJS: Perf-tune
`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
```SwiftToSkeleton by avoiding unnecessary Syntax node allocation (#577)1 parent 56aabfa commit 81885ea
File tree
1 file changed
+19
-17
lines changed- Plugins/BridgeJS/Sources/BridgeJSCore
1 file changed
+19
-17
lines changedLines changed: 19 additions & 17 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
394 | 394 | | |
395 | 395 | | |
396 | 396 | | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
397 | 405 | | |
398 | 406 | | |
399 | 407 | | |
400 | 408 | | |
401 | 409 | | |
402 | 410 | | |
403 | | - | |
404 | | - | |
405 | | - | |
| 411 | + | |
406 | 412 | | |
407 | 413 | | |
408 | 414 | | |
409 | 415 | | |
410 | 416 | | |
411 | 417 | | |
412 | | - | |
| 418 | + | |
413 | 419 | | |
414 | 420 | | |
415 | 421 | | |
| |||
1916 | 1922 | | |
1917 | 1923 | | |
1918 | 1924 | | |
1919 | | - | |
1920 | | - | |
1921 | | - | |
| 1925 | + | |
1922 | 1926 | | |
1923 | 1927 | | |
1924 | 1928 | | |
1925 | 1929 | | |
1926 | 1930 | | |
1927 | 1931 | | |
1928 | 1932 | | |
1929 | | - | |
1930 | | - | |
1931 | | - | |
| 1933 | + | |
1932 | 1934 | | |
1933 | 1935 | | |
1934 | 1936 | | |
1935 | 1937 | | |
1936 | 1938 | | |
1937 | 1939 | | |
1938 | 1940 | | |
1939 | | - | |
1940 | | - | |
1941 | | - | |
| 1941 | + | |
1942 | 1942 | | |
1943 | 1943 | | |
1944 | 1944 | | |
1945 | 1945 | | |
1946 | 1946 | | |
1947 | 1947 | | |
1948 | 1948 | | |
1949 | | - | |
1950 | | - | |
1951 | | - | |
| 1949 | + | |
| 1950 | + | |
| 1951 | + | |
| 1952 | + | |
| 1953 | + | |
1952 | 1954 | | |
1953 | 1955 | | |
1954 | 1956 | | |
1955 | 1957 | | |
1956 | 1958 | | |
1957 | 1959 | | |
1958 | | - | |
| 1960 | + | |
1959 | 1961 | | |
1960 | 1962 | | |
1961 | 1963 | | |
| |||
0 commit comments