Frontory

Open code, practice, and notes →

Download source with English comments · for reading

WebAssembly · 14 Arrays and Boundary Costs

Series contents · Technology map

Stage: Memory and Array Boundaries · Editable example · Storage ID: webassembly-02

Goals and learning outcomes

Prerequisites

Prepare the experiment results for Call count and Fair comparison from Unit 13, “Scalar and Batch Calls”.

Key concepts and explanations

Memory layout

Passing an array requires a byte offset and length. Copy cost is separate from kernel computation.

View lifetime

Recreate views after grow. Continuing to use stale references prevents correct validation.

Practice setup

The iframe preview is an experiment with WebAssembly.Memory and JS reference computations; do not present it as execution of an actual Wasm module. Practice with actual modules in a separate Node 22+ environment or a controlled local web project. Use kernel.wat·kernel.wasm·benchmark.mjs in the existing src/labs/webassembly-02·03 folders, and rebuild with the official wat2wasm tool when modifying WAT. Preserve CSP·isolation, and record measurements yourself.

The linked example is a starting point. It does not implement every task below. Complete work beyond its supported scope in a separate project.

Practice tasks

  1. In day-14.mjs in a separate practice project, run node src/labs/webassembly-02/benchmark.mjs in a separate Node environment and inspect the copy·batch·scalar·grow results. Refer to the existing Unit 1·14·28 examples only as starting points.
  2. Input conditions: the existing 100003 inputs and a small array. Baseline: 100 elements. Run under the baseline conditions, then record observations and errors in notes/day-14.md.
  3. Variable: batch size; changed value: 100003 elements. Run again through the same input path. Deliverable to save: matching sums·copyMs·batchMs·scalarMs·view lengths. Hypothesis to check: The proportions of call and copy costs change, and the results match. Compare it with the actual results, and record whether they agree and why they differ.

Variables to observe

VariableBaselineChangeExpected change / hypothesis
batch size100 elements100003 elementsThe proportions of call and copy costs change, and the results match.

Predictions in this table are not measured results. Change one condition at a time and record why the actual result differs.

Completion criteria

Self-check

  1. Which processing stage does Memory layout affect in this exercise? Input cases: the existing 100003 inputs and a small array.
  2. Variable: batch size. Hypothesis to check: The proportions of call and copy costs change, and the results match. Did the actual results agree with the hypothesis? Explain the evidence in terms of View lifetime.

Official references

Linked example and execution scope

Example source · Runtime environments and limits

Source code and records are not overwritten automatically. Resetting an existing example also preserves your notes.

Next learning

Previous: Scalar and Batch Calls · Next: In-place Transformation

Open code, practice, and notes →