TimedParallelMap

foresight.eqsat.parallel.TimedParallelMap
final class TimedParallelMap(val name: String, inner: ParallelMap) extends ParallelMap

A ParallelMap decorator that records wall-clock timing for mapping and ad-hoc tasks.

TimedParallelMap captures elapsed time for both this node and its entire subtree of child strategies created via child. Timing is computed as:

  • Start: the earliest System.nanoTime() observed among this node and all of its children during any call to apply or run.
  • End: the latest System.nanoTime() observed among this node and all of its children.
  • nanos returns End - Start. Overlapping child work is not double-counted; this is wall-clock duration, not a sum of per-task CPU times.

Typical usage

val pm: ParallelMap = ParallelMap.parallel
val timed = new TimedParallelMap("root", pm)

val child = timed.child("phase-1")
val out   = child(Seq(1,2,3), _ * 2)   // work to be timed under "phase-1"

val report: TimingReport = timed.report
println(report.pretty)                 // or however you surface it

Thread safety

All timing state and the child list are protected by an internal java.util.concurrent.locks.ReentrantLock. You may call apply, run, child, nanos, and report concurrently from multiple threads.

Overhead

Timing introduces one System.nanoTime() pair per apply/run call and a few lock acquisitions. For extremely fine-grained tasks, prefer timing fewer, larger phases.

Value parameters

inner

The underlying strategy to which work is delegated.

name

Logical name for this timing node (used in report).

Attributes

Graph
Supertypes
trait ParallelMap
class Object
trait Matchable
class Any

Members list

Value members

Concrete methods

override def apply[A, B](inputs: Iterable[A], f: A => B): Iterable[B]

Delegates to the inner strategy while recording a timing window for this node.

Delegates to the inner strategy while recording a timing window for this node.

Attributes

Definition Classes
override def child(name: String): ParallelMap

Creates a named child timing node that delegates work to the same underlying strategy.

Creates a named child timing node that delegates work to the same underlying strategy.

The child contributes to this node's overall timing window (see nanos).

Attributes

Definition Classes

The immediate child timing nodes created from this strategy via child.

The immediate child timing nodes created from this strategy via child.

Returned as an immutable snapshot.

Attributes

def nanos: Long

Wall-clock elapsed time (in nanoseconds) covered by this node and all of its descendants.

Wall-clock elapsed time (in nanoseconds) covered by this node and all of its descendants.

Defined as max(endTimes) - min(startTimes) across the subtree. If no work has been recorded yet (no apply or run was called on this node or its children), returns 0.

Attributes

Builds a hierarchical TimingReport for this node and its children.

Builds a hierarchical TimingReport for this node and its children.

The report captures each node's name and elapsed wall-clock time (via nanos) and then runs a simplification pass (see TimingReport.simplify) to collapse trivial structure.

Attributes

override def run[A](f: => A): A

Delegates to the inner strategy while recording a timing window for this node.

Delegates to the inner strategy while recording a timing window for this node.

Attributes

Definition Classes

Inherited methods

Returns a view of this strategy that cooperatively cancels work using the given token.

Returns a view of this strategy that cooperatively cancels work using the given token.

Semantics:

  • If the token is canceled before work begins, no work is performed and an OperationCanceledException is thrown immediately.
  • While mapping, cancellation is observed at wrapper checkpoints (see below). When detected, an OperationCanceledException is thrown and remaining work is skipped.

Checkpoints added by this wrapper:

  • One check before the mapping starts.
  • One check before processing each input element.

Important:

  • The wrapper does not interrupt user code while running a single element function f. If f can run for a long time, pass the token into f and poll it inside f to achieve finer-grained cancellation.

Example:

val token = new CancellationToken
token.cancelAfter(30.seconds)                 // common "set and forget" timeout

val pm = ParallelMap.parallel.cancelable(token)
val out = pm(items, { a =>
 // Optional finer-grained check inside user code
 if (token.isCanceled) throw OperationCanceledException(token)
 compute(a)
})

Composition:

  • Children created via child inherit cancellation by wrapping the parent's child.
  • Can be combined with timed; timing still reflects the work up to cancellation.

Value parameters

token

Cancellation trigger to observe.

Attributes

Returns

A new ParallelMap that observes the token at the described checkpoints.

Throws
OperationCanceledException

if the token is canceled before start or at any checkpoint.

Inherited from:
ParallelMap
final def timed: TimedParallelMap

Wraps this strategy to record execution times.

Wraps this strategy to record execution times.

Useful for profiling or monitoring performance. Timing starts at the root and can be nested for child strategies.

Attributes

Returns

A TimedParallelMap that records elapsed times.

Inherited from:
ParallelMap

Concrete fields

val name: String