Apex › Systems & OS
The compiler’s last polish (peephole optimization)
The final local-rewrite pass: slide a small window over consecutive instructions and replace patterns with cheaper equivalents. Strength reduction (mul r,4 → shl r,2), algebraic identities and dead ops (add r,0 and mul r,1 vanish; xor r,r → mov r,0), and combining adjacent ops (add r,1; add r,1 → add r,2). Every rule is a proven semantics-preserving identity, and it iterates to a fixpoint since one rewrite can expose another — the closing pass in GCC and LLVM. Verified in node: all rewrites preserve semantics for every 32-bit input, and a 6-instruction sequence optimizes to 3 with identical output. Slide the peephole and watch the program shrink while the result stays 8x+4.
More in Systems & OS
- CPU scheduling
- Linux CFS scheduler
- How Linux schedules now (EEVDF)
- Priority inversion
- How a CPU runs an instruction
- How a calculator parses math (shunting-yard)
- How code becomes machine code
- The form every optimizer uses (SSA & phi nodes)
- How variables get registers (graph coloring)
- How types are inferred with none written (Hindley-Milner)
- How a bytecode VM runs code
- How WebAssembly sandboxes untrusted code
- How a JIT makes code fast
- Pipeline hazards
- Branch prediction
- How the CPU prefetches memory (stride prefetcher)
- Code with no branches (branchless / cmov)
- Out-of-order execution
- Spectre (speculation)
- How Meltdown reads kernel memory (transient execution)
- How Rowhammer flips bits in DRAM (fault injection)
- The kill chain & defense-in-depth (attacker’s lens)
- Copy-on-write fork
- Page-table walk
- Process memory layout
- How a page fault brings in memory
- inode & indirect blocks
- TLB (address cache)
- How a VM translates memory (nested paging)
- NUMA & first-touch
- Buddy allocator
- One block, one pointer (arena allocator)
- How garbage collection works
- How a copying collector compacts the heap (Cheney)
- How reference counting frees memory
- How Rust ownership prevents memory bugs
- Timing wheel
- epoll & C10k
- How a syscall enters the kernel
- How a container isolates a process
- cgroups (resource limits)
- OverlayFS (container layers)
- Container bridge networking
- How a debugger breakpoint works
- futex (fast mutex)
- RCU (read-copy-update)
- ABA problem (lock-free)
- seqlock (torn reads)
- io_uring (async I/O)
- Lamport bakery (mutex)
- MESI cache coherence
- False sharing
- Memory consistency (TSO)