Skip to content

Commit e875533

Browse files
authored
[perf]: a couple more micro optimizations (#334)
small changes to: 1. avoid an unnecessary buffer copy during render() when updating event pipes 2. allow our 'session' id generation to wrap so it doesn't need to perform bounds checks (it functionally cannot overflow so they are unneeded)
1 parent 97beb1d commit e875533

File tree

2 files changed

+8
-10
lines changed

2 files changed

+8
-10
lines changed

Diff for: Workflow/Sources/SubtreeManager.swift

+7-9
Original file line numberDiff line numberDiff line change
@@ -82,15 +82,19 @@ extension WorkflowNode {
8282
childWorkflows = context.usedChildWorkflows
8383
sideEffectLifetimes = context.usedSideEffectLifetimes
8484

85-
/// Captured the reusable sinks from this render pass.
85+
/// Capture the reusable sinks from this render pass.
8686
previousSinks = context.sinkStore.usedSinks
8787

8888
/// Capture all the pipes to be enabled after render completes.
8989
eventPipes = context.eventPipes
90-
eventPipes.append(contentsOf: context.sinkStore.eventPipes)
90+
for (_, sink) in context.sinkStore.usedSinks {
91+
eventPipes.append(sink.eventPipe)
92+
}
9193

9294
/// Set all event pipes to `pending`.
93-
eventPipes.forEach { $0.setPending() }
95+
for eventPipe in eventPipes {
96+
eventPipe.setPending()
97+
}
9498

9599
/// Return the rendered result
96100
return rendering
@@ -288,12 +292,6 @@ extension WorkflowNode.SubtreeManager {
288292

289293
extension WorkflowNode.SubtreeManager {
290294
fileprivate struct SinkStore {
291-
var eventPipes: [EventPipe] {
292-
usedSinks.values.map { reusableSink -> EventPipe in
293-
reusableSink.eventPipe
294-
}
295-
}
296-
297295
private var previousSinks: [ObjectIdentifier: AnyReusableSink]
298296
private(set) var usedSinks: [ObjectIdentifier: AnyReusableSink]
299297

Diff for: Workflow/Sources/WorkflowObserver.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public struct WorkflowSession {
107107
private static var _nextRawID: UInt64 = 0
108108
private static func _makeNextSessionID() -> UInt64 {
109109
let nextID = _nextRawID
110-
_nextRawID += 1
110+
_nextRawID &+= 1
111111
return nextID
112112
}
113113

0 commit comments

Comments
 (0)