You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: DatadogSessionReplay/Sources/Recorder/ViewTreeSnapshotProducer/ViewTreeSnapshot/NodeRecorders/SwiftUI/ShapeResource.swift
+6-11Lines changed: 6 additions & 11 deletions
Original file line number
Diff line number
Diff line change
@@ -7,10 +7,7 @@
7
7
#if os(iOS)
8
8
9
9
import SwiftUI
10
-
11
-
#if canImport(CryptoKit)
12
-
import CryptoKit
13
-
#endif
10
+
import CommonCrypto
14
11
15
12
@available(iOS 13.0,*)
16
13
internalfinalclassShapeResource:NSObject{
@@ -24,13 +21,11 @@ internal final class ShapeResource: NSObject {
Copy file name to clipboardExpand all lines: DatadogSessionReplay/Sources/Recorder/ViewTreeSnapshotProducer/ViewTreeSnapshot/NodeRecorders/SwiftUI/ShapeResourceBuilder.swift
+33Lines changed: 33 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -9,8 +9,14 @@
9
9
import Foundation
10
10
import SwiftUI
11
11
12
+
/// A performance-optimized builder for creating SVG-based shape resources from SwiftUI paths.
13
+
///
14
+
/// `ShapeResourceBuilder` implements a multi-level caching strategy to eliminate expensive
15
+
/// recomputations during UI updates and scrolling animations. This addresses performance
16
+
/// issues that can occur when the same shapes are rendered repeatedly in Session Replay.
12
17
@available(iOS 13.0,*)
13
18
internalfinalclassShapeResourceBuilder{
19
+
/// Cache key for SwiftUI path data, used to avoid redundant SVG path string generation.
14
20
privateclassPathKey:NSObject{
15
21
privateletpath:SwiftUI.Path
16
22
@@ -32,6 +38,7 @@ internal final class ShapeResourceBuilder {
32
38
}
33
39
}
34
40
41
+
/// Composite cache key for complete shape resources, incorporating all visual properties.
35
42
privateclassResourceKey:NSObject{
36
43
privateletpath:SwiftUI.Path
37
44
privateletcolor:ResolvedPaint
@@ -71,14 +78,33 @@ internal final class ShapeResourceBuilder {
71
78
}
72
79
}
73
80
81
+
/// Cache for SVG path data strings, preventing redundant path-to-SVG conversions.
74
82
privateletpathCache=NSCache<PathKey,NSString>()
83
+
84
+
/// Cache for complete shape resources, avoiding full SVG generation and hashing.
Copy file name to clipboardExpand all lines: DatadogSessionReplay/Tests/Recorder/ViewTreeSnapshotProducer/ViewTreeSnapshot/NodeRecorders/SwiftUI/ShapeResourceBuilderTests.swift
+17Lines changed: 17 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -115,6 +115,23 @@ final class ShapeResourceBuilderTests: XCTestCase {
0 commit comments