Compiling the SIMD version of python-rapidjson

Allan Lei
Allan Lei
Jan 7 · 1 min read

A recent task had me taking a look at alternative JSON libraries for the purpose of performance. One of them was python-rapidjson which offered support for SIMD.

Compiling

To get python-rapidjson to compile with SIMD, we need to define one of the SIMD macros, either RAPIDJSON_SSE2, RAPIDJSON_SSE42, or RAPIDJSON_NEON.

The chosen flag would then need to be passed to pip during install via CFLAGS. Depending on the flag, you would have to pass some addition options.

  • SSE2: CFLAGS="-DRAPIDJSON_SSE2=1"
  • SSE4.2: CFLAGS="-DRAPIDJSON_SSE42=1 -msse4.2"

One-liner to re-install the currently installed version as the SIMD version.

CFLAGS="-DRAPIDJSON_SSE42=1 -msse4.2" pip -v install -force-reinstall -no-binary python-rapidjson $(pip freeze | grep python-rapidjson)
Allan Lei

Written by

Allan Lei

The Adventures of Me

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade