# David Álvarez Rosa

Personal site of David Álvarez Rosa

This is one page of public article previews, not the complete archive. Follow Next page to continue. Summaries are not the original full articles.

## Self-Hosting Behind CGNAT

DevFeed: [Self-Hosting Behind CGNAT](<https://devfeed.tech/articles/self-hosting-behind-cgnat-60980.md>)

Original publisher: [Read original article](<https://david.alvarezrosa.com/posts/self-hosting-behind-cgnat/>)

Author: David Álvarez Rosa

Published: 2026-09-21T07:32:00Z

Content type: tutorial

Language: en

Sources: [David Álvarez Rosa](<https://devfeed.tech/sources/david-alvarez-rosa.md>)

Topics: [Homelab](<https://devfeed.tech/topics/homelab.md>), [Virtual Private Network](<https://devfeed.tech/topics/vpn.md>), [Self-hosted](<https://devfeed.tech/topics/self-hosted.md>), [NAT and SNAT](<https://devfeed.tech/topics/nat-and-snat.md>), [IP routing](<https://devfeed.tech/topics/ip-routing.md>)

Tags: [cgnat](<https://devfeed.tech/tags/cgnat.md>), [homelab](<https://devfeed.tech/tags/homelab.md>), [hosting](<https://devfeed.tech/tags/hosting.md>), [internet](<https://devfeed.tech/tags/internet.md>), [ipv4](<https://devfeed.tech/tags/ipv4.md>), [nat](<https://devfeed.tech/tags/nat.md>), [self-hosting](<https://devfeed.tech/tags/self-hosting.md>), [ssh](<https://devfeed.tech/tags/ssh.md>), [static](<https://devfeed.tech/tags/static.md>), [vps](<https://devfeed.tech/tags/vps.md>)

### AI overview

The article explains how to expose home-hosted services behind carrier-grade NAT by routing traffic through a VPS bridge over a bidirectional WireGuard tunnel. It describes the tunnel configuration, the added 39 ms round-trip-time penalty, and recovery options for failures.

### Source excerpt

There is nothing more satisfying than owning, end to end, the software and the hardware you use without relying on abusive cloud corporations. Internet is us, not them. Break free from censorship. Learn how to self-host at home, and be truly libre. In the past, self-hosting was easier. You just had to open a port on your router and forward it to any machine at home.1 Nowadays, the shortage of IPv4 addresses means routers share the same IP across your neighborhood. Requests are routed using carrier-grade NAT (CGNAT), a second-layer NAT inside the carrier's network, where your router's address is private and translated by the carrier on the way out. The public address is the carrier's, so port forwarding no longer works. Topology § My services run on a mid-range machine in my mother's basement in northern Spain, and are exposed to the Internet through a cheap VPS bridge in a French data center. +-------------------------------------+ | public Internet | +-------------------------------------+ ^ ^ | inbound | v | +------------+ | | bridge | | egress +------------+ | ^^ | || WireGuard | vv | +-------------------------------------+ | homelab | +-------------------------------------+ Code Snippet 1: Topology diagram. The homelab is exposed to the Internet through a WireGuard tunnel to a VPS bridge. A bidirectional WireGuard tunnel2 forwards all packets in all ports from the bridge to the homelab box, and vice versa. The beauty of this is that the tunnel is initiated by the homelab, so you don't need a static dedicated IP at home.3 The penalty of the bridge is 39 ms of RTT. Tunnel configuration § Bridge's wg0.conf.4 [Interface] Address = 10.0.0.1/24 PrivateKey = <bridge-private-key> ListenPort = 51820 PostUp = ... PostDown = ... [Peer] PublicKey = <homelab-public-key> AllowedIPs = 10.0.0.2/32 PostUp sets up NAT and forwarding rules at the kernel level.5 The first two exclude ports 2222 for SSH, and 51820 for the VPN tunnel itself. The last three forward all traffic in all

## Optimizing a Spin-Lock

DevFeed: [Optimizing a Spin-Lock](<https://devfeed.tech/articles/optimizing-a-spin-lock-60979.md>)

Original publisher: [Read original article](<https://david.alvarezrosa.com/posts/optimizing-a-spin-lock/>)

Author: David Álvarez Rosa

Published: 2026-08-27T13:23:00Z

Content type: tutorial

Language: en

Sources: [David Álvarez Rosa](<https://devfeed.tech/sources/david-alvarez-rosa.md>)

Topics: [locking](<https://devfeed.tech/topics/locking.md>), [synchronization](<https://devfeed.tech/topics/synchronization.md>), [Cache](<https://devfeed.tech/topics/cache.md>), [queueing theory](<https://devfeed.tech/topics/queueing-theory.md>)

Tags: [atomic](<https://devfeed.tech/tags/atomic.md>), [cache](<https://devfeed.tech/tags/cache.md>), [cpp](<https://devfeed.tech/tags/cpp.md>), [energy](<https://devfeed.tech/tags/energy.md>), [exponential-backoff](<https://devfeed.tech/tags/exponential-backoff.md>), [perf](<https://devfeed.tech/tags/perf.md>), [performance](<https://devfeed.tech/tags/performance.md>), [thread](<https://devfeed.tech/tags/thread.md>), [threads](<https://devfeed.tech/tags/threads.md>)

### AI overview

This tutorial benchmarks a C++ spin-lock that protects a shared counter, then improves it through memory ordering, test-and-test-and-set, and exponential backoff. In the reported four-thread benchmark, the backoff version reduces latency from 246 ns to 43.0 ns and energy use from 64.92 J to 11.92 J compared with the naive version. The article recommends considering spin-locks only for threads pinned to dedicated cores and after measuring.

### Source excerpt

A spin-lock is a lock that never sleeps. Instead of yielding to the scheduler, the thread stays on the CPU and spins. No syscalls. No context switches. In this post, we'll build a version, step by step, that is 5.7x faster while drawing 5.4x less energy. Benchmark § Threads increment a shared counter under the lock.1 template <typename Lockable> auto BM_SpinLock(benchmark::State& state) -> void { alignas(std::hardware_destructive_interference_size) static auto lockable = Lockable{}; alignas(std::hardware_destructive_interference_size) static auto counter = std::uint64_t{}; pinThread(state.thread_index()); for (auto _ : state) { lockable.lock(); ++counter; lockable.unlock(); } benchmark::DoNotOptimize(counter); } The lock and the counter get a cache line each. Threads are pinned. A naive spin-lock § An atomic bool and an exchange loop.2 class SpinLockV1 { std::atomic_bool locked_{false}; public: auto lock() noexcept -> void { while (locked_.exchange(true)); } auto unlock() noexcept -> void { locked_.store(false); } }; Uncontended it takes 3.14 ns. Two threads take 61.5 ns, twenty times as long. Four take 246 ns. $ ./benchmark --benchmark_filter='V1>' BM_SpinLock<SpinLockV1>/real_time/threads:1 3.14 ns BM_SpinLock<SpinLockV1>/real_time/threads:2 61.5 ns BM_SpinLock<SpinLockV1>/real_time/threads:4 246 ns A core must own the line exclusively to write it, so waiters take it from each other. L1-d misses go from 1.27% at one thread to 61.73% at four, and one branch in eight is mispredicted.3 $ perf stat -d ./benchmark --benchmark_filter='V1>.*threads:1' 1,638,619,370 instructions # 0.51 insn per cycle 244,253 branch-misses # 0.11% of all branches 75,519 L1-dcache-load-misses # 1.27% of all L1-dcache accesses $ perf stat -d ./benchmark --benchmark_filter='V1>.*threads:4' 1,231,495,723 instructions # 0.02 insn per cycle 33,824,516 branch-misses # 12.52% of all branches 208,756,315 L1-dcache-load-misses # 61.73% of all L1-dcache accesses Spinning costs energy.4 At four thread

## Tuning a Server for Benchmarking

DevFeed: [Tuning a Server for Benchmarking](<https://devfeed.tech/articles/tuning-a-server-for-benchmarking-60982.md>)

Original publisher: [Read original article](<https://david.alvarezrosa.com/posts/tuning-a-server-for-benchmarking/>)

Author: David Álvarez Rosa

Published: 2026-06-25T17:02:00Z

Content type: tutorial

Language: en

Sources: [David Álvarez Rosa](<https://devfeed.tech/sources/david-alvarez-rosa.md>)

Topics: [rapidfireai](<https://devfeed.tech/topics/rapidfireai.md>), [Macrobenchmark](<https://devfeed.tech/topics/macrobenchmark.md>), [NUMA](<https://devfeed.tech/topics/numa.md>), [Processor Affinity](<https://devfeed.tech/topics/processor-affinity.md>)

Tags: [benchmark](<https://devfeed.tech/tags/benchmark.md>), [cpu](<https://devfeed.tech/tags/cpu.md>), [hardware](<https://devfeed.tech/tags/hardware.md>), [performance](<https://devfeed.tech/tags/performance.md>), [time](<https://devfeed.tech/tags/time.md>)

### AI overview

The article demonstrates how to reduce noise in microbenchmarks by tuning a server, including pinning the benchmark to a core and locking CPU frequency. It reports that core pinning lowered the measured mean to 55.3 µs and reduced the coefficient of variation to 1.06%.

### Source excerpt

Optimizing code starts with measuring it, and a measurement is only useful if it is repeatable: a 2% improvement is invisible under 5% of noise. Yet on an untuned machine the same binary can easily run several percent faster or slower between runs. In this post we take a tiny benchmark and tune the machine step by step, re-measuring after every change, until runs become deterministic.1 A noisy baseline § Our running example sums an array of doubles, in short bursts. Real services rarely hammer the CPU continuously: they handle a request, sit idle, and wake up for the next one. Each timed iteration here runs a burst of 256 sums after a 2 ms idle gap, with the gap excluded from the measurement2 static auto BM_Sum(benchmark::State& state) -> void { alignas(64) static std::array<double, 4096> data; std::iota(data.begin(), data.end(), 0.0); for (auto _ : state) { state.PauseTiming(); // Idle between bursts, like a real service std::this_thread::sleep_for(std::chrono::milliseconds(2)); state.ResumeTiming(); for (auto i = 0; i < 256; ++i) { auto sum = std::accumulate(data.cbegin(), data.cend(), 0.0); benchmark::DoNotOptimize(sum); } } } BENCHMARK(BM_Sum); Compile it in release with all optimizations, -O3, and -march=native -mtune=native -flto -ffast-math. Then run ten repetitions and aggregate them $ ./benchmark --benchmark_repetitions=10 --benchmark_min_time=100x BM_Sum_mean 99575 ns BM_Sum_stddev 2704 ns BM_Sum_cv 2.72 % The interesting line is cv, the coefficient of variation: standard deviation divided by mean. Almost 3% of run-to-run noise--any optimization smaller than that is invisible. Let's bring it down. Know your hardware § Before turning any knob, look at what you are tuning. lstopo draws the whole machine in one picture: caches, cores, SMT pairs, and the PCIe devices hanging off them. Start with my laptop Figure 1: My laptop (Intel Core Ultra 5 135U). Three kinds of cores: two P-cores with two hardware threads each (dotted), eight E-cores in clusters of four sh

## Self-Hosting on the Dark Web

DevFeed: [Self-Hosting on the Dark Web](<https://devfeed.tech/articles/self-hosting-on-the-dark-web-60981.md>)

Original publisher: [Read original article](<https://david.alvarezrosa.com/posts/self-hosting-on-the-dark-web/>)

Author: David Álvarez Rosa

Published: 2026-06-01T09:55:00Z

Content type: tutorial

Language: en

Sources: [David Álvarez Rosa](<https://devfeed.tech/sources/david-alvarez-rosa.md>)

Topics: [Self-hosted](<https://devfeed.tech/topics/self-hosted.md>), [tor](<https://devfeed.tech/topics/tor.md>), [Jamstack](<https://devfeed.tech/topics/jamstack.md>), [nginx](<https://devfeed.tech/topics/nginx.md>), [Hugo](<https://devfeed.tech/topics/hugo.md>), [Domain Name System (DNS)](<https://devfeed.tech/topics/dns-resolution-process.md>), [QUIC](<https://devfeed.tech/topics/quic.md>), [Virtual Private Network](<https://devfeed.tech/topics/vpn.md>)

Tags: [0-1](<https://devfeed.tech/tags/0-1.md>), [hugo](<https://devfeed.tech/tags/hugo.md>), [nginx](<https://devfeed.tech/tags/nginx.md>), [self-hosting](<https://devfeed.tech/tags/self-hosting.md>), [tor](<https://devfeed.tech/tags/tor.md>)

### AI overview

A tutorial explains how to publish a static site as a Tor hidden service. It covers configuring Tor to forward traffic to a local port, serving the onion address with nginx, and building and deploying a separate copy with Hugo so links use the onion base URL.

### Source excerpt

This site is now reachable over Tor as a hidden service, at a .onion address that resolves only inside the Tor network.1 Tor relays and encrypts your traffic as it passes through thousands of volunteer-run servers, so that no single party can link who you are to what you are doing; a hidden service extends that anonymity to the server itself. It's built by the nonprofit Tor Project, which advances human rights and freedoms through free software and open networks, so that anyone can use the internet free from tracking, surveillance, and censorship. The network only works because people use it, so consider supporting them or running a relay--your contribution helps millions stay safe and private online every day. The hidden service § Install Tor and point a hidden service at a local port. Edit /etc/tor/torrc HiddenServiceDir /var/lib/tor/blog/ HiddenServicePort 80 127.0.0.1:8080 The directory must be a dedicated, Tor-owned path--not your web root.2 Restart Tor and read the address it generates $ sudo systemctl restart tor@default $ sudo cat /var/lib/tor/blog/hostname dhevt6e4rtgbtr3jh53xrpwmgtilkah6nyjujocsspssrsexc7omxhid.onion Serving the site § Tor forwards the onion's port 80 to 127.0.0.1:8080, so the web server just needs to listen there. Add an nginx server block for it--no TLS, no HTTP/2, no QUIC, since Tor speaks plain TCP and provides its own encryption. server { listen 127.0.0.1:8080; server_name dhevt6e4rtgbtr3jh53xrpwmgtilkah6nyjujocsspssrsexc7omxhid.onion; root /srv/tor.david.alvarezrosa.com; index index.html; error_page 404 /404/index.html; location / { try_files $uri $uri/ =404; } } Reload nginx and the site is live on Tor. Building for the onion § A static site bakes its base URL into absolute links, so a clearnet build would point visitors back to the clearnet domain even when served over Tor. The fix is to build a second copy with the onion as its base URL $ hugo --minify --baseURL="http://dhevt6e4rtgbtr3jh53xrpwmgtilkah6nyjujocsspssrsexc7omxhid.onion/"

## First Steps on a New Server

DevFeed: [First Steps on a New Server](<https://devfeed.tech/articles/first-steps-on-a-new-server-60975.md>)

Original publisher: [Read original article](<https://david.alvarezrosa.com/posts/first-steps-on-a-new-server/>)

Author: David Álvarez Rosa

Published: 2026-05-17T16:26:00Z

Content type: tutorial

Language: en

Sources: [David Álvarez Rosa](<https://devfeed.tech/sources/david-alvarez-rosa.md>)

Topics: [Back end](<https://devfeed.tech/topics/backend.md>), [ssh](<https://devfeed.tech/topics/ssh.md>), [Zsh](<https://devfeed.tech/topics/zsh.md>)

Tags: [debian](<https://devfeed.tech/tags/debian.md>), [dns](<https://devfeed.tech/tags/dns.md>), [linux](<https://devfeed.tech/tags/linux.md>), [password](<https://devfeed.tech/tags/password.md>), [self-hosting](<https://devfeed.tech/tags/self-hosting.md>), [servers](<https://devfeed.tech/tags/servers.md>), [ssh](<https://devfeed.tech/tags/ssh.md>), [starship](<https://devfeed.tech/tags/starship.md>)

### AI overview

A practical checklist for setting up a new Linux server covers choosing a distribution, configuring DNS, creating a non-root account, setting up shell dotfiles and SSH keys, enabling firewall rules and security updates, and confirming nginx and HTTPS work.

### Source excerpt

Over the last decade I've been playing with dozens of servers from multiple providers. These are the steps I've been perfecting to get up to speed fast and feel right at home on a new machine. Wrote it down here mostly as a personal reference, but hopefully useful to someone else too. Hardware, distro, and DNS § Clean Linux install with one large root partition plus big swap.1 While I run Arch on my laptop, Debian tends to be a better fit for servers because of its stability and long support window. Point your domain2 to your server's IP at your DNS provider: an A record for IPv4 and an AAAA record for IPv6. Wait a few minutes, then verify both. $ dig alvarezrosa.com A +short 213.32.19.229 $ dig alvarezrosa.com AAAA +short 2001:41d0:305:2100::febc Hardware doesn't matter: a VPS, a Raspberry Pi, or a dedicated box will do. First login § Log in as root, change the password, and update. $ ssh root@alvarezrosa.com $ passwd $ apt update && apt full-upgrade Create a non-root user with sudo privileges. $ useradd --create-home --groups sudo david $ passwd david Log out, then reconnect as the new user. $ ssh david@alvarezrosa.com From here on, stay on this account and use sudo when you need it. Dotfiles § I like to set up dotfiles early. Debugging on an unfamiliar shell is its own kind of miserable.3 $ git init $ git remote add origin https://github.com/david-alvarez-rosa/dotfiles.git $ git fetch origin $ git checkout -t origin/main $ git submodule update --init --recursive $ git config status.showUntrackedFiles no Switch to zsh and install starship.4 $ sudo apt install zsh starship $ chsh --shell $(which zsh) Log out and back in to confirm the shell loads correctly. SSH keys § Copy your public key to the server from your local machine.5 $ ssh-copy-id david@alvarezrosa.com Confirm you can get in without a password. $ ssh david@alvarezrosa.com If you need root access over SSH, install the key there too. $ sudo install -d -m 700 /root/.ssh $ sudo install -m 600 ~/.ssh/authoriz

## Optimizing a Lock-Free Ring Buffer

DevFeed: [Optimizing a Lock-Free Ring Buffer](<https://devfeed.tech/articles/optimizing-a-lock-free-ring-buffer-60978.md>)

Original publisher: [Read original article](<https://david.alvarezrosa.com/posts/optimizing-a-lock-free-ring-buffer/>)

Author: David Álvarez Rosa

Published: 2026-03-24T11:51:00Z

Content type: tutorial

Language: en

Sources: [David Álvarez Rosa](<https://devfeed.tech/sources/david-alvarez-rosa.md>)

Topics: [thread safe data sharing](<https://devfeed.tech/topics/thread-safe-data-sharing.md>), [Deadlock](<https://devfeed.tech/topics/deadlock.md>)

Tags: [atomics](<https://devfeed.tech/tags/atomics.md>), [cpp](<https://devfeed.tech/tags/cpp.md>), [fifo](<https://devfeed.tech/tags/fifo.md>), [latency](<https://devfeed.tech/tags/latency.md>), [lock-free](<https://devfeed.tech/tags/lock-free.md>), [performance](<https://devfeed.tech/tags/performance.md>), [single-threaded](<https://devfeed.tech/tags/single-threaded.md>)

### AI overview

A tutorial builds a single-producer, single-consumer ring buffer from a simple array-based queue through thread-safe and lock-free versions. It explains fixed capacity, FIFO behavior, and using atomics to remove mutual-exclusion overhead for low-latency data sharing between threads.

### Source excerpt

A single-producer single-consumer (SPSC) queue is a great example of how far constraints can take a design. In this post, you will learn how to implement a ring buffer from scratch: start with the simplest design, make it thread-safe, and then gradually remove overhead while preserving FIFO behavior and predictable latency. This pattern is widely used to share data between threads in the lowest-latency environments. What is a ring buffer? § 1You might have run into the term circular buffer, or perhaps cyclic queue. These are simply other names for a ring buffer: a queue where a producer generates data and inserts it into the buffer, and a consumer later pulls it back out, in first-in-first-out order. What makes a ring buffer distinctive is how it stores data and the constraints it enforces. It has a fixed capacity; it neither expands nor shrinks. As a result, when the buffer fills up, the producer must either wait until space becomes available or overwrite entries that have not been read yet, depending on what the application expects. The consumer's job is straightforward: read items as they arrive. When the ring buffer is empty, the consumer has to block, spin, or move on to other work. Each successful read releases a slot the producer can reuse. In the ideal case, the producer stays just a bit ahead, and the system turns into a quiet game of "catch me if you can," with minimal waiting on both sides. Single-threaded ring buffer § Let's start with a single-threaded ring buffer, which is just an array2 and two indices. We leave one slot permanently unused to distinguish "full" from "empty." Push writes to head and advances it; pop reads from tail and advances it. template <typename T, std::size_t N> class RingBufferV1 { std::array<T, N> buffer_; std::size_t head_{0}; std::size_t tail_{0}; }; We can now implement the push (or write) operation3 auto push(const T& value) noexcept -> bool { auto new_head = head_ + 1; if (new_head == buffer_.size()) [[unlikely]] { // Wrap

## Deriving Type Erasure

DevFeed: [Deriving Type Erasure](<https://devfeed.tech/articles/deriving-type-erasure-60973.md>)

Original publisher: [Read original article](<https://david.alvarezrosa.com/posts/deriving-type-erasure/>)

Author: David Álvarez Rosa

Published: 2026-03-10T09:46:00Z

Content type: tutorial

Language: en

Sources: [David Álvarez Rosa](<https://devfeed.tech/sources/david-alvarez-rosa.md>)

Topics: [union types](<https://devfeed.tech/topics/union-types.md>), [Polymorphism](<https://devfeed.tech/topics/polymorphism.md>)

Tags: [code](<https://devfeed.tech/tags/code.md>), [cpp](<https://devfeed.tech/tags/cpp.md>), [inheritance](<https://devfeed.tech/tags/inheritance.md>), [polymorphism](<https://devfeed.tech/tags/polymorphism.md>), [subclass](<https://devfeed.tech/tags/subclass.md>), [types](<https://devfeed.tech/tags/types.md>)

### AI overview

The tutorial explains type erasure in C++ by comparing interface-based polymorphism with templates. It introduces wrappers that can provide a shared interface for concrete types that do not share a base class, deriving a minimal std::any implementation.

### Source excerpt

Ever looked at std::any and wondered what's going on behind the scenes? Beneath the intimidating interface is a classic technique called type erasure: concrete types hidden behind a small, uniform wrapper. Starting from familiar tools like virtual functions and templates, we'll build a minimal std::any. By the end, you'll have a clear understanding of how type erasure works under the hood. Polymorphism with interfaces § The typical way to achieve polymorphism is to define an interface consisting of pure-virtual methods you want to be able to call. Then, for each implementation that you want to use polymorphically, you create a subclass that inherits from the base class and implement those methods. As an example, let's implement shape classes that have an area() method. We start with an interface1 class class Shape { public: virtual ~Shape() = default; virtual auto area() const noexcept -> double = 0; }; And add a couple of concrete implementations for Square and Circle class Square : public Shape { int side_; public: explicit Square(int side) noexcept : side_{side} {} auto area() const noexcept -> double override { return side_ * side_; } }; class Circle : public Shape { int radius_; public: explicit Circle(int radius) noexcept : radius_{radius} {} auto area() const noexcept -> double override { return std::numbers::pi * radius_ * radius_; } }; Now, we can use these implementations generically, by coding against the interface auto printArea(const Shape& shape) -> void { std::println("Area is {:.2f}", shape.area()); } Simple enough, right? Polymorphism with templates § Inheritance is a good solution to problems that require polymorphism, but sometimes the concrete types you want to handle polymorphically cannot share a common base class.2 In that case, if the types provide the same interface, you can use a template to get polymorphism instead auto printArea(const auto& shape) -> void { std::println("Area is {:.2f}", shape.area()); } You can use this method with Squar

## Devirtualization and Static Polymorphism

DevFeed: [Devirtualization and Static Polymorphism](<https://devfeed.tech/articles/devirtualization-and-static-polymorphism-60974.md>)

Original publisher: [Read original article](<https://david.alvarezrosa.com/posts/devirtualization-and-static-polymorphism/>)

Author: David Álvarez Rosa

Published: 2026-02-25T09:45:00Z

Content type: tutorial

Language: en

Sources: [David Álvarez Rosa](<https://devfeed.tech/sources/david-alvarez-rosa.md>)

Topics: [Polymorphism](<https://devfeed.tech/topics/polymorphism.md>), [Compilers and Linkers](<https://devfeed.tech/topics/compilers-and-linkers.md>), [inlining](<https://devfeed.tech/topics/inlining.md>)

Tags: [compilation](<https://devfeed.tech/tags/compilation.md>), [compiler](<https://devfeed.tech/tags/compiler.md>), [compiler-flags](<https://devfeed.tech/tags/compiler-flags.md>), [cpp](<https://devfeed.tech/tags/cpp.md>), [inlining](<https://devfeed.tech/tags/inlining.md>), [performance](<https://devfeed.tech/tags/performance.md>), [polymorphism](<https://devfeed.tech/tags/polymorphism.md>)

### AI overview

The article explains how virtual dispatch can add pointer indirection, increase object size, and limit inlining. It describes compiler devirtualization and cross-translation-unit optimization, then recommends static polymorphism for latency-sensitive paths to reduce runtime dispatch cost.

### Source excerpt

Ever wondered why your "clean" polymorphic design underperforms in benchmarks? Virtual dispatch enables polymorphism, but it comes with hidden overhead: pointer indirection, larger object layouts, and fewer inlining opportunities. Compilers do their best to devirtualize these calls, but it isn't always possible. On latency-sensitive paths, it's beneficial to manually replace dynamic dispatch with static polymorphism, so calls are resolved at compile time and the abstraction has effectively zero runtime cost. Virtual dispatch § Runtime polymorphism occurs when a base interface exposes a virtual method that derived classes override. Calls made through a Base& are then dispatched to the appropriate override at runtime. Under the hood, a virtual table (vtable) is created for each class, and a pointer (vptr) to the vtable is added to each instance. Figure 1: Virtual dispatch diagram. The method foo is declared virtual in Base and overridden in Derived. Both classes get a vtable, and each object gets a vptr pointing to the corresponding vtable. On a virtual call, the compiler loads the vptr, selects the right slot in the vtable, and performs an indirect call through that function pointer. The drawback is that the extra vptr increases object size, and the indirection through the vtable makes the call hard to predict. This prevents inlining, increases branch mispredictions, and reduces cache efficiency. The best way to observe this phenomenon is by inspecting the assembly1 code emitted by the compiler for a minimal example class Base { public: auto foo() -> int; }; auto bar(Base* base) -> int { return base->foo() + 77; } For a non-virtual member function foo like in the example above, the free function bar issues a direct call bar(Base*): sub rsp, 8 call Base::foo() // Direct call add rsp, 8 add eax, 77 ret However, declaring foo as virtual changes bar's assembly into an indirect, vtable-based call bar(Base*): sub rsp, 8 mov rax, QWORD PTR [rdi] // vptr (pointer to vtable)

## About this Site

DevFeed: [About this Site](<https://devfeed.tech/articles/about-this-site-60972.md>)

Original publisher: [Read original article](<https://david.alvarezrosa.com/posts/about-this-site/>)

Author: David Álvarez Rosa

Published: 2018-05-11T20:18:00Z

Content type: article

Language: en

Sources: [David Álvarez Rosa](<https://devfeed.tech/sources/david-alvarez-rosa.md>)

Topics: [Self-hosted](<https://devfeed.tech/topics/self-hosted.md>), [Hugo](<https://devfeed.tech/topics/hugo.md>), [MkDocs](<https://devfeed.tech/topics/mkdocs.md>), [Org mode](<https://devfeed.tech/topics/orgmode.md>)

Tags: [about](<https://devfeed.tech/tags/about.md>), [hugo](<https://devfeed.tech/tags/hugo.md>), [org](<https://devfeed.tech/tags/org.md>), [self-hosted](<https://devfeed.tech/tags/self-hosted.md>), [self-hosting](<https://devfeed.tech/tags/self-hosting.md>)

### AI overview

The author introduces a personal blog focused on software, self-hosting, and lessons learned. The post describes its purpose, publishing cadence, and setup: it is hosted at a family home, exposed through a WireGuard tunnel to a VPS and global CDN, and written in Emacs Org mode before being exported to Hugo.

### Source excerpt

After nearly a decade, I've rebuilt my personal site from scratch--a blog on software, self-hosting, and lessons learned along the way. This first post is backdated to when I originally launched a site on this domain, back in 2018. What?--A personal blog. Posts aim to be concise, practical, and rigorous. Why?--To give back to the libre software community. To keep a record of my learning journey. To deepen my own understanding by writing things down.1 Who?--See the About page. Where?--Self-hosted at my mother's house in northern Spain (ha!), exposed to the Internet through a WireGuard tunnel to a VPS, and served via a global CDN. When?--Once or twice a month. How?--Written in Emacs Org-mode, exported to Hugo with a custom theme.2 If you spot an error or have suggestions, I welcome feedback--reach out via the contact link on the About page. As Einstein put it, "If you can't explain it simply, you don't understand it well enough." Feynman followed the same principle, testing his understanding by teaching from first principles. ↩︎ Inspired by the work of Edward Tufte and Matthew Butterick. ↩︎