Skip to content

Promises: bound host rejection queue draining #874

Description

@chrisbbreuer

Parent: #493
Related: #474, #480, #482, #495

Problem

The realm-local unhandled- and handled-rejection queues are growable arrays, but each host checkpoint removes index zero with orderedRemove(0). The private ABI drains those functions in a loop, so N JavaScript-created rejection notifications copy Θ(N²) Promise pointers while repeatedly holding realm_lock. Rejection fanout is script-controlled, making this an avoidable latency and contention surface.

Required implementation

  • Replace front-removal with an exact FIFO cursor so each queued Promise is consumed in O(1) amortized work and event order is unchanged.
  • Reset the cursor and logical storage as soon as the queue is exhausted, reusing bounded retained capacity rather than retaining consumed logical entries indefinitely.
  • Trace and relocate only pending queue entries while preserving precise Promise rooting, early-handled skipping, one-time notification state, and realm-lock synchronization.
  • Preserve reentrant behavior: rejection callbacks may enqueue more notifications, which must follow the already-pending FIFO entries and drain in the same checkpoint.
  • Do not reverse events, use unordered removal, cap valid fanout, defer required notifications, weaken locking, or add workload-recognizing paths.

Acceptance

  • A deterministic wide-queue witness proves dequeue advances a cursor without shifting the backing prefix and resets exactly at exhaustion.
  • Unhandled and later-handled notifications retain FIFO order, early-handled entries are skipped, and reentrant enqueues follow pending entries.
  • Precise tracing and moving relocation cover pending entries without retaining consumed prefixes as roots.
  • Empty, repeated, OOM, teardown, and bounded-capacity lifecycle paths remain exact.
  • Focused Promise/private-ABI tests pass in Debug, ReleaseSafe, and suppression-free TSan; relevant threadfuzz and the full unit suite have zero failures/leaks.
  • Exact affected Test262 Promise coverage has zero regressions; documentation states the bounded FIFO contract without unsupported throughput claims.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions