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

Avoid unmarshalling QueryRes.Hits into json default types #744

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

georgantasp
Copy link

@georgantasp georgantasp commented Nov 2, 2023

Q A
Bug fix? no
New feature? yes?
BC breaks? no
Related Issue Fix #743
Need Doc update yes

Describe your change

Unmarshal QueryRes.Hits into a dedicated Hit struct that holds json.RawMessage (alias for []byte) and the bare minimum of object attributes. Implement custom UnmarshalJSON and MarshalJSON 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 using QueryRes.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:

image
The gap between the green http.request span and the UnmarshalHits span is where the Aloglia client unmarshals the response into the QueryRes struct and Hits 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.

@georgantasp georgantasp changed the title Full Unmarshaling and Remarshalling of Hits should be avoided Avoid unmarshalling QueryRes.Hits into json default types Nov 2, 2023
@vredens
Copy link

vredens commented Mar 18, 2024

+1

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

Successfully merging this pull request may close these issues.

Avoid unmarshalling QueryRes.Hits into json default types
2 participants