0Pricing
Mojo Academy · Lesson

Reducing Memory Traffic

Keep data close to the compute.

Reducing Memory Traffic is a free Mojo Academy lesson on CoddyKit — lesson 3 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Mojo Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

Why Memory Matters

Modern CPUs compute far faster than they can fetch data. Often a kernel waits on memory, not on the math itself.

What Is Memory Traffic?

Memory traffic is the total bytes your kernel reads and writes. Less traffic per result usually means a faster kernel.

Touch Data Once

Reading the same value many times wastes bandwidth. Load it once, do all the work, then reuse it from a register.

var x = a[i]
var y = x * x + x

Fuse Your Loops

Two separate loops over the same array read it twice. Fusing them into one pass reads each element only once.

for i in range(n):
    out[i] = a[i] * 2 + a[i]

Keep Values in Registers

A value held in a CPU register needs no memory access. Reuse intermediate results instead of writing them out and back.

Avoid Temp Buffers

Extra temporary arrays add both stores and loads. Skip them when you can and compute straight into the final output.

Stream Sequentially

Reading memory in order lets the CPU prefetch ahead. Jumping around defeats prefetching and stalls the loop.

for i in range(n):
    total += a[i]

Cache Lines Travel Together

Memory arrives in fixed-size cache lines. Using every byte of a line you fetched gives you free, already-loaded data.

Compute More per Byte

Arithmetic intensity is work done per byte loaded. Raising it means each fetched value earns more compute before you move on.

Write Once, If You Can

Stores cost bandwidth too. Accumulate in a local and write the final result once rather than updating memory repeatedly.

var acc = Float32(0)
for i in range(n):
    acc += a[i]
out[0] = acc

Less Traffic, More Speed

When the kernel waits on data, cutting reads and writes is the biggest win, often beating clever arithmetic tweaks.

Quick Check

Your kernel reads the same array in two separate loops. What single change cuts its memory traffic most?

Recap

Cut memory traffic by touching data once, fusing loops, reusing registers, streaming in order, and writing results just once. 💾

Frequently asked questions

Is the “Reducing Memory Traffic” lesson free?

Yes — the full text of “Reducing Memory Traffic” is free to read here on the web, and the Mojo Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Mojo Academy course, upgrade to CoddyKit PRO.

What will I learn in “Reducing Memory Traffic”?

Keep data close to the compute. You practise Mojo Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Mojo Academy?

No prior experience is required. Mojo Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 3 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Reducing Memory Traffic” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Mojo Academy lesson?

Yes. Every Mojo Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Anatomy of a Compute Kernel
  2. Combining SIMD with Loops
  3. Reducing Memory Traffic
  4. Tiling for Cache Locality
← Back to Mojo Academy