Skip to content

Conversation

@emir-karabeg
Copy link
Collaborator

@emir-karabeg emir-karabeg commented Jan 30, 2026

Summary

Addresses a timing discrepancy where fast-executing blocks, particularly the "start" block, would often report 0ms or inconsistent durations due to the millisecond precision of Date.now(). This PR replaces Date.now() with performance.now() for all execution timing measurements in the block executor and engine, providing sub-millisecond precision for accurate duration tracking.

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation
  • Other: ___________

Testing

The changes were verified by:

  • Running all existing engine tests (29 tests)
  • Running all existing start-block tests (8 tests)
  • Passing lint checks
  • Passing TypeScript type checks

Reviewers should focus on ensuring that the switch to performance.now() does not introduce any unexpected side effects in timing calculations or logging, particularly regarding the endTime which now uses new Date().toISOString() for the timestamp while performance.now() is used for duration calculation.

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

Screenshots/Videos


Open in Cursor Open in Web

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>
@cursor
Copy link

cursor bot commented Jan 30, 2026

Cursor Agent can help with this pull request. Just @cursor in comments and I'll start working on changes in this branch.
Learn more about Cursor Agents

@vercel
Copy link

vercel bot commented Jan 30, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
docs Skipped Skipped Jan 30, 2026 8:44pm

Request Review

@emir-karabeg emir-karabeg changed the title Start block precision fix(terminal): start precision Jan 30, 2026
@emir-karabeg
Copy link
Collaborator Author

@greptile

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Jan 30, 2026

Greptile Overview

Greptile Summary

This PR improves timing precision in block execution by replacing Date.now() with performance.now() for all duration measurements.

Key Changes:

  • block-executor.ts: Updated 3 timing measurements (line 74, 148, 224) to use performance.now() for block execution duration tracking
  • engine.ts: Updated execution duration tracking (lines 104, 128, 149, 436) while correctly preserving Date.now() for cancellation check intervals (line 81)

Implementation Details:

  • performance.now() provides sub-millisecond precision (microseconds) vs Date.now()'s millisecond precision
  • Duration calculations now use performance.now() for startTime and endTime
  • ISO timestamp for metadata.endTime correctly changed from new Date(endTime).toISOString() to new Date().toISOString() since performance.now() returns elapsed time, not epoch time
  • Cancellation interval checking appropriately kept Date.now() as it needs wall-clock time

Impact:
Fast-executing blocks (especially the "start" block) will now show accurate sub-millisecond durations instead of often reporting 0ms.

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • The changes are surgical and well-contained. The PR correctly distinguishes between duration measurement (now using performance.now()) and wall-clock time intervals (correctly kept as Date.now()). All tests pass, the implementation properly handles the epoch-time vs elapsed-time distinction for timestamps, and the changes only affect timing precision without altering any business logic.
  • No files require special attention

Important Files Changed

Filename Overview
apps/sim/executor/execution/block-executor.ts replaced Date.now() with performance.now() for precise block execution timing (3 instances)
apps/sim/executor/execution/engine.ts replaced Date.now() with performance.now() for precise workflow execution duration, correctly preserved Date.now() for cancellation check intervals

Sequence Diagram

sequenceDiagram
    participant Client
    participant Engine as ExecutionEngine
    participant BlockExec as BlockExecutor
    participant Handler as BlockHandler
    
    Client->>Engine: run(triggerBlockId?)
    Note over Engine: startTime = performance.now()
    
    Engine->>Engine: initializeQueue()
    
    loop While has work
        Engine->>Engine: processQueue()
        Engine->>Engine: executeNodeAsync(nodeId)
        Engine->>BlockExec: execute(ctx, node, block)
        Note over BlockExec: startTime = performance.now()
        
        BlockExec->>BlockExec: resolveInputs()
        BlockExec->>Handler: execute(ctx, block, inputs)
        Handler-->>BlockExec: output
        
        Note over BlockExec: duration = performance.now() - startTime
        BlockExec->>BlockExec: Update blockLog with duration
        BlockExec-->>Engine: NormalizedBlockOutput
        
        Engine->>Engine: handleNodeCompletion()
    end
    
    Note over Engine: endTime = performance.now()<br/>duration = endTime - startTime<br/>metadata.endTime = new Date().toISOString()
    Engine-->>Client: ExecutionResult with precise duration
Loading

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 files reviewed, no comments

Edit Code Review Agent Settings | Greptile

@waleedlatif1 waleedlatif1 marked this pull request as ready for review January 30, 2026 20:21
Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 files reviewed, no comments

Edit Code Review Agent Settings | Greptile

…l started/ended times on server and passback to clinet
@waleedlatif1
Copy link
Collaborator

@cursor review

@waleedlatif1 waleedlatif1 merged commit 2c4eb9f into staging Jan 30, 2026
11 checks passed
@waleedlatif1 waleedlatif1 deleted the cursor/start-block-precision-28b8 branch January 30, 2026 20:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants