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

Use cattrs to optimize response serialization #67

Open
JWCook opened this issue May 12, 2021 · 1 comment
Open

Use cattrs to optimize response serialization #67

JWCook opened this issue May 12, 2021 · 1 comment
Assignees
Labels
logistics CI builds, project config, refactoring, and other logistical details performance
Milestone

Comments

@JWCook
Copy link
Member

JWCook commented May 12, 2021

Since we're already using attrs, there would be several potential benefits from using cattrs, which could be considered a pre-serialization/post-deserialization optimization step. It uses attrs definitions to recursively unstructure classes and nested data structures into dicts and builtin types, and vice versa. In relational db terms, this is similar to adding a serialization library (like Marshmallow) on top of an ORM framework (like SQLAlchemy), but without needing to define a separate model + serialization schema. There are some more details on how it works in this article.

This would make both serialization and deserialization a little more efficient, avoid some edge cases inherent with pickling (or more specifically unpickling classes), and open up the possibility for other serialization formats like JSON.

@JWCook JWCook added logistics CI builds, project config, refactoring, and other logistical details performance labels May 12, 2021
@JWCook JWCook closed this as not planned Won't fix, can't repro, duplicate, stale Jul 13, 2022
@JWCook JWCook added this to the v0.13 milestone Oct 4, 2024
@JWCook JWCook reopened this Oct 4, 2024
@JWCook JWCook self-assigned this Oct 4, 2024
@JWCook
Copy link
Member Author

JWCook commented Oct 4, 2024

Here are requests-cache's serialization modules that make use of attrs + cattrs, for reference: https://github.com/requests-cache/requests-cache/tree/main/requests_cache/serializers For this library, I would opt to keep things a bit simpler since we don't currently have a need for some of the more advanced features supported there.

I'll work on this next, whenever I have a free weekend to dedicate to it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
logistics CI builds, project config, refactoring, and other logistical details performance
Projects
None yet
Development

No branches or pull requests

1 participant