Skip to content

ENH: Optional dependencies for accelerating JSON serialization  #2944

Closed
@jonmmease

Description

@jonmmease

On top of #2943, I investigated a couple of interesting libraries we could potentially use as optional dependencies to further accelerate JSON serialization

pybase64

I played with pybase64 a little, and it looks like an easy way to get a decent speedup over the built-in python base64 module for performing the numpy base64 encoding step being introduced in #2943. This wouldn't require any refactoring or anything, and can drop the base64 encoding time (which is a substantial portion of the total json encoding time for figures that contain large numpy arrays) by something liek 20% to 40%.

orjson

orjson is a really impressive alternative JSON encoder that, in playing with a little bit, I've seen it be 2x to 5x times faster than the built-in Python json encoder.

orjson doesn't support custom JSON encoder classes (like PlotlyJSONEncoder), so supporting this as an optional dependency would require a total refactor of the current json encoding process.

Basically, we would need to switch to an architecture where we would preprocess the figure dictionary recursively to perform any conversions we need, and then feed that dictionary through the JSON encoder.

Another nice thing about orjson is that it automatically converts nan and infinity values to JSON null values, so the JSON re-endcoding stuff we were working through in #2880 wouldn't be needed (cc @emmanuelle ).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions