-
-
Notifications
You must be signed in to change notification settings - Fork 136
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
GraphQLSchema serialization using pickle #173
Comments
It's currently not supported. You can serialize a schema to SDL using Will keep this open as a reminder to maybe/someday investigate whether supporting this would be feasible somehow without totally reinventing GraphQL-Core. If anybody wants to work on this or has comments or ideas how to solve this, please feel free to jump in. |
@rpgreen Out of curiosity, where do you expect performance gains when serializing your schema? |
We are using build_schema() at runtime and there's a significant performance hit (several hundreds ms up to several seconds) I assume it would be much faster to rehydrate a serialized schema object if that was possible. |
@rpgreen Interesting. Maybe it would be worthwile then to profile why/where |
Thanks @erikwrede for the profiling. Did you use the latest version (3.2.1) of GraphQL-core? I'm asking because there have been some speedups and get_visit_fn is actually deprecated. |
@rpgreen I have looked into this a bit more. It seems you want to pickle only schemas that have been produced from SDL, which makes this issue a bit more restricted and easier to tackle. The reason why this currently does not work is the implementation in Also, I'm still not sure how much faster pickling really would be, and whether improving the performance of |
Btw, I have added a test for pickling schemas here which is currently skipped. |
Just checked, seems like I messed up the version in my test env. The new version sees a performance improvement roughly equal to removing |
@rpgreen @erikwrede I have now created a branch pickle-schema that allows serialization of a schema built from SDL. It may be a bit slower when building schemas, as it uses a class instead of local functions and therefore needs attribute lookups, but it does not seem to be a big difference. Please check it out and give me feedback whether you think this should go to the main branch. |
@Cito @erikwrede Thanks for looking into this. We will try this out and share our results. From our perspective, we would be fine with a higher one-time cost of building the schema as long as we have a way to quickly serialize/deserialize at runtime. |
Hi folks, |
@rpgreen-vendia thanks for the feedback. Will consider this when working on the next version. Please have some patience as I cannot work on this full time and am currently deep in other projects. Feedback from others is also appretiated. |
Hi there,
Please let me know if I can give more detail on any of this and/or if I'm doing any part of this wrong. Thanks again! Mika |
Thanks for the feedback @mika-vendia . Will look into this. |
I have started working on this issue again. First step was to update the @mika-vendia I have also looked into your point 1 (deepcopy of a pickled schema). I was able to create a unit test reproducing the problem. The cause is clear - the unpickled standard scalar type objects are different from the original ones. I have fixed this now by replacing them with the original ones when creating the schema. The unit test passes. Maybe you can check out if point 1 is also solved for you with the current Will continue to work on this later this week. Maybe there is a better way of solving this, more fundamentally by somehow guaranteeing that singletons are preserved in the pickle/unpickle process. Will also look into your point 2. |
Thank you, @Cito! I will test out issue 1 and let you know how it goes. |
@Cito - @mika-vendia has confirmed that the fix for the first issue is working as expected. Let us know if you need any more details on the second issue. |
@danvendia I have solved the issue now a bit more fundamentally in this branch and extended the tests. Should still be working. Wil try to tackle the second issue next week. |
@danvendia Update: I have looked into the second issue, can reproduce it and have an idea how to solve it, even more fundamentally than the last fix. Will continue to work on it this week. |
@Cito - awesome! Thanks for the update! |
@danvendia The complete fix has now been merged into the main branch and will be available with the next alpha release. Please open a new issue if there are still any problems with this. |
@danvendia @mika-vendia @rpgreen-vendia: This is now available in v3.3.0a2 for testing. |
Just came by to say you rock @Cito 🎸 |
Is it possible to serialize an instance of GraphQLSchema?
We would like to dump and load an instance of GraphQLSchema to/from a file for performance reasons.
It does not appear to be serializable using pickle by default.
Thanks in advance.
The text was updated successfully, but these errors were encountered: