Skip to content
research

The Nanosecond Trick Speeding Up All Code

A fundamental coding operation just got a mind-blowing speed boost, cutting processing times by over 75%. This sub-2-nanosecond breakthrough could make your entire software stack faster.

Stork.AI
Hero image for: The Nanosecond Trick Speeding Up All Code

TL;DR / Key Takeaways

A fundamental coding operation just got a mind-blowing speed boost, cutting processing times by over 75%. This sub-2-nanosecond breakthrough could make your entire software stack faster.

Your Code's Invisible Speed Limit

Every piece of software, from enterprise services to embedded devices, relies on a hidden performance bottleneck: integer-to-string conversion. This fundamental, often-overlooked operation—turning a numerical value into its text representation—underpins nearly every application. It’s an invisible constant, found in every log line, constructing JSON payloads, processing real-time metrics, and generating crucial traces.

Did you realize this "boring" conversion happens millions of times per second in high-throughput systems? Modern applications constantly transform raw integers into human-readable or machine-parsable strings. This immense scale transforms a micro-operation, one that developers normally take for granted, into a significant and cumulative drain on computational resources, impacting overall system throughput.

Establishing a performance baseline reveals the current cost. The standard C++ library function, `std::to_chars`, represents the typical performance for this ubiquitous task. In most real-world tests, this operation consumes between 4 and 8 nanoseconds per conversion. While that sounds trivial for a single instance, consider the cumulative effect across billions of operations, where string conversion silently sets the speed limit for vast amounts of code.

Breaking the Nanosecond Barrier

Jael Champagne Gareau and Daniel Lemire have unveiled a monumental breakthrough, shattering the performance ceiling for integer-to-string conversion. Their innovative algorithms now execute this seemingly mundane yet pervasive operation in under two nanoseconds. This unprecedented speed redefines what’s possible for a task fundamental to nearly every piece of software.

The new SIMD-powered methods dramatically outpace conventional approaches. Benchmarks reveal these algorithms are two to four times faster than the C++ standard library's `std::to_chars`, which typically requires four to eight nanoseconds for the same conversion. Furthermore, they achieve up to two times the speed of their closest competing libraries, establishing a new performance baseline across the industry.

These sub-nanosecond gains cascade into incredible real-world data processing capabilities. On tested workloads, the new technique achieved an astounding throughput of approximately 1.4 gigabytes per second. This translates the "nanosecond trick" from an academic curiosity into a practical engine for massive data volumes, significantly accelerating applications handling high-frequency logging, complex JSON payloads, and extensive metrics generation. The `simditoa` library, embodying this research, is already open-source, making this transformative performance accessible today.

How Parallel Math Changes Everything

Traditional integer-to-string conversion methods rely on a computationally expensive, serial process. CPUs typically extract digits one by one, repeatedly performing division operations. This sequential approach, while straightforward, creates a significant bottleneck, especially when applications generate millions of log entries or JSON payloads per second, where each character requires individual processing.

New algorithms fundamentally transform this process through parallel math. Researchers Jael Champagne Gareau and Daniel Lemire leverage SIMD (Single Instruction, Multiple Data) instructions, specifically advanced AVX-512 IFMA instructions, to execute multiple calculations concurrently. This powerful approach allows the CPU to avoid the slow, traditional digit-peeling process and instead perform several operations simultaneously.

The core innovation centers on using clever multiplicative inverses, rather than inefficient division, to simultaneously extract multiple digits. Modern CPUs can now execute up to eight tiny digit calculations side by side, effectively processing a number in parallel chunks. This paradigm shift moves conversion from a slow, serial chore to a rapid, parallel operation, drastically reducing the time required per conversion. For a deeper technical dive into the methodology, consult Converting an Integer to a Decimal String in Under Two Nanoseconds (PDF Preprint).

Get Your Free Performance Upgrade

Jael Champagne Gareau and Daniel Lemire's breakthrough transcends mere academic theory; it delivers a free performance upgrade available right now. Developers gain immediate access to the open-source `simditoa` library and its comprehensive benchmarks on GitHub, offering a clear, practical path to implementation. This groundbreaking algorithm, converting integers to strings in under two nanoseconds, is not just fast—it is production-ready.

The `simditoa` library arrives with robust real-world readiness, featuring two distinct versions optimized for varied data patterns. One variant targets scenarios with numbers of similar digit lengths, providing maximum efficiency for structured datasets. The other addresses messy, mixed-length inputs, ensuring consistent, high-speed performance across the unpredictable data streams common in logs, JSON payloads, metrics, and traces. This dual-pronged approach guarantees developers can select the most effective solution for their specific workload.

Implementing `simditoa` translates directly into tangible benefits. Achieving throughputs up to 1.4 gigabytes per second on tested workloads, this library offers a significant, immediate boost for any application performing high-volume integer-to-string conversions. It transforms a hidden bottleneck into a powerful asset, delivering a critical speed advantage without requiring extensive code changes.

Frequently Asked Questions

What is the simditoa library?

simditoa is an open-source C++ library developed by Jael Champagne Gareau and Daniel Lemire that uses SIMD instructions to dramatically accelerate integer-to-string conversions.

How much faster is this new integer-to-string method?

The new SIMD-based algorithm is 2 to 4 times faster than the standard C++ library's std::to_chars, converting an integer to a string in under two nanoseconds.

What technology makes this performance possible?

The speedup is achieved by avoiding traditional division and instead using modern CPU capabilities, specifically AVX-512 IFMA instructions, to process multiple digits in parallel.

Where is this optimization most impactful?

It provides a significant performance benefit in high-throughput applications that perform this conversion millions of times per second, such as logging systems, JSON serializers, and metrics pipelines.

One weekly email of tools worth shipping. No drip funnel.

one email per week · unsubscribe in two clicks · no third-party tracking

🚀Discover More

Stay Ahead of the AI Curve

Discover the best AI tools, agents, and MCP servers curated by Stork.AI. Find the right solutions to supercharge your workflow.

P.S. Built something worth using? List it on Stork

Back to all posts