-
Notifications
You must be signed in to change notification settings - Fork 62
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
Avoid unmarshalling QueryRes.Hits into json default types #744
base: master
Are you sure you want to change the base?
Conversation
+1 |
5aea651
to
e92b605
Compare
Hey @georgantasp 👋🏻 I'm really sorry we took so long to get back to you. We can't merge your PR as-is because it would introduce breaking changes, which we won't do until we release our new client, at least. However, if you're up to slightly updating your PR (and I promise I'll answer faster this time), you can introduce a new Feel free to reach out if you disagree or want more explanations Thanks! |
Hey @Fluf22 👋 Understood about the breaking change. I expected that might force the decision. Your alternative idea is interesting... I had also heard that there was a brand new client in the works. Has that gotten any closer to release? Thanks for your review. Cheers |
I'll get back to you on Monday about this alternative, I didn't think about the fact it would be painful to unmarshal the same prop into two different types About the new clients, we are targeting GA this quarter. Sadly, despite what was initially planned, I don't think the first release of this new version will ship with generics, as we try to use struct methods, and generic on methods are not allowed in Go. |
@georgantasp you're right that it may not be the most efficient way to solve this issue, in the end. We better not double the amount of memory consumption (for holding hits), if possible. We just implemented something that could be useful for you in the beta version, if you're willing to try. Each method has a derivative Tell me if it's too much work to only get a raw |
Forgot to add an example, so it's more clear: here is the search method, returning the raw data from the API call, in the beta version of the client |
Hey @georgantasp , |
Describe your change
Unmarshal QueryRes.Hits into a dedicated
Hit
struct that holdsjson.RawMessage
(alias for[]byte
) and the bare minimum of object attributes. Implement customUnmarshalJSON
andMarshalJSON
to handle this json optimization.It should be a considered a breaking change because QueryRes.Hits was previously exported as
[]map[string]interface
. However, not breaking for developers usingQueryRes.UnmarshalHits
.What problem is this fixing?
During the unmarshalling of the QueryRes object, the existing implementation will completely unmarshal each hit object into json default types. As a result, the method QueryRes.UnmarshalHits remarshals the default types just to unmarshal again into the users's desired type. For large result sets and/or large objects, this can be wasteful.
Updated 2024-05-08:
The gap between the green http.request span and the UnmarshalHits span is where the Aloglia client unmarshals the response into the
QueryRes
struct andHits map[string]interface{}
. The UnmarshalHits span takes even longer than the gap because the client re-marshals the Hits just to unmarshal into the user's desired struct.