Skip to main content

A msgpack extension with special optimizations for PyPy

Project description

PyPy has a special optimization to store lists of ints and floats in a compact way, as they were C arrays of longs and doubles.

msgpack-pypy is an extension for msgpack which exploits this optimization to provide a very fast packing/unpacking of those. Essentially, it serializes a Python list of ints/floats by copying the whole array at once.

Note that such lists are serialized using the “ext types” mechanism provided by msgpack 2.0, which means that if you pack an object like [1, 2, 3] with msgpack-pypy, you cannot unpack it using the plain msgpack-python module, because the ext types are not recognized. You need msgpack-pypy to unpack it.

Despite the name, msgpack-pypy does work on CPython, although it does not bring any speed benefit there. It is useful if you have a system in which a PyPy process packs and object and a CPython process needs to unpack it.

Performance

For best performance, you should use a nightly PyPy built after Oct 21, 2013, as it contains a special optimization to read/write all the bytes representing the Python list at once.

Here are the results got by running this benchmark: https://bitbucket.org/antocuni/msgpack-pypy/src/default/benchmark.py

list of ints

CPython/msgpack: dump: 0.2287 ms load: 0.2075 ms PyPy/msgpack: dump: 0.2019 ms load: 0.2447 ms PyPy/msgpack_pypy: dump: 0.1321 ms load: 0.0391 ms

list of floats

CPython/msgpack: dump: 0.2295 ms load: 0.2096 ms PyPy/msgpack: dump: 1.1049 ms load: 1.9803 ms PyPy/msgpack_pypy: dump: 0.1373 ms load: 0.0392 ms

As you can see, dumping is 1.73x faster for ints and 8x faster for floats. The speedup for loading is even more impressive, as it is 6.2x faster for ints and 50x (fifty!) faster for floats.

If you use an older version of PyPy (such as the last stable release, 2.1), you still get a small speedup compared to the plain msgpack, but not as impressive. Dumping is 1.66x slower for ints and 1.67x faster for floats. Loading is 4x faster for ints and 16x faster for floats.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

msgpack-pypy-0.0.1.tar.gz (3.3 kB view details)

Uploaded Source

File details

Details for the file msgpack-pypy-0.0.1.tar.gz.

File metadata

  • Download URL: msgpack-pypy-0.0.1.tar.gz
  • Upload date:
  • Size: 3.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for msgpack-pypy-0.0.1.tar.gz
Algorithm Hash digest
SHA256 571ce37d38247e1293fffc1b3377ca13253f68387174ad77ee11cf737f987479
MD5 58b04ad2644cff8fd7d60a0d2a06c312
BLAKE2b-256 d0f544e8333cc32abe4d83d53629b9d7127dea7f92c9fdc54b401daf8f833700

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page