Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Package.resolved

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions Sources/OpenSwiftUI/App/AppGraph.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ package final class AppGraph: GraphHost {
return
}
if launchProfileOptions.contains(.profile) {
OGGraph.startProfiling()
Graph.startProfiling()
}
}

Expand All @@ -58,11 +58,11 @@ package final class AppGraph: GraphHost {
}
didCollectLaunchProfile = true
if launchProfileOptions.contains(.profile) {
OGGraph.stopProfiling()
Graph.stopProfiling()
}
if !launchProfileOptions.isEmpty {
// /tmp/graph.ag-gzon
OGGraph.archiveJSON(name: nil)
Graph.archiveJSON(name: nil)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,10 +261,10 @@ extension BodyAccessor {
@inline(__always)
package func setBody(_ body: () -> Body) {
let value = traceRuleBody(Container.self) {
OGGraph.withoutUpdate(body)
Graph.withoutUpdate(body)
}
withUnsafePointer(to: value) { value in
OGGraph.setOutputValue(value)
Graph.setOutputValue(value)
}
}
}
Expand Down
10 changes: 9 additions & 1 deletion Sources/OpenSwiftUICore/OpenGraph/Graph/Graph+OpenSwiftUI.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
import OpenGraphShims

extension Graph {}
extension Graph {
static func startTracing(options: Graph.TraceFlags?) {
Graph.startTracing(nil, options: options ?? ProcessEnvironment.tracingOptions)
}

static func stopTracing() {
Graph.stopTracing(nil)
}
}
75 changes: 57 additions & 18 deletions Sources/OpenSwiftUICore/Test/Benchmark.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,29 @@
// Benchmark.swift
// OpenSwiftUICore
//
// Audited for iOS 18.0
// Status: WIP
// Status: Complete
// ID: 3E629D505F0A70F29ACFC010AA42C6E0 (SwiftUI)
// ID: 5BCCF82F8606CD0B3127FDEEA7C13601 (SwiftUICore)

public import Foundation
#if canImport(QuartzCore)
import QuartzCore
#endif
import OpenGraphShims

// MARK: - Benchmark [6.4.41]

@available(OpenSwiftUI_v1_0, *)
public protocol _BenchmarkHost: AnyObject {
func _renderForTest(interval: Double)

@available(OpenSwiftUI_v3_0, *)
func _renderAsyncForTest(interval: Double) -> Bool

func _performScrollTest(startOffset: CGFloat, iterations: Int, delta: CGFloat, length: CGFloat, completion: (() -> Void)?)
}

@available(OpenSwiftUI_v1_0, *)
public protocol _Benchmark: _Test {
func measure(host: _BenchmarkHost) -> [Double]
}
Expand All @@ -26,31 +33,30 @@ package var enableProfiler = EnvironmentHelper.bool(for: "OPENSWIFTUI_PROFILE_BE

package var enableTracer = EnvironmentHelper.bool(for: "OPENSWIFTUI_TRACE_BENCHMARKS")

@available(OpenSwiftUI_v1_0, *)
extension _BenchmarkHost {
@available(OpenSwiftUI_v1_0, *)
public func _renderAsyncForTest(interval _: Double) -> Bool {
false
}

public func _performScrollTest(startOffset _: CGFloat, iterations _: Int, delta _: CGFloat, length _: CGFloat, completion _: (() -> Void)?) {}

public func measureAction(action: () -> Void) -> Double {
// WIP: trace support
#if canImport(QuartzCore)
let begin = CACurrentMediaTime()
if enableProfiler,
let renderHost = self as? ViewRendererHost {
renderHost.startProfiling()
let begin = Time.systemUptime
if enableTracer {
Graph.startTracing(options: nil)
} else if enableProfiler {
(self as? ViewRendererHost)?.startProfiling()
}
action()
let end = CACurrentMediaTime()
if enableProfiler,
let renderHost = self as? ViewRendererHost {
renderHost.stopProfiling()
let end = Time.systemUptime
if enableTracer {
Graph.stopTracing()
} else if enableProfiler {
(self as? ViewRendererHost)?.stopProfiling()
}
return end - begin
#else
preconditionFailure("Unsupported Platfrom")
#endif
}

public func measureRender(interval: Double = 1.0 / 60.0) -> Double {
Expand All @@ -75,14 +81,47 @@ extension _BenchmarkHost {
}
}

// WIP
package func summarize(_ measurements: [(any _Benchmark, [Double])]) -> String {
preconditionFailure("TODO")
let benchmarkData = measurements.map { (String(describing: $0.0), $0.1) }

let maxNameLength = benchmarkData.map { $0.0.count }.max() ?? 0

let results: [String] = benchmarkData.map { (name, values) in
let padding = maxNameLength - name.count + 1
let paddingString = String(repeating: " ", count: padding)

let average = values.reduce(0, +) / Double(values.count)
let milliseconds = average * 1000.0

return "\(name)\(paddingString): \(String(format: "%.3f", milliseconds))ms"
}
return results.joined(separator: "\n")
}

package func write(_ measurements: [(any _Benchmark, [Double])], to path: String) throws {
preconditionFailure("TODO")
let dictionary = Dictionary(uniqueKeysWithValues: measurements.map { (String(describing: $0), $1) })
let data = try JSONSerialization.data(withJSONObject: dictionary, options: .prettyPrinted)
let manager = FileManager.default
let directory = (path as NSString).deletingLastPathComponent
try manager.createDirectory(atPath: directory, withIntermediateDirectories: true)
try data.write(to: URL(fileURLWithPath: path))
}

package func log(_ measurements: [(any _Benchmark, [Double])]) {
preconditionFailure("TODO")
print(summarize(measurements))
let path: String
if CommandLine.arguments.count < 2 {
let formatter = DateFormatter()
formatter.dateFormat = "yyyy-MM-dd-HHmmss"
path = "/tmp/org.OpenSwiftUIProject.OpenSwiftUI/Benchmarks/\(formatter.string(from: Date())).json"
} else {
path = CommandLine.arguments[1]
}
print(path)
do {
try write(measurements, to: path)
} catch {
Log.internalError(error.localizedDescription)
}
}
3 changes: 2 additions & 1 deletion Sources/OpenSwiftUICore/Test/Test.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
// Test.swift
// OpenSwiftUICore
//
// Audited for iOS 18.0
// Status: Complete

// MARK: - _Test [6.4.41]

public protocol _Test {
func setUpTest()
func tearDownTest()
Expand Down
2 changes: 2 additions & 0 deletions Sources/OpenSwiftUICore/Test/TestApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ public struct _TestApp {

package static func setTestEnvironment(_ environment: EnvironmentValues?) {
// TODO
host?.environmentOverride = environment
comparisonHost?.environmentOverride = environment
}

package static func updateTestEnvironment(_ body: (inout EnvironmentValues) -> Void) {
Expand Down
10 changes: 4 additions & 6 deletions Sources/OpenSwiftUICore/Test/TestIDView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@
// TestIDView.swift
// OpenSwiftUICore
//
// Audited for iOS 18.0
// Status: Complete
// ID: CC151E1A36B4405FF56CDABA5D46BF1E (SwiftUICore)

import OpenGraphShims

// MARK: - TestIDView + View extension
// MARK: - TestIDView + View extension [6.4.41]

@_spi(Testing)
@available(OpenSwiftUI_v2_0, *)
Expand All @@ -18,21 +17,20 @@ extension View {
}
}

// MARK: - TestIDView
// MARK: - TestIDView [6.4.41]

@_spi(Testing)
@available(OpenSwiftUI_v2_0, *)
public struct TestIDView<Content, ID>: PrimitiveView, UnaryView where Content: View, ID: Hashable {
public var content: Content

public var id: ID

nonisolated public static func _makeView(view: _GraphValue<Self>, inputs: _ViewInputs) -> _ViewOutputs {
let view = _GraphValue(IdentifiedView(view: view.value, id: nil))
return Content.makeDebuggableView(view: view, inputs: inputs)
}

public typealias Body = Never


private struct IdentifiedView: StatefulRule, AsyncAttribute, IdentifierProvider, CustomStringConvertible {
@Attribute var view: TestIDView
var id: ID?
Expand Down
3 changes: 2 additions & 1 deletion Sources/OpenSwiftUICore/Util/EnvironmentHelper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import WASILibc
#else
#error("Unsupported Platform")
#endif
import OpenGraphShims

package enum EnvironmentHelper {
@_transparent
Expand Down Expand Up @@ -50,5 +51,5 @@ package enum ProcessEnvironment {
return UInt32(atoi(env))
}

// package static let tracingOptions: OGGraphTraceFlags = .init(rawValue: uint32(forKey: "SWIFTUI_TRACE"))
static let tracingOptions: Graph.TraceFlags = .init(rawValue: uint32(forKey: "OPENSWIFTUI_TRACE"))
}
2 changes: 1 addition & 1 deletion Sources/OpenSwiftUICore/View/Graph/ViewGraph.swift
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ package final class ViewGraph: GraphHost {
self.rootViewType = rootViewType
self.requestedOutputs = requestedOutputs
let data = GraphHost.Data()
OGSubgraph.current = data.globalSubgraph
Subgraph.current = data.globalSubgraph
rootView = Attribute(type: Root.self).identifier
_rootTransform = Attribute(RootTransform())
_transform = _rootTransform
Expand Down