fix: make DocList.to_json() return str instead of bytes#1769
Merged
JohannesMessner merged 4 commits intomainfrom Sep 1, 2023
Merged
fix: make DocList.to_json() return str instead of bytes#1769JohannesMessner merged 4 commits intomainfrom
JohannesMessner merged 4 commits intomainfrom
Conversation
Signed-off-by: Johannes Messner <messnerjo@gmail.com>
Signed-off-by: Johannes Messner <messnerjo@gmail.com>
Signed-off-by: Johannes Messner <messnerjo@gmail.com>
Codecov ReportPatch coverage:
Additional details and impacted files@@ Coverage Diff @@
## main #1769 +/- ##
=======================================
Coverage 85.00% 85.00%
=======================================
Files 134 134
Lines 8845 8845
=======================================
Hits 7519 7519
Misses 1326 1326
Flags with carried forward coverage won't be shown. Click here to find out more.
☔ View full report in Codecov by Sentry. |
Signed-off-by: Johannes Messner <messnerjo@gmail.com>
|
📝 Docs are deployed on https://ft-fix-to-json-list--jina-docs.netlify.app 🎉 |
samsja
approved these changes
Sep 1, 2023
Closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
💥 Contains breaking change
This changes the return type of
DocList.to_json()andDocVec.to_json()from bytes to str, by decoding the bytes output obtained from theorjsonlibrary.This is done to make it consistent with
to_json()onBaseDocand in pydantic.from_json()does not need to be touched, since orjson happily accepts strings as well.This decoding step incurs a small performance penalty:

Running this multiple times I saw a
to_json()performance penalty of 8-15%, depending on the run.The
to_json()/from_json()roundrip penalty was consistently single digit percent, presumably because thefrom_json()call dominates this runtime.Note the breaking change this induces in cases like the one shown in the documentation that is also changed as part of this PR.
Also note that in the scenario there, after this change, a bytes object will be decoded to string, only to be encoded into bytes again.
closes #1766