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
[BUG] [Go] MarshalJSON is extremely slow. (Performance Issue) #16948
Comments
@kokoichi206 thanks for brining it up and the benchmark result. If I remember correctly, the customized MarshalJSON method was added to meet the requirement of different use cases (e.g. oneOf/anyOf schema in properties, additional properties, nullable properties, etc) For your use cases, if these are not needed, what about adding an option to skip generating the MarshalJSON method? Would that help? |
@wing328 Having an option to skip generating the MarshalJSON method would be a welcome addition for our use case. |
yes please. let me know if you need help with the PR. |
closing this as the PR has been merged. happy to reopen if needed. |
Bug Report Checklist
Description
It might not be appropriate to raise this as a bug report.
json.Marshal of the generated struct was extremely slow (5-10x).
I guess that the cause lies in the part of the MarshalJSON method for the struct generation, where it's converting to a map of string and interface.
I couldn't understand the reason for processing every field in this manner.
I'd appreciate it if you could explain the reason for this kind of generation and, if possible, let me know how to avoid it during the generation process.
openapi-generator version
openapi-generator-cli:v7.0.0
(v5.1.1 also reproduced)
OpenAPI declaration file content or url
I used the petstore example from OpenAPI-Specification
Generation Details
I used docker of the cli.
docker run --rm -v $(shell pwd):/project openapitools/openapi-generator-cli:v7.0.0 \ generate -i /project/openapi.yaml -g go \ --additional-properties=packageName=component -o /project/gen/component -p enumClassPrefix=true
.openapi-generator-ignore
Steps to reproduce
json.Marshal
andjson.Unmarshal
.json.Marshal
of "component_method" is 6x slower than "component"test results
The benchmark test code
res.json
supplement
Related issues/PRs
Suggest a fix
The text was updated successfully, but these errors were encountered: