PostgreSQL Sees Up To 4x Query Performance With SIMD-Optimized JSON Escaping

Written by Michael Larabel in Programming on 6 August 2024 at 07:01 AM EDT. 17 Comments
PROGRAMMING
For those making use of JSON data with the PostgreSQL database server, now merged code to make use of SIMD for JSON escaping has shown up to a 4x improvement for query performance when dealing with lots of JavaScript Object Notation data.

Since PostgreSQL 16 has been a lot of SIMD optimizations on both x86_64 and ARM. Now merged to PostgreSQL Git for what is PostgreSQL 18 development with v17 already branched and in beta phase, the SIMD support has been expanded to help with JSON escaping.

David Rowley who pursued this SIMD-optimized JSON escaping explained in the commit merged yesterday:
"Here we adjust escape_json_with_len() to make use of SIMD to allow processing of up to 16-bytes at a time rather than processing a single byte at a time. This has been shown to speed up escaping of JSON strings significantly.

Escaping is required for both JSON string properties and also the property names themselves, so this should also help improve the speed of the conversion from JSON into text for JSON objects that have property names 16 or more bytes long.

Escaping JSON strings was often a significant bottleneck for longer strings. With these changes, some benchmarking has shown a query performing nearly 4 times faster when escaping a JSON object with a 1MB text property. Tests with shorter text properties saw smaller but still significant performance improvements. For example, a test outputting 1024 JSON strings with a text property length ranging from 1 char to 1024 chars became around 2 times faster."

So nearly four times faster when dealing with large sets of JSON data or around two times with smaller sizes. Not too surprising as with the "simdjson" project we've also seen how AVX/AVX-512 can make JSON parsing extremely fast and continues to show impressive wins with simdjson benchmarks.

PostgreSQL logo


Great seeing the continued SIMD efforts by PostgreSQL!
Related News
About The Author
Michael Larabel

Michael Larabel is the principal author of Phoronix.com and founded the site in 2004 with a focus on enriching the Linux hardware experience. Michael has written more than 20,000 articles covering the state of Linux hardware support, Linux performance, graphics drivers, and other topics. Michael is also the lead developer of the Phoronix Test Suite, Phoromatic, and OpenBenchmarking.org automated benchmarking software. He can be followed via Twitter, LinkedIn, or contacted via MichaelLarabel.com.

Popular News This Week