Marshmallow fork optimized for dumping speed.
Project description
Althaia
Althaia: from Latin althaea, from Greek althaia - marsh mallow (literally: healing plant), from Greek althein to heal
What is it?
Althaia is a very simple fork of marshmallow, with patches to improve the performance when dumping large sets of data. It is then also compiled via cython for some extra performance boost. Ideally, these patches will one day find their way into the upstream marshmallow in some cleaner form, and this package will become obsolete.
How does it work?
During the serialization process, marshmallow repeats a lot of lookup operations for each object it's attempting to serialize, even though these values never change during the single execution. The main patch in this repo is basically reading those values once and creating a serializer function, which is much more performant on large data sets.
The entire thing is then compiled into C extension modules and released only as binary wheels.
Check out the original upstream PR for some discussion.
How fast is it?
It really depends on your data and usage, but using the benchmark.py
test from the upstream marshmallow repo,
Althaia seems to shave off some ~55% of execution time on average. These values are an example test run results
from the upstream benchmark:
Upstream(usec/dump) | Althaia(usec/dump) | Improvement(%) |
---|---|---|
23586.67 | 10033.57 | 42.54 |
478799.10 | 211586.81 | 44.19 |
231851.84 | 102877.19 | 44.37 |
The table is the result of the following commands:
python performance/benchmark.py --object-count 1000
python performance/benchmark.py --iterations=5 --repeat=5 --object-count 20000
python performance/benchmark.py --iterations=10 --repeat=10 --object-count 10000
They are also available in this repo as poetry run task upstream-performance
. Note that you may get different
results while running the benchmarks (the numbers above were obtained with Althaia v3.18.0, generally speaking you
should be getting better results with newer versions).
Contribution into the serialization benchmark is in the works (update: stalled), but local run seems to be almost comparable to Toasted Marshmallow, which is stuck on an old marshmallow 2.x branch. This means that Althaia gives you (almost) the speed of Toasted Marshmallow, with all the goodies of the latest marshmallow.
Library | Many Objects (seconds) | One Object (seconds) | Relative |
---|---|---|---|
serpyco | 0.00767612 | 0.00389147 | 1 |
Custom | 0.00965786 | 0.00467634 | 1.23917 |
lima | 0.0116959 | 0.00583649 | 1.51564 |
Pickle | 0.0137603 | 0.0136833 | 2.37246 |
serpy | 0.0352728 | 0.0181508 | 4.61839 |
Strainer | 0.0516005 | 0.0260506 | 6.71281 |
Toasted Marshmallow | 0.076792 | 0.0412786 | 10.207 |
Althaia | 0.101892 | 0.0484211 | 12.9943 |
Colander | 0.208514 | 0.105719 | 27.1649 |
Avro | 0.303786 | 0.151184 | 39.3314 |
Lollipop | 0.352331 | 0.173141 | 45.4262 |
Marshmallow | 0.531636 | 0.276243 | 69.8398 |
Django REST Framework | 0.531175 | 0.387527 | 79.4203 |
kim | 0.669759 | 0.336132 | 86.9576 |
Installation
pip install althaia
NOTE: This is still a work in progress and a wheel may not be available for your platform yet. PRs welcome!
Usage
There are two ways to use Althaia: as a standalone package, or as a drop-in replacement for marshmallow. Latter method is the recommended one. Add the following code as early as possible in your app bootstrap:
import althaia
althaia.patch()
This will install a Python meta path importer which will mimic marshmallow for the rest of your project, without any
changes to the codebase, i.e. import marshmallow
will work as expected. If and when this package becomes obsolete,
there will be no need to change the rest of your source to revert to upstream marshmallow.
Alternatively, you can use Althaia directly:
from althaia import marshmallow
# or, e.g.
from althaia.marshmallow import Schema
Though I'm not sure why one would do that.
Obviously, for all actual usage of marshmallow, you should always refer to the excellent marshmallow docs.
Bugs & Contributing
If there are bugs, please make sure they are not upstream marshmallow bugs before reporting them. Since the patches applied are picking apart some of the marshmallow internals, any breakage should be immediately visible, and the chances are that most bugs will be upstream bugs.
Contributing manylinux builds for the CI pipeline is most welcome.
If you have any other ideas on how to tweak the performance, feel free to contribute in any way you can!
Versioning & Releases
Althaia will always follow the upstream version of marshmallow to reduce confusion. In other words, Althaia version
X.Y.Z
will use marshmallow version X.Y.Z
.
Additionally, if it comes to some changes on Althaia side (repo structure, build process, bugfixes),
PEP440 will be followed and will be released either as alpha, beta, rc (X.Y.ZaN
, X.Y.ZbN
, X.Y.ZrcN
) if there is
still no change in the upstream dependency, or post-releases (X.Y.ZpostN
). Since bugfixing is discouraged for
post-releases, there may also be a hotfix release as X.Y.Z.N
, where N
is the hotfix version.
dev
releases may appear on test PyPI (X.Y.Z.devN
), but these are not relevant to the general public.
There will obviously be some delay between marshmallow and Althaia releases, and it is inevitable that I will get sloppy over time, so feel free to create a GitHub issue if you need an urgent update to latest marshmallow.
Developing
Althaia is using Poetry with a custom build script, and some taskipy scripts to facilitate things.
You can see them defined in pyproject.toml
, or just type poetry run task --list
.
Preparing a new version TL;DR:
- Edit
pyproject.toml
and change the version of the packages for upstream marshmallow and Althaia itself. - Run
poetry run task version-check
. - Run
poetry run task build
. - Run
poetry run task upstream-test
. - [Optional] Run
poetry run task upstream-performance
. - [Optional] Inspect the wheel content with
poetry run task inspect
. - Run
poetry run task publish-test
to deploy to test PyPI.
Known Issues
- If you have any marshmallow warnings ignored in your
pytest.ini
, i.e. you havefilterwarnings
set up to ignore an error starting withmarshmallow.warnings
, you will get an import error even if you're doingalthaia.patch()
in yourconftest.py
. As a workaround, you can change it to start withalthaia.marshmallow.warnings
. This happens because pytest is trying to import marshmallow before Althaia gets a chance to patch the importer.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
File details
Details for the file althaia-3.18.0.tar.gz
.
File metadata
- Download URL: althaia-3.18.0.tar.gz
- Upload date:
- Size: 51.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.14
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c75e01a10a81efc71c78429a82c5611a5d9be695ecbbfa26d744ed836a58f303 |
|
MD5 | 8782f241eab2c48b3178a275596863f9 |
|
BLAKE2b-256 | 7154d4c6f25e7afc01acac7d4160fc3c22d1da7beccb196120cd9f4682bcfd4f |
File details
Details for the file althaia-3.18.0-cp310-cp310-win_amd64.whl
.
File metadata
- Download URL: althaia-3.18.0-cp310-cp310-win_amd64.whl
- Upload date:
- Size: 714.0 kB
- Tags: CPython 3.10, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.14
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7075763159b4be7bc064cf423a4af42e4338c96019641348e2590d022334d7d1 |
|
MD5 | 4c6fe74a95be5f078af8edccdefff745 |
|
BLAKE2b-256 | 8945fabe3b8525e6498d0c8ab3d9cebed72e3e565b3ff0410009e2c780d58253 |
File details
Details for the file althaia-3.18.0-cp310-cp310-musllinux_1_1_x86_64.whl
.
File metadata
- Download URL: althaia-3.18.0-cp310-cp310-musllinux_1_1_x86_64.whl
- Upload date:
- Size: 1.1 MB
- Tags: CPython 3.10, musllinux: musl 1.1+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.14
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 072420b3456417b86a14f6db6200eda8699813659e34a29e6fb6dbaef99a5397 |
|
MD5 | 300c51692b7d1592d7a36c48d55a9e35 |
|
BLAKE2b-256 | 8a65f7ddb4a29dcfa420064bbf05c8b74f3de75a187c1905a3574d71ae01e1cb |
File details
Details for the file althaia-3.18.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: althaia-3.18.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 1.1 MB
- Tags: CPython 3.10, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.14
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2cec0a1e7fd05ce43fb54adcd61798546726f17800656cfce4d7495b3c65299c |
|
MD5 | a4d8ed6abfd482de68fb6eef81d6ddb6 |
|
BLAKE2b-256 | d757e6c4d5f6df0d62809b3d1bbb3ed3f8356a5c1b29390434e55fd4339376fd |
File details
Details for the file althaia-3.18.0-cp310-cp310-macosx_11_0_x86_64.whl
.
File metadata
- Download URL: althaia-3.18.0-cp310-cp310-macosx_11_0_x86_64.whl
- Upload date:
- Size: 947.1 kB
- Tags: CPython 3.10, macOS 11.0+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.14
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 16a1229eb0e2b7a9733bfc7da34c10d2bf4d726163e0696c25813b81b3305151 |
|
MD5 | 4562fb647ec648e43cc6af3fb8800e92 |
|
BLAKE2b-256 | 4669a626f2110d1c7841d60aae3dd7b41c840d77b718fe1e79361e22fe32c0c8 |
File details
Details for the file althaia-3.18.0-cp39-cp39-win_amd64.whl
.
File metadata
- Download URL: althaia-3.18.0-cp39-cp39-win_amd64.whl
- Upload date:
- Size: 714.0 kB
- Tags: CPython 3.9, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.14
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ec26c32db668b5cc5da301c714e4fe832ebd257189fa74e07a9b4632c77df519 |
|
MD5 | dfb50fbbfcec54c68a72b5ed0f8277a0 |
|
BLAKE2b-256 | a1949e55ea2b66d67598e0a0dabbe853eb27f3e0524be89e34012fc9f1c6e926 |
File details
Details for the file althaia-3.18.0-cp39-cp39-musllinux_1_1_x86_64.whl
.
File metadata
- Download URL: althaia-3.18.0-cp39-cp39-musllinux_1_1_x86_64.whl
- Upload date:
- Size: 1.1 MB
- Tags: CPython 3.9, musllinux: musl 1.1+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.14
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 52dfab0122b60104aa9de6115da85c2d7171be1ffbc90c011a0e51622288b6b2 |
|
MD5 | 444849fb7b516538e07c0e7d205ab5c5 |
|
BLAKE2b-256 | 11a8172257468f2707eb60c72137c5896754a5a097ae8af16dba7b54e116200e |
File details
Details for the file althaia-3.18.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: althaia-3.18.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 1.1 MB
- Tags: CPython 3.9, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.14
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b5bf4e666caa5aa6fb9bb2a5f9ade807537694bd6b403cdf36300b9ec7d0694d |
|
MD5 | f19f7479de269ccdc628c79d5397fcfc |
|
BLAKE2b-256 | a5c5b0f18a1fd7a7f3166554aa80ecb18d64d49dfc110b238011dcc11be1dc8b |
File details
Details for the file althaia-3.18.0-cp39-cp39-macosx_11_0_x86_64.whl
.
File metadata
- Download URL: althaia-3.18.0-cp39-cp39-macosx_11_0_x86_64.whl
- Upload date:
- Size: 949.0 kB
- Tags: CPython 3.9, macOS 11.0+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.14
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | af0a7e42e14d58ddd6b4396fbb8373481b4cdf829bb76ec285556c63f8ee3ba6 |
|
MD5 | 0640aa93216147e1733f2f089a9d9b91 |
|
BLAKE2b-256 | 669954efad3cf1da8ae1ba5284473311b3c7b54c6493dcf3b40fdd8df28887fb |
File details
Details for the file althaia-3.18.0-cp38-cp38-win_amd64.whl
.
File metadata
- Download URL: althaia-3.18.0-cp38-cp38-win_amd64.whl
- Upload date:
- Size: 721.1 kB
- Tags: CPython 3.8, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.14
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5eb8c067f04edab48213c4c3fa28a5010d327c063fe0efe499901d567d758d8d |
|
MD5 | 449d14e5c5c01d44b2810ea4c40c0067 |
|
BLAKE2b-256 | a5f6f3dc5a6cea95de522436a2231a0190d285b5813ef048b3720b76b5613afd |
File details
Details for the file althaia-3.18.0-cp38-cp38-musllinux_1_1_x86_64.whl
.
File metadata
- Download URL: althaia-3.18.0-cp38-cp38-musllinux_1_1_x86_64.whl
- Upload date:
- Size: 1.1 MB
- Tags: CPython 3.8, musllinux: musl 1.1+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.14
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5aa5086e45df1f7aece5c280518dcfde7ac80e686ee0c93a733a23d51bf68123 |
|
MD5 | 4632664cfc4f3fc649475739185106f3 |
|
BLAKE2b-256 | c072c013410901dc3b410e241e65e6ef35286cdb7214c30ca5675d80b2f22035 |
File details
Details for the file althaia-3.18.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: althaia-3.18.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 1.1 MB
- Tags: CPython 3.8, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.14
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 438bdc977796f29b2396549870dddf5f2066373e315534650bc06ecf698b8eaa |
|
MD5 | d185b347cd01c3cbde6cc238fd5d0ea7 |
|
BLAKE2b-256 | cc4cc775f567020be0ffe79a431b03d4ae94eabf6aa30aa88ef6cd969adb6a77 |
File details
Details for the file althaia-3.18.0-cp38-cp38-macosx_10_16_x86_64.whl
.
File metadata
- Download URL: althaia-3.18.0-cp38-cp38-macosx_10_16_x86_64.whl
- Upload date:
- Size: 941.5 kB
- Tags: CPython 3.8, macOS 10.16+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.14
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | fdc4d30963955398627e7122956020bf6fccdff735097e2fd6b0f2a5123f41f6 |
|
MD5 | 1e07b973eb86bfbbd61330129d8ece60 |
|
BLAKE2b-256 | 6cf55df068b045c16bed0dabf6cf1efb8b806ad2ee147f2ace45cfa5732a450e |