Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: pickle frontend payloads #3340

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

benedikt-bartscher
Copy link
Contributor

@benedikt-bartscher benedikt-bartscher commented May 19, 2024

Benefit from pickles referential serialization to reduce reflex event payload size
This is especially useful when dealing with complex sqlalchemy models which can contain circular and self-referencing relationships
Serialization should also be faster? (did not measure the impact yet)

We could drop most of the serializers and rely on pickle. You can test this with bare sqlalchemy models like this:

import reflex as rx
from reflex.utils.serializers import serializer
from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column

@rx.model.ModelRegistry.register
class Base(DeclarativeBase):
    pass


@serializer
def serialize_base(obj: Base):
    return obj

class TestModel(Base):
    __tablename__: str = "test"

    id: Mapped[int] = mapped_column(primary_key=True, autoincrement=True)
    name: Mapped[str] = mapped_column(default="test")
    ...

Advantages:

  • Smaller payloads
  • Faster serialization
  • Referential Serialization (allow recursion)
  • Custom serializers are optional, most objects should just work fine out of the box.
  • Object identities in js. Should allow for easier comparison on client side. For example, if an array of objects contains a specific object which currently does not work, because [{a:1}].includes({a:1}) is false in js

Disadvantages:

  • Payloads are not human-readable anymore
  • dependency on pickleparser, but we should implement our own version which fits our needs anyway

TODO: custom dill/pickle dispatch table for frontend. dill currently has no support for this? Not really needed, since users can still define a @serializer function to control serialization.

TODO: reflex pickleparser implementation

benefit from pickles referential serialization to reduce reflex event payloads
this is especially useful when dealing with complex sqlalchemy models
which can contain circular and self-referencing relationships
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant