Dart / Integration: targets, resources, validation, and evidence / Lesson 21
Isolate CPU work behind a measurable boundary
Move a small pure calculation to an isolate, verify the result, and account for platform and lifecycle costs.
On this page
Lesson goals
- Identify a suitable CPU-bound calculation.
- Await isolate completion and handle failure.
- Compare correctness and overhead with a local baseline.
- Compare local and isolate results for a bounded pure calculation before measuring.
- Design an evidence-based worker experiment including transfer, lifecycle and target limits.
Choose a boundary
An isolate is useful when suitable CPU-bound work would otherwise block the current event loop, but moving work adds startup and message-transfer costs. Begin with a pure calculation whose inputs and output are explicit. The sum-of-squares example is deliberately tiny for explanation, not a claim that isolation makes it faster. Check that the target platform and declared Dart SDK support the chosen isolate API.
Run the calculation
The first program imports dart:isolate and awaits Isolate.run for a calculation of 1² + 2² + 3². The expected result is 14. Awaiting ties the result to main; a real caller should also handle errors and define what happens if its owner is disposed. Keep messages and captured state small and compatible with the API’s transfer rules. Do not assume ordinary mutable state is shared like a local reference.
import "dart:isolate";
int sumSquares(int n) {
var total = 0;
for (var i = 1; i <= n; i++) {
total += i * i;
}
return total;
}
Future<void> main() async {
final result = await Isolate.run(() => sumSquares(3));
print(result);
}
Isolate.run returns a Future for the calculation; the caller awaits the result.
Establish a local correctness baseline
The second independent program tests the same pure function locally for inputs three and zero. These assertions illustrate expected behavior; use a test framework and enable appropriate assertions in a real check. Compare the isolate result with the local result for representative inputs before measuring performance. A correct local function does not by itself prove resource cleanup or platform support for the isolate path.
int sumSquares(int n) {
var total = 0;
for (var i = 1; i <= n; i++) {
total += i * i;
}
return total;
}
void main() {
assert(sumSquares(3) == 14);
assert(sumSquares(0) == 0);
}
Known small inputs provide a correctness baseline independent of isolate scheduling.
Account for lifecycle and effects
Pure computation is easier to move because it avoids sharing ownership of files, sockets, or user-interface state. If work needs external resources, define which isolate opens and closes them and how errors and cancellation are reported. A timed-out caller does not necessarily prove work has stopped or that an external effect was reversed. Use a worker lifecycle design suited to the application rather than treating the example as a complete job system.
Measure and verify
Test zero, a small known result, invalid input according to a stated contract, and a worker error. Measure a representative workload both locally and in the isolate under the same conditions, including startup and transfer. Check responsiveness and total completion time separately. Record the SDK, platform, and workload, and avoid claiming a universal speedup from a single run or this tiny example.
Select a pure computation boundary
A Future represents eventual completion but async alone does not move a CPU loop to another isolate. A long synchronous calculation can delay the current isolate’s event processing. On a supporting native target, Isolate.run can execute a suitable one-shot computation in a new isolate and return its result through a Future. The computation should have explicit inputs, output and failure rules, and the caller must await or return the Future.
The sum-of-squares function is small enough to reason about, not evidence that a worker improves performance. Define its input domain: for this lesson n is a nonnegative integer and negative input is rejected. Start with a local correctness baseline for zero and small known values. A real computation may require bounds to avoid excessive work or arithmetic issues on its actual target.
Respect transfer and ownership
Isolates do not share an ordinary mutable object graph like local aliases. Inputs and results must satisfy the selected API’s sendability and transfer rules. A closure can capture more surrounding state than expected, including an unsendable client or large object graph. Prefer a small explicit payload and a pure function, and review the actual Isolate.run contract for the target and SDK.
The caller owns the returned Future and must handle a worker error. A timeout changes the caller’s wait but does not generally prove that the computation or an external effect stopped. For longer-lived workers, define ports, request identity, shutdown and pending-caller outcomes. A one-shot local example does not establish a durable job system or external resource cleanup.
Prove comparable results before timing
Run the same pure function locally and through the worker using identical inputs and domain rules. Verify zero, small known values, the boundary and invalid input before comparing performance. For n=3 the sum is 1 + 4 + 9 = 14; for n=0 the empty sum is 0. An explicit runtime guard is preferable to an assertion-only validation when negative values must always be rejected.
A worker failure must reach the result owner, not become a plausible successful number. If results differ, investigate correctness before interpreting timings. Control input generation and avoid changing the calculation between baseline and worker. The small result verifies only the stated fixture; it does not establish numeric safety for every input or target.
Measure the whole decision
Compare a representative synchronous baseline and isolate path under the same target, SDK, workload and input distribution. Include isolate startup, data transfer, result delivery and cleanup in end-to-end completion time. Measure responsiveness separately from total latency: a worker may improve the main event loop’s responsiveness while increasing total elapsed time for a small task.
Use an appropriate warmup and multiple observations, report variation and workload characteristics, and account for system load and measurement overhead. Avoid inferring a universal crossover point from one run. A bounded worker pool may amortize setup for repeated tasks but adds queueing, lifecycle and failure policies; measure the actual design rather than assuming a benefit.
Report only observed evidence
This lesson provides synthetic source and a measurement plan. Isolate and scheduler-sensitive programs remain runnable:false unless the exact block is qualified in an authorized controlled environment. No timing, worker throughput, responsiveness, transfer or cancellation result is claimed here. A synchronous local fixture can be qualified separately without implying that the isolate path was run.
Record the exact SDK, platform, source, workload, commands, correctness results and observed measurements. State what was not tested, including browser support or real resource lifecycle. A passing local arithmetic test is necessary evidence for the policy but does not establish worker reliability, service authorization or production capacity.
Walk through correctness before measurement
The pure sumSquares function rejects a negative input and otherwise accumulates squares from 1 through n. The local path computes 14 for n=3. The worker path calls the same function with the same input through Isolate.run, and the caller awaits the result before comparing it. The reasoned output is true then 14. The typed catch illustrates one input-error boundary; a real owner must also account for other worker failures.
This fixture does not measure time, transfer size or responsiveness and remains unexecuted as an isolate example. A representative experiment should test multiple inputs and include startup and transfer, then report actual target and variation. It does not perform I/O or establish browser support, durable delivery or a production worker lifecycle.
import 'dart:isolate';
int sumSquares(int n) {
if (n < 0) throw ArgumentError.value(n, 'n');
var total = 0;
for (var i = 1; i <= n; i++) {
total += i * i;
}
return total;
}
Future<void> main() async {
try {
final local = sumSquares(3);
final worker = await Isolate.run(() => sumSquares(3));
print(local == worker);
print(worker);
} on ArgumentError {
print('invalid input');
}
}
true
14
Both paths are intended to compute 14 for the same input; the isolate result is reasoned and unexecuted.
20 worked examples
1. Compute the empty sum
Problem: Evaluate the local baseline for n=0.
- The loop has no integers from 1 through 0.
- The initial total remains zero.
int sumSquares(int n) { if (n < 0) throw ArgumentError.value(n); var total = 0; for (var i = 1; i <= n; i++) { total += i * i; } return total; }
void main() { print(sumSquares(0)); }
0
The empty input has a defined additive result. The exact program produced the shown output with Dart 3.13.7 on Linux x64.
Why this result follows: The empty input has a defined additive result.
2. Compute one square
Problem: Evaluate the local baseline for n=1.
- The loop visits only integer 1.
- Its square contributes 1 to the total.
int sumSquares(int n) { if (n < 0) throw ArgumentError.value(n); var total = 0; for (var i = 1; i <= n; i++) { total += i * i; } return total; }
void main() { print(sumSquares(1)); }
1
A small known value checks the lower nonempty boundary. The exact program produced the shown output with Dart 3.13.7 on Linux x64.
Why this result follows: A small known value checks the lower nonempty boundary.
3. Compute four squares
Problem: Calculate the local result for n=4.
- The squares are 1, 4, 9 and 16.
- Their sum is 30.
int sumSquares(int n) { if (n < 0) throw ArgumentError.value(n); var total = 0; for (var i = 1; i <= n; i++) { total += i * i; } return total; }
void main() { print(sumSquares(4)); }
30
A known result checks the loop’s accumulation. The exact program produced the shown output with Dart 3.13.7 on Linux x64.
Why this result follows: A known result checks the loop’s accumulation.
4. Reject a negative input
Problem: Apply the stated nonnegative input contract.
- The guard detects n=-1 before entering the loop.
- It throws ArgumentError, which the local handler reports as invalid.
int sumSquares(int n) { if (n < 0) throw ArgumentError.value(n); var total = 0; for (var i = 1; i <= n; i++) { total += i * i; } return total; }
void main() { try { sumSquares(-1); } on ArgumentError { print('invalid'); } }
invalid
An explicit guard enforces the domain at runtime. The exact program produced the shown output with Dart 3.13.7 on Linux x64.
Why this result follows: An explicit guard enforces the domain at runtime.
5. Establish a local baseline
Problem: Check two known results without using an isolate.
- The local function should return 0 for n=0 and 5 for n=2.
- A mismatch throws instead of producing a misleading pass marker.
int sumSquares(int n) { if (n < 0) throw ArgumentError.value(n); var total = 0; for (var i = 1; i <= n; i++) { total += i * i; } return total; }
void main() {
if (sumSquares(0) != 0 || sumSquares(2) != 5) throw StateError('mismatch');
print('baseline ok');
}
baseline ok
A correctness baseline precedes performance comparison. The exact program produced the shown output with Dart 3.13.7 on Linux x64.
Why this result follows: A correctness baseline precedes performance comparison.
6. Await a one-shot isolate result
Problem: Move the same pure calculation to Isolate.run on a supporting target.
- The worker computes sumSquares(3), whose reasoned value is 14.
- The caller awaits the returned Future before using that value.
final result = await Isolate.run(() => sumSquares(3));
print(result);
An explicit isolate boundary differs from async syntax alone. Exact qualification is recorded separately.
Expected result: The reasoned result is 14.
Why this result follows: An explicit isolate boundary differs from async syntax alone.
7. Own a worker failure
Problem: Specify an error boundary for a failing isolate computation.
- The worker Future can complete with an error.
- The owner awaits it inside a handler or propagates the error to its caller.
try {
final value = await Isolate.run(compute);
use(value);
} catch (error, stack) {
report(error, stack);
}
Failure ownership is part of the worker contract. Exact qualification is recorded separately.
Expected result: The worker error has an owner.
Why this result follows: Failure ownership is part of the worker contract.
8. Pass small explicit data
Problem: Choose a worker input containing only the values needed for a sum.
- The calculation needs the integer list [2, 3, 4].
- The payload excludes an unrelated client and its resource graph.
worker input: [2, 3, 4]
excluded: caller-owned network client
Explicit inputs make transfer and ownership easier to review. Exact qualification is recorded separately.
Expected result: Only the required data is transferred under the API contract.
Why this result follows: Explicit inputs make transfer and ownership easier to review.
9. Avoid closure overcapture
Problem: Repair a computation that captures a large resource owner.
- The closure needs only a count but references its surrounding service.
- Move the pure function to an appropriate boundary and pass the count explicitly.
caller owns: service and count
worker needs: count only
repair: explicit count input
Narrow capture reduces accidental transfer of unrelated state. Exact qualification is recorded separately.
Expected result: The worker no longer needs the service object.
Why this result follows: Narrow capture reduces accidental transfer of unrelated state.
10. Scope platform support
Problem: Choose a strategy for native and browser builds.
- The example imports dart:isolate for a supporting native target.
- A browser requires its own supported concurrency or fallback design.
native: Isolate.run where supported
web: target-specific supported approach
Target support is a separate requirement from the local calculation. Exact qualification is recorded separately.
Expected result: No general browser compatibility is inferred.
Why this result follows: Target support is a separate requirement from the local calculation.
11. Compare identical fixtures
Problem: Check local and worker results for the same input before timing.
- Both paths use the same sumSquares function and n=4.
- Their expected results are both 30; a mismatch blocks performance interpretation.
input: n=4
local expected: 30
worker expected: 30
check: equality before timing
Correctness must be established on comparable inputs. Exact qualification is recorded separately.
Expected result: Both paths should agree on 30.
Why this result follows: Correctness must be established on comparable inputs.
12. Include startup in latency
Problem: Define the start and end of an isolate timing interval.
- The interval begins before starting the worker.
- It ends after the result is received, so startup and delivery are included.
start timer: before Isolate.run
stop timer: after awaited result
include: startup and result delivery
End-to-end latency includes the boundary’s overhead. Exact qualification is recorded separately.
Expected result: The measurement covers end-to-end completion.
Why this result follows: End-to-end latency includes the boundary’s overhead.
13. Include transfer cost
Problem: Account for moving a large input to a worker.
- The worker path requires transferring or copying supported input according to the API.
- Measure that boundary with the computation instead of timing only the inner loop.
workload: large integer list
measure: input transfer + compute + result delivery
Transfer cost is part of the real design decision. Exact qualification is recorded separately.
Expected result: Transfer is included in the worker measurement.
Why this result follows: Transfer cost is part of the real design decision.
14. Separate responsiveness from total latency
Problem: Interpret two different metrics for a worker experiment.
- Main-loop responsiveness measures delay to other work.
- End-to-end latency measures time until the computation result arrives; either can improve while the other worsens.
metric 1: main event-loop responsiveness
metric 2: total completion latency
The metrics answer different operational questions. Exact qualification is recorded separately.
Expected result: Report both metrics rather than equating them.
Why this result follows: The metrics answer different operational questions.
15. Use repeated observations
Problem: Plan a measurement that captures variation.
- One observed timing can reflect transient system load.
- Warm up appropriately and collect multiple observations with the workload and environment recorded.
plan: warmup; repeated runs; record SDK, target and workload
report: observations and variation
Variation matters when assessing a performance hypothesis. Exact qualification is recorded separately.
Expected result: No universal speed claim follows from one run.
Why this result follows: Variation matters when assessing a performance hypothesis.
16. Avoid inventing a benchmark
Problem: Report an unexecuted isolate comparison honestly.
- The local and worker source is available for review.
- No timing run has been performed, so the report marks timing unmeasured.
source review: complete
correctness expectation: 14
timing: not measured
Reasoned expectations and observed measurements are different evidence. Exact qualification is recorded separately.
Expected result: No performance result is claimed.
Why this result follows: Reasoned expectations and observed measurements are different evidence.
17. Distinguish timeout from termination
Problem: Assess a worker after its caller’s wait expires.
- The Future timeout changes what the caller observes.
- It does not generally prove that the isolate computation has stopped.
worker: running
caller: timeout
cancellation protocol: none specified
Waiting and worker lifetime require separate policies. Exact qualification is recorded separately.
Expected result: The worker may still complete.
Why this result follows: Waiting and worker lifetime require separate policies.
18. Bound repeated worker tasks
Problem: Design admission for a worker pool with two active slots.
- At most two tasks run concurrently under the stated limit.
- Additional tasks wait in a bounded queue or receive an explicit busy outcome.
active limit: 2
queue: bounded
when full: reject busy
A pool needs capacity and overflow policies as well as workers. Exact qualification is recorded separately.
Expected result: No more than two tasks are active under this policy.
Why this result follows: A pool needs capacity and overflow policies as well as workers.
19. Resolve pending work on worker failure
Problem: Define outcomes when a worker exits with request R1 pending.
- The coordinator observes worker failure or exit.
- It fails R1 under the documented policy and closes owned resources.
worker: exits unexpectedly
pending: R1
policy: fail R1; close owned ports
A worker lifecycle must account for pending callers. Exact qualification is recorded separately.
Expected result: R1 receives a worker-failure outcome.
Why this result follows: A worker lifecycle must account for pending callers.
20. Design a reproducible comparison
Problem: List the evidence for an isolate performance decision.
- Both paths first pass the same correctness fixtures.
- The experiment records SDK, target, workload, overhead and repeated timing observations.
correctness: compare identical inputs
measurement: include startup and transfer
report: SDK, target, workload, observations
A reproducible protocol connects a claim to its actual conditions. Exact qualification is recorded separately.
Expected result: The decision is based on recorded evidence, not a toy assumption.
Why this result follows: A reproducible protocol connects a claim to its actual conditions.
Common errors and fixes
A tiny task becomes slower after isolation
- Why it happens
- Startup and transfer costs exceed the work saved.
- How to fix it
- Measure representative workloads including overhead.
- Prevent it next time
- Use a baseline and choose the boundary based on evidence.
A worker result is lost
- Why it happens
- The caller starts isolate work without awaiting its Future.
- How to fix it
- Await or return the Future and handle its failure.
- Prevent it next time
- Test delayed completion and an injected worker error.
A timeout is treated as proof of cleanup
- Why it happens
- Caller timing and worker or external-effect lifetimes were conflated.
- How to fix it
- Define explicit cancellation and resource ownership.
- Prevent it next time
- Test late completion and partial external effects.
20 practice exercises
1. What is sumSquares(3)?
Show hint
List the squares from one through three.
Show worked solution
It is 1 + 4 + 9, or 14. Both local and isolate paths should produce the same result for this fixture before performance is compared.
The calculation adds 1², 2² and 3²: 1 + 4 + 9 = 14. Verify the same known value locally and through the worker path before comparing their performance. This fixture alone does not establish speedup.
Check your solution
- The local expected result is 14.
- The worker should return the same value for n=3.
2. Why might Isolate.run be a poor choice for this exact example?
Show hint
Compare the size of useful work with the isolate boundary costs.
Show worked solution
The calculation is tiny, so setup and transfer can cost more than the work. Measure a representative CPU-bound workload and include overhead before choosing isolation.
Three squares require very little computation, while starting an isolate and transferring a result add overhead. This is a reason to measure, not an observed timing claim. Compare a representative workload on the actual target, including startup and transfer, and assess responsiveness separately from total latency.
Check your solution
- The tiny fixture is not evidence of speedup.
- A measurement includes boundary overhead and target details.
3. Calculate sumSquares(5) and verify the recurrence against sumSquares(4), independently deriving both values.
Show hint
Adding the fifth square should connect the two results.
Show worked solution
The first four squares sum to 30; adding 5² gives 55 for n=5. The difference 55−30 is 25, providing a second relation to check the implementation beyond a single expected number. Neither value is a timing result.
Check your solution
- sumSquares(4) is 30 and sumSquares(5) is 55.
- Their difference is 25.
4. The local and worker paths accept nonnegative n. Design tests for -3 and a worker error, including what the caller must observe.
Show hint
Check the domain rejection and Future failure ownership separately.
Show worked solution
Reject -3 in the shared calculation with the documented error and verify both paths expose that failure to their owner. Separately inject a worker failure unrelated to input and confirm it is propagated or handled without inventing a numeric result.
Check your solution
- Negative input is rejected in both paths.
- An unrelated worker error remains distinguishable.
5. For n=2 compare local and worker results, then inject a worker failure and specify the owner’s separate outcome.
Show hint
Correctness comparison and error ownership are distinct checks.
Show worked solution
Both successful paths should yield 5 for n=2. Await the worker and compare with the independently derived local expectation; then use a controlled failure to confirm the caller receives an error rather than 5. Do not interpret timing if correctness fails.
Check your solution
- The successful paths agree on 5.
- The injected failure does not become numeric success.
6. A worker throws StateError and owned cleanup can also fail. Define a primary-error-first result and a separate diagnostic.
Show hint
Await the worker and preserve failure precedence.
Show worked solution
The owner awaits the worker, propagates its StateError and records a cleanup failure safely as secondary when both occur. If the worker succeeds but required cleanup fails, surface that cleanup failure. Do not return a numeric success on either failure path.
Check your solution
- The worker failure remains primary when both fail.
- A cleanup-only failure is visible.
7. A closure captures a service but needs n=4. Define an explicit bounded input and invalid-input outcome for the worker.
Show hint
Pass data rather than the resource owner and validate its domain.
Show worked solution
Separate the pure calculation from the service and pass n with a request ID under the supported transfer contract. Reject negative or oversized n with a correlated error before expensive work. Do not capture the potentially unsendable service graph.
Check your solution
- The worker receives only the bounded input and ID.
- Invalid input produces a correlated rejection.
8. A product supports native and web. Design a target matrix with a native isolate path, web fallback and evidence status for each.
Show hint
Platform support and observed execution are separate fields.
Show worked solution
Use Isolate.run only on a supporting native target and choose a supported web strategy or local fallback. Record whether correctness and performance were actually tested for each target; mark unrun cells explicitly. A native pass cannot populate the web evidence cell.
Check your solution
- Native and web strategies are stated separately.
- Each target has observed or untested evidence status.
9. Plan a comparison for 100 representative inputs while controlling differences between local and worker paths.
Show hint
Use identical inputs, function and environment.
Show worked solution
Generate or fix the same 100 inputs for both paths, verify each result matches, and run under the same SDK and target. Record the workload distribution and system conditions. Avoid changing the algorithm or input set between measurements.
Check your solution
- Both paths receive identical inputs.
- Correctness is checked before timing interpretation.
10. A benchmark times only the worker’s inner loop and excludes startup and transfer. Explain the bias and repair it.
Show hint
Measure the full end-to-end worker path.
Show worked solution
Start timing before Isolate.run or worker admission and stop after the result is received, including startup, input transfer and result delivery. Compare with the equivalent local interval. Report separately if an internal compute-only measurement is also useful.
Check your solution
- The primary worker measurement includes boundary overhead.
- The local comparison covers an equivalent operation.
11. One run reports 20 ms locally and 18 ms with an isolate. Design repeated measurements and specify median and tail latency reporting.
Show hint
A single timing does not describe variation or outliers.
Show worked solution
Warm up appropriately, run both paths repeatedly on identical representative inputs and report median and a stated tail percentile with sample counts and environment. Include startup and transfer, verify correctness first and avoid inferring a universal speedup from the two hypothetical values.
Check your solution
- Both paths have repeated observations and sample counts.
- Median and chosen tail latency are reported with target scope.
12. A product requires event-loop delay below 50 ms; hypothetical measurements show local 80 ms and isolate 30 ms while total isolate latency is higher. Make a scoped decision.
Show hint
Compare both metrics against the stated requirement.
Show worked solution
Under these hypothetical measurements the isolate meets the 50 ms responsiveness target while the local path does not, but the added total latency must also satisfy the product’s latency budget. Validate with repeated representative runs before deployment; the numbers here are not observed results.
Check your solution
- The hypothetical isolate delay meets the stated target.
- Total latency and repeated evidence remain part of the decision.
13. A worker returns 31 while the trusted local fixture expects 30 for the same input. What should happen before benchmarking?
Show hint
Resolve the correctness mismatch first.
Show worked solution
Investigate input, implementation and transfer assumptions until both paths satisfy an independently derived expected result. Treat the mismatch as a correctness failure; do not interpret speed differences as success. Rerun the corrected checks and record the source revision.
Check your solution
- The mismatch is not labeled a performance pass.
- The corrected paths are checked against the same expectation.
14. For a hypothetical tiny task, local computation takes 2 ms and isolate startup plus transfer takes 8 ms before the same 2 ms computation. Compare end-to-end latency.
Show hint
Add the stated overhead to the worker computation.
Show worked solution
Under these hypothetical figures the isolate path takes 10 ms end to end versus 2 ms locally, so it is slower for this fixture. This arithmetic is not a benchmark; real measurements must use representative workloads and include responsiveness requirements.
Check your solution
- The hypothetical isolate total is 10 ms.
- The local path is 2 ms under the stated assumptions.
15. You suspect isolate overhead becomes worthwhile above some input size. Design a test without inventing the crossover.
Show hint
Measure multiple sizes and record the environment.
Show worked solution
Test a stated range of input sizes with identical correct results, repeated end-to-end observations and documented SDK and hardware. Report where the observed tradeoff changes, including variation, without claiming a universal threshold. Include queueing if the real design uses a pool.
Check your solution
- The experiment covers multiple input sizes.
- Any threshold is scoped to observed conditions.
16. Two timed-out isolate tasks differ: R1 is a pure calculation and R2 may have committed an external write. Define late-result and recovery policies for each.
Show hint
A timeout ends the wait, not necessarily the worker or its effect.
Show worked solution
For pure R1, retain or discard the late result under a bounded documented policy while observing errors. For R2, preserve request identity and reconcile the external status before any retry, because the write may already have occurred. Neither timeout proves worker termination.
Check your solution
- R1 has a bounded late-result policy.
- R2 is reconciled before a potentially duplicating retry.
17. A pool has four active workers and ten queue slots; a queued caller cancels as a new request arrives. Define capacity and race behavior.
Show hint
Remove cancelled queued work before admitting a replacement.
Show worked solution
If the cancellation removes a queued task first, admit the new request into that slot under the documented queue order. If it has not completed, report busy rather than exceed capacity. Resolve the cancelled caller and record the race policy; active work remains bounded at four.
Check your solution
- At most four tasks are active and ten queued.
- Cancellation and admission have a defined ordering outcome.
18. A synchronous baseline passed on source H1, while the isolate experiment was planned but not run. Write separate evidence statements.
Show hint
Bind observed and unobserved claims to their exact scope.
Show worked solution
Record the actual baseline command, SDK, platform, H1 and observed result. Mark isolate correctness and timing not run, listing the proposed workload separately. Do not let the baseline pass imply worker execution or speedup.
Check your solution
- The baseline receipt is tied to H1 and its environment.
- The isolate experiment is explicitly unrun.
19. A worker exits with two pure calculations and one external write pending. Define separate recovery outcomes and cleanup.
Show hint
Classify task effects before retrying.
Show worked solution
Fail or safely retry the pure calculations under the pool policy. Preserve the write’s request identity and reconcile its external status before retrying, since it may have committed. Resolve all callers and close owned ports; an exit marker is not rollback evidence.
Check your solution
- Both pure tasks receive defined outcomes.
- The external write is reconciled before any retry.
20. Design a native isolate experiment for a bounded pure calculation, including correctness, ownership and measurement evidence.
Show hint
Combine a local baseline with a controlled worker lifecycle.
Show worked solution
Define input bounds and known expected values, compare local and Isolate.run results, and await or propagate worker failures. Measure representative sizes with startup and transfer included, repeated observations and separate responsiveness metrics. Record SDK, platform, source and limitations; test browser support separately if required.
Check your solution
- Correctness is established before timing claims.
- The report includes overhead, variation and target scope.
Key takeaways
- Use isolates for a justified work boundary, not an assumed speedup.
- Verify correctness, platform support, and ownership before measuring.
- Async syntax alone does not move CPU work to another isolate.
- Correctness and result ownership precede performance claims.
- End-to-end measurements include startup, transfer and result delivery.