knaxuslearn · build · ship

Roadmaps / Fundamentals / Phase 1

Phase 1 of 4 · Study weeks 1-4

Languages, memory and measurement

This phase makes the first checkpoint possible: a server you can measure and a clear picture of where its memory goes.

Topics every week

  1. Week 18 h
    • Values, references and pointers
    • The stack and the heap
    • Object layout and alignment
    • Copy against reference

    Hand inA table of sizes and copy costs for five types, predicted then measured

  2. Week 28 h
    • Memory management: garbage collection, manual and ownership styles
    • Allocation cost
    • Escape analysis
    • Leaks and how they show up

    Hand inThe first single-connection server and its allocation count per message

  3. Week 38 h
    • Profilers: CPU and heap
    • Flame graphs
    • Benchmarks and why they lie
    • Reading a profile

    Hand inA heap profile and the fix for the seeded leak

  4. Week 48 h
    • Errors and how languages report them
    • Strings, bytes and encodings
    • Language differences that bite (nulls, integer overflow, ordering)

    Hand inCheckpoint 1: the table, the profile and the before and after numbers

Practice projects

  • Practice 1, the layout table (Week 1): print the size and alignment of five types and predict each first. Done when: every prediction is checked and each difference is explained.
  • Practice 2, the allocation count (Week 2): count allocations per message for three ways of parsing a frame. Done when: a table shows allocations and time for each and you pick one with a reason.
  • Practice 3, the seeded leak (Week 3): keep a map entry after a topic closes. Done when: a heap profile shows the growth, the fix is measured and the growth stops.
  • Optional, a second language: write the frame parser in a second language. Done when: a table compares lines of code, allocations and speed with the first.

GitHub repos to study

Existence and last commit were checked on 22 Nov 2026 by shallow clone. Every repository below had a commit in the last 12 months. Look at the README for archive notices before you rely on one.

RepoWhat to readWeek
golang/goThe runtime allocator and runtime/pprof3
openjdk/jdkThe garbage collector docs and the object header layout2
isocpp/CppCoreGuidelinesThe ownership and resource management rules2
async-profiler/async-profilerHow a low-overhead sampling profiler works3
google/benchmarkHow a fair microbenchmark is written3

Milestone checkpoint

Build Checkpoint 1. Write your predictions for the layout and allocation tables first. Build the single-connection server, then profile it before changing anything. Seed the leak, find it from the heap profile and fix it. Hand in the tables with your own numbers, the profiles, ADR-1 (the language and why) and ADR-2 (the frame format).

Check yourself

Answer each question in your head first, then open it to check.

  1. What is the difference between the stack and the heap, and what decides where a value lives?
    The stack holds fixed-size frames that are freed when a function returns. The heap holds values whose lifetime or size is not known in advance. The language and the compiler decide, using rules such as escape analysis.
  2. Why does a benchmark that runs for 10 ms mislead?
    Warm-up, caches and the compiler or runtime may not have settled, and one slow run can dominate. Run long enough, repeat and report the spread.
  3. How does a leak show up in a garbage-collected language?
    Objects stay reachable by a reference you forgot (a map, a listener, a cache), so the collector cannot free them and the heap grows after each collection.
  4. What does alignment do to the size of a struct?
    The compiler pads fields so each sits at a multiple of its size, so the struct can be larger than the sum of its fields. Ordering fields by size can shrink it.
  5. Why profile before optimising?
    The slow part is rarely where you guess. A profile shows the few functions that account for most of the time or memory.