-
Notifications
You must be signed in to change notification settings - Fork 3
Improve performance of writing and serving JSON IIIF objects
If you are saving the JSON files in your server there is usually no need to improve the performance. However, if you are planning to create the JSON IIIF objects (manifests, collection...) "on-the-fly" each time the user requests them or caching the results temporarily you might want to improve the writing speed of the manifest.
tests/performance/performance_test.py
offers a way to test the performance of your server in serving a manifest with 2000 canvas and 2000 annotations, and one of 4000 canvas and 40000 annotations. Feel free to do a pull request with the results of the test which are appended to the csv files in the same folder.
If the speed is not enough for your needs, you can try one of the following actions or both:
- Install orjson:
pip install orjson
and usemyIIIFobject.orjson_save()
or.orjson_dumps()
instead ofmyIIIFobject.json_save()
or.json_dumps()
⚠️ Check the IIIF JSON object once and then run optimized Python code using the-O
flag e.g.python -O 0001-mvm-image.py
⚠️
orjson
is a much faster parser compared to the standard json
module.
While the -O
flag basically
An Intel(R) Core(TM) i7-4770HQ CPU @ 2.20GHz using pyIIIFpres
can produce 4000 canvas and 40000 annotations in 2.26 seconds, using orjson in 1.19 seconds and with the optimization in 0.48 seconds.