Number Parsing at a Gigabyte a Second

Reviewed by Greg Wilson / 2022-03-30
Keywords: Performance

They say the devil's in the details, but angels live there too. Case in point: by combining a deep understanding of how computers represent numbers with some pragmatic engineering decisions, Lemire2021 shows that, "we can reach high parsing speeds (e.g., 1 GiB/s) on current 64-bit processors without sacrificing accuracy by focusing on optimizing the common number-parsing scenario where we have no more than 19 digits." Its analysis of tradeoffs (e.g., the size of lookup tables vs. the size of compiled code) and its careful benchmarking should warm every engineer's heart.

And on a related note, we'd like to congratulate Jack Dongarra, this year's winner of the Turing Award. He has devoted his career to designing, building, testing, and sharing high-performance software that has directly impacted the lives of countless researchers, and has been an inspiration to many of us. Congratulations, Jack.

Lemire2021 Daniel Lemire: Number parsing at a gigabyte per second. Software: Practice and Experience, 51(8):1700–1727, 2021, doi:10.1002/spe.2984.

With disks and networks providing gigabytes per second, parsing decimal numbers from strings becomes a bottleneck. We consider the problem of parsing decimal numbers to the nearest binary floating-point value. The general problem requires variable-precision arithmetic. However, we need at most 17 digits to represent 64-bit standard floating-point numbers (IEEE 754). Thus, we can represent the decimal significand with a single 64-bit word. By combining the significand and precomputed tables, we can compute the nearest floating-point number using as few as one or two 64-bit multiplications. Our implementation can be several times faster than conventional functions present in standard C libraries on modern 64-bit systems (Intel, AMD, ARM, and POWER9). Our work is available as open source software used by major systems such as Apache Arrow and Yandex ClickHouse. The Go standard library has adopted a version of our approach.