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

Using toastedmarshmallow for JIT #22

Open
Rishi321 opened this issue Sep 29, 2020 · 2 comments
Open

Using toastedmarshmallow for JIT #22

Rishi321 opened this issue Sep 29, 2020 · 2 comments

Comments

@Rishi321
Copy link

Has this library been tested with ToastedMarshmallow?
We have been using this library to great effect recently in a project (for about 8 months), but we're now seeing some performance hits during the Marshmallow serialization (sometimes 100's of ms) when dealing with many objects (100's)

I've seen people talk about ToastedMarshmallow and notice that the compute_schema recreates schema instances everytime, according to the ToastedMarshmallow documentation this will reduce the gain heavily.

Is there a reason we recreate schema objects every time? If not, what would be the best way to change the code to allow one schema object per resource?

I tried changing the code and using an in-memory object dict as an object cache, but toastedmarshmallow still made no performance impact.
Anybody tried this before?

Also posted here: miLibris#192

@multimeric
Copy link
Owner

multimeric commented Sep 29, 2020

Hi @Rishi321. I'm still hoping to merge with https://github.com/AdCombo/flask-combo-jsonapi, so there is some chance you could ask this question over there.

To answer your question, though, I believe it's fairly core to this library that we can create Schema instances on the fly. For example, if the user requests certain relationships or certain fields via query params, we have to create a new schema that includes these fields, and this has to happen per request.

Consider this function, which does exactly that (builds a schema instance based on the query string): https://github.com/TMiguelT/flapison/blob/379b37774fd16197c803a7b5e3bd9eca99191337/flapison/schema.py#L12-L90.

How could we make this compatible with ToastedMarshmallow?

@Rishi321
Copy link
Author

Sorry for skipping out on the answer for so long, my attention was diverted to other projects.
To answer the dynamism of the schema, we could cache the schema based on given query parameters (probably all of them).
This is still gainful because API requests are usually built into code and are standard for an app or websites pages.
Eg. If a page does a query /profiles?include=account,payments then this query is not going to change on this page unless the code of the page is changed, hence the cached schema should be the same for the same type of request on this page.

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

No branches or pull requests

2 participants