All Topics
All Topics
Technology
Technology
Design
Design
Programming
Programming
Science
Science
News
News
Gaming
Gaming
Entertainment
Entertainment
Business
Business
Finance
Finance
Sports
Sports
Health
Health
Food
Food
Travel
Travel
Art
Art
Music
Music
Books
Books
Education
Education
Politics
Politics
Personal
Personal
No algorithm. No AI slop. No ads. Just RSS. Pro-human. Indie writers. Real journalism. Open web. Chronological. Hand toasted.

Performance Optimization: Replacing Virtual Dispatch with Static Polymorphism in C++

By

dalvrosa

3mo ago· 4 min readenInsight

Summary

The article discusses performance issues with virtual dispatch in object-oriented programming and advocates for using static polymorphism as an alternative. It explains that while virtual dispatch enables runtime polymorphism, it introduces overhead through pointer indirection, larger object layouts, and reduced inlining opportunities. The author suggests that compilers attempt to devirtualize calls but often fail, making manual replacement with static polymorphism beneficial for latency-sensitive code paths where abstraction should have zero runtime cost.

Key quotes

· 3 pulled
Virtual dispatch enables polymorphism, but it comes with hidden overhead: pointer indirection, larger object layouts, and fewer inlining opportunities.
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.
Compilers do their best to devirtualize these calls, but it isn't always possible.
Snippet from the RSS feed
Ever wondered why your “clean” polymorphic design underperforms in benchmarks? Virtual dispatch enables polymorphism, but it comes with hidden …

You might also wanna read

Java Performance Optimization: Fixing 8 Common Anti-Patterns to Reduce Processing Time by 80%

The article presents a case study of Java performance optimization where fixing common anti-patterns dramatically improved application perfo

jvogel.me·2mo ago

Performance Optimization: Achieving 20x Speedup by Removing Code in Rust Data Versioning Tool

A developer shares a performance optimization story where removing code led to a 20x speedup in their data versioning tool. The team at Oxen

suriya.cc·3mo ago

Introducing tprof: A Targeted Profiler for Python Performance Optimization

The article introduces tprof, a targeting profiler for Python that addresses the inefficiency of traditional profilers when optimizing speci

adamj.eu·4mo ago

Building memchunk: A High-Performance Text Chunking Library for RAG Pipelines Using SIMD and memchr

The article details the development of memchunk, a high-performance text chunking library for RAG (Retrieval-Augmented Generation) pipelines

minha.sh·4mo ago

GitHub Repository: Fix for VLC Video Source Audio Stuttering and CPU Throttling on Low-End Devices

A GitHub repository containing code that fixes VLC Video Source audio stuttering and CPU throttling issues on low-end or older devices durin

github.com·4mo ago

Python 3.15's Tail-Calling Interpreter Shows 15% Performance Gain on Windows x86-64

The article discusses performance improvements in Python 3.15's interpreter, specifically highlighting that the tail-calling interpreter sho

fidget-spinner.github.io·5mo ago