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 ~45% of execution time on average. These values are an example test run results
from the upstream benchmark:
Upstream(usec/dump) | Althaia(usec/dump) | Improvement(%) |
---|---|---|
22672.54 | 11969.85 | 52.80 |
463016.55 | 267486.80 | 57.78 |
231068.86 | 128756.36 | 55.72 |
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
.
Contribution into the serialization benchmark is in the works, 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.14.1a1.tar.gz
.
File metadata
- Download URL: althaia-3.14.1a1.tar.gz
- Upload date:
- Size: 49.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b591337883b8eab9d5cfa3353352bdd34e2b5986e4f62d6ac92aa945fce3cbe9 |
|
MD5 | 2ace27e44be035db1beb24cfe5b31b4c |
|
BLAKE2b-256 | fddee651e7d87c2ae042140c0eaf1fb27445cea53c54a1b2a3ee914766aeda43 |
File details
Details for the file althaia-3.14.1a1-pp38-pypy38_pp73-manylinux_2_17_x86_64.manylinux_2_5_x86_64.manylinux1_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: althaia-3.14.1a1-pp38-pypy38_pp73-manylinux_2_17_x86_64.manylinux_2_5_x86_64.manylinux1_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 772.1 kB
- Tags: PyPy, manylinux: glibc 2.17+ x86-64, manylinux: glibc 2.5+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 74a0940c348999ddbefe0d7dd37be60a727604a19b1cdf0e8abc56a415af775a |
|
MD5 | 22528e50e1c7913ca6ef0f556fd26688 |
|
BLAKE2b-256 | c6a04013659962455947ddfaffa0c6cb146c4ee795ca35b196a436f5732ffe51 |
File details
Details for the file althaia-3.14.1a1-cp310-cp310-win_amd64.whl
.
File metadata
- Download URL: althaia-3.14.1a1-cp310-cp310-win_amd64.whl
- Upload date:
- Size: 758.5 kB
- Tags: CPython 3.10, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 72fcafa7676f9b049884b6fbd8120b917abd7f8d1ac081609340ba9c6c4ff7c0 |
|
MD5 | e0f7e804971e338f3204867ba045bfef |
|
BLAKE2b-256 | b445f8ff00baab3f5823218d6f3974586a9314e44595be5c35e8086b93427716 |
File details
Details for the file althaia-3.14.1a1-cp310-cp310-musllinux_1_1_x86_64.whl
.
File metadata
- Download URL: althaia-3.14.1a1-cp310-cp310-musllinux_1_1_x86_64.whl
- Upload date:
- Size: 1.0 MB
- Tags: CPython 3.10, musllinux: musl 1.1+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 975b671aceb9acd6473896e490176309dd8422aad7cd8f20e52c191d7b8b383e |
|
MD5 | d8b71b04fc3844e0ba6e2d482bb81452 |
|
BLAKE2b-256 | 828e6d961ce240a624c752d7625a639bf00c5b755a2c701d9386e29dda688c08 |
File details
Details for the file althaia-3.14.1a1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: althaia-3.14.1a1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 1.0 MB
- Tags: CPython 3.10, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7745277be5369b1a3739703f9ebecf6769911d54b3910f23f2a5064befea7d3b |
|
MD5 | 485177290b4fffeb1f1970d647112205 |
|
BLAKE2b-256 | c489c08646e9c7bd3e56f664b05c370e20008af19c07223938fd8dca21ef8fb5 |
File details
Details for the file althaia-3.14.1a1-cp310-cp310-macosx_10_15_x86_64.whl
.
File metadata
- Download URL: althaia-3.14.1a1-cp310-cp310-macosx_10_15_x86_64.whl
- Upload date:
- Size: 980.8 kB
- Tags: CPython 3.10, macOS 10.15+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7f629dc2629661ec6375c1bd870c4c796379b028857a974087289f1147e12c7b |
|
MD5 | e52c3f2256b2e4f388d45d4cb6ebe0bb |
|
BLAKE2b-256 | c0634c658a02308dde3f7ed3872e4b7c648b824d89a891ea046068cdb98c6fe9 |
File details
Details for the file althaia-3.14.1a1-cp39-cp39-win_amd64.whl
.
File metadata
- Download URL: althaia-3.14.1a1-cp39-cp39-win_amd64.whl
- Upload date:
- Size: 754.8 kB
- Tags: CPython 3.9, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 02542bb21cf648d879d57293c0714f3cae20214d67fb32484b39e16aeaf3f9ad |
|
MD5 | 6cda76f39d9e2a8afda7f992453de742 |
|
BLAKE2b-256 | 548a692b0d17f74c1147ebeca15022a3089395f3d6bbf1427c2bc608729d35bd |
File details
Details for the file althaia-3.14.1a1-cp39-cp39-musllinux_1_1_x86_64.whl
.
File metadata
- Download URL: althaia-3.14.1a1-cp39-cp39-musllinux_1_1_x86_64.whl
- Upload date:
- Size: 1.0 MB
- Tags: CPython 3.9, musllinux: musl 1.1+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8cabe6e99de17264da08d00f1a8f6ece3e8a4820ce6b9ca10295468f3c793849 |
|
MD5 | e1d02b73ebe086ae9c8e126601aee630 |
|
BLAKE2b-256 | 1626336fc716bc0755cfc7b94dad689046fcee9881060db8c79f2e8c833d2972 |
File details
Details for the file althaia-3.14.1a1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: althaia-3.14.1a1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 1.0 MB
- Tags: CPython 3.9, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f6faaa74479f8aac43aebdb8d7fccce0183849e14ac6dbf4278163b728317896 |
|
MD5 | 72231326034671b4fc0ba65ca006ad09 |
|
BLAKE2b-256 | eb1be76740a37ef6ba715ac7de387b774d7826836c0ea093bf9aad16be5c9281 |
File details
Details for the file althaia-3.14.1a1-cp39-cp39-macosx_10_15_x86_64.whl
.
File metadata
- Download URL: althaia-3.14.1a1-cp39-cp39-macosx_10_15_x86_64.whl
- Upload date:
- Size: 979.9 kB
- Tags: CPython 3.9, macOS 10.15+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8de33b9a065d0af10111702928e99433875f8054d6fe8dcc29ac6df871df2b35 |
|
MD5 | 92bb48d486499c2dbcc561ff14581b06 |
|
BLAKE2b-256 | 168fa94d36a7978619fd4634d7eb68ae63e2124cfe2fd2369c78541796ac03b2 |
File details
Details for the file althaia-3.14.1a1-cp38-cp38-win_amd64.whl
.
File metadata
- Download URL: althaia-3.14.1a1-cp38-cp38-win_amd64.whl
- Upload date:
- Size: 766.3 kB
- Tags: CPython 3.8, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 59d6388f4f38e974f0aac883bdfe98a3017446af66ea5eb0ce549b1213858ca0 |
|
MD5 | 5d1c0f398cc2c38d1dfe22de995dbfff |
|
BLAKE2b-256 | 5bff06e93ce12054b87176ed6bce968078456a1cb52ce3daddb6e5b1d007f0a1 |
File details
Details for the file althaia-3.14.1a1-cp38-cp38-musllinux_1_1_x86_64.whl
.
File metadata
- Download URL: althaia-3.14.1a1-cp38-cp38-musllinux_1_1_x86_64.whl
- Upload date:
- Size: 1.0 MB
- Tags: CPython 3.8, musllinux: musl 1.1+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | bd552000f2a189129c8a005deddeb16ccbac24c83990af9afb4635b1daa5b7d0 |
|
MD5 | a73c5ca07bf9fbf82a457d765bccbae6 |
|
BLAKE2b-256 | 5f855987eef88c699bce654c2494e28b357b972a32c4a834af5b2f914cec69d8 |
File details
Details for the file althaia-3.14.1a1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: althaia-3.14.1a1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 1.0 MB
- Tags: CPython 3.8, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0b931c3664966d84df8cec14dc63b2690101fb9ee82a9f25272e22edd7e2c8b3 |
|
MD5 | b66f3fed2193e8569b149857ed4252ee |
|
BLAKE2b-256 | c96b30549bcd6b886bf1f238aec90ead0a406843f480bea9aa1924b773df34ab |
File details
Details for the file althaia-3.14.1a1-cp38-cp38-macosx_10_15_x86_64.whl
.
File metadata
- Download URL: althaia-3.14.1a1-cp38-cp38-macosx_10_15_x86_64.whl
- Upload date:
- Size: 956.4 kB
- Tags: CPython 3.8, macOS 10.15+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 880adb375c328d4c624a0c208c1f8bce7140d4c41519493ffc9c2f7b745a013b |
|
MD5 | b16a47effba0d45390ea35ff86f46a6c |
|
BLAKE2b-256 | d8c1ba6a746ced2ba01a08c215926636f809ca5676efc18dfdeb238e4af404b5 |