Skip to content

Commit 4953262

Browse files
fix(executor): use performance.now() for precise block timing
Replace Date.now() with performance.now() for timing measurements in the executor to provide sub-millisecond precision. This fixes timing discrepancies with fast-executing blocks like the start block where millisecond precision was insufficient. Changes: - block-executor.ts: Use performance.now() for block execution timing - engine.ts: Use performance.now() for overall execution timing Co-authored-by: emir <emir@simstudio.ai>
1 parent f718079 commit 4953262

2 files changed

Lines changed: 10 additions & 10 deletions

File tree

apps/sim/executor/execution/block-executor.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ export class BlockExecutor {
7171
this.callOnBlockStart(ctx, node, block)
7272
}
7373

74-
const startTime = Date.now()
74+
const startTime = performance.now()
7575
let resolvedInputs: Record<string, any> = {}
7676

7777
const nodeMetadata = this.buildNodeMetadata(node)
@@ -145,7 +145,7 @@ export class BlockExecutor {
145145
})) as NormalizedBlockOutput
146146
}
147147

148-
const duration = Date.now() - startTime
148+
const duration = performance.now() - startTime
149149

150150
if (blockLog) {
151151
blockLog.endedAt = new Date().toISOString()
@@ -221,7 +221,7 @@ export class BlockExecutor {
221221
isSentinel: boolean,
222222
phase: 'input_resolution' | 'execution'
223223
): NormalizedBlockOutput {
224-
const duration = Date.now() - startTime
224+
const duration = performance.now() - startTime
225225
const errorMessage = normalizeError(error)
226226
const hasResolvedInputs =
227227
resolvedInputs && typeof resolvedInputs === 'object' && Object.keys(resolvedInputs).length > 0

apps/sim/executor/execution/engine.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ export class ExecutionEngine {
101101
}
102102

103103
async run(triggerBlockId?: string): Promise<ExecutionResult> {
104-
const startTime = Date.now()
104+
const startTime = performance.now()
105105
try {
106106
this.initializeQueue(triggerBlockId)
107107

@@ -125,8 +125,8 @@ export class ExecutionEngine {
125125
return this.buildPausedResult(startTime)
126126
}
127127

128-
const endTime = Date.now()
129-
this.context.metadata.endTime = new Date(endTime).toISOString()
128+
const endTime = performance.now()
129+
this.context.metadata.endTime = new Date().toISOString()
130130
this.context.metadata.duration = endTime - startTime
131131

132132
if (this.cancelledFlag) {
@@ -146,8 +146,8 @@ export class ExecutionEngine {
146146
metadata: this.context.metadata,
147147
}
148148
} catch (error) {
149-
const endTime = Date.now()
150-
this.context.metadata.endTime = new Date(endTime).toISOString()
149+
const endTime = performance.now()
150+
this.context.metadata.endTime = new Date().toISOString()
151151
this.context.metadata.duration = endTime - startTime
152152

153153
if (this.cancelledFlag) {
@@ -433,8 +433,8 @@ export class ExecutionEngine {
433433
}
434434

435435
private buildPausedResult(startTime: number): ExecutionResult {
436-
const endTime = Date.now()
437-
this.context.metadata.endTime = new Date(endTime).toISOString()
436+
const endTime = performance.now()
437+
this.context.metadata.endTime = new Date().toISOString()
438438
this.context.metadata.duration = endTime - startTime
439439
this.context.metadata.status = 'paused'
440440

0 commit comments

Comments
 (0)