Skip to content

Conversation

@vvb
Copy link
Contributor

@vvb vvb commented Aug 13, 2021

PR checklist

  • Read the contribution guidelines.
  • Pull Request title clearly describes the work in the pull request and Pull Request description provides details about how to validate the work. Missing information here may result in delayed response from the community.
  • Run the following to build the project and update samples:
    ./mvnw clean package 
    ./bin/generate-samples.sh
    ./bin/utils/export_docs_generators.sh
    
    Commit all changed files.
    This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
    These must match the expectations made by your contribution.
    You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example ./bin/generate-samples.sh bin/configs/java*.
    For Windows users, please run the script in Git BASH.
  • File the PR against the correct branch: master, 5.3.x, 6.0.x
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.

This PR greatly reduces the time taken for Csharp-netcore code generation.
toModelName() method is invoked numerous number of times and it was accummulating to a lot of time.
This PR adds memoization to CSharp and DefaultCodeGen toModelName() methods.
This has reduced the C# SDK generation time for our rather large openapi spec from ~2 hours to 4 mins.
This has reduced the Golang SDK generation time for our rather large openapi spec from ~1h30m hours to 4 mins.

The generated code is the same as before.

spec: https://cdn.intersight.com/components/an-apidocs/1.0.9-4430/model/intersight-openapi-v3-1.0.9.4430.yaml

@vvb vvb changed the title Fix/enum slowness [CSharp-Netcore] Optimize time taken to generate CSharp code Aug 13, 2021
@vvb
Copy link
Contributor Author

vvb commented Aug 13, 2021

/cc @wing328 @mandrean @frankyjuang @shibayan @Blackclaws @lucamazzanti

@Blackclaws
Copy link
Contributor

Just out of curiosity if you're seeing generation times of 2 hours how large is your api definition file? I've been running the generator on what I would consider intermediate sized apis and it never took more than a minute.

@vvb
Copy link
Contributor Author

vvb commented Aug 13, 2021

Just out of curiosity if you're seeing generation times of 2 hours how large is your api definition file? I've been running the generator on what I would consider intermediate sized apis and it never took more than a minute.

Our spec is very large, over 350k lines, 5000+ model objects. You can check it out at https://cdn.intersight.com/components/an-apidocs/1.0.9-4430/model/intersight-openapi-v3-1.0.9.4430.yaml

@Blackclaws
Copy link
Contributor

Ok, yeah that is indeed a spec size that not a lot of people will have. That being said I have no issue with this pull request and it looks good to me, performance enhancements are always welcome even if they are mostly relevant to edge cases :)

@vvb vvb changed the title [CSharp-Netcore] Optimize time taken to generate CSharp code [CSharp-Netcore][Go] Optimize time taken to generate CSharp code Aug 14, 2021
@Blackclaws
Copy link
Contributor

I'm wondering if this seems to be an issue in multiple generators, whether this caching shouldn't be going into the default codegen somehow

@vvb
Copy link
Contributor Author

vvb commented Aug 14, 2021

I'm wondering if this seems to be an issue in multiple generators, whether this caching shouldn't be going into the default codegen somehow

so my initial fix was that - 8452565 But after some pointers from @wing328 it was clear that toModelName() is also invoked at many other places and so a better fix was to memoize toModelName itself.

@devhl-labs
Copy link
Contributor

If it took two hours before, how long does it take after this change?

@wing328
Copy link
Member

wing328 commented Aug 14, 2021

I'm wondering if this seems to be an issue in multiple generators, whether this caching shouldn't be going into the default codegen somehow

Good point. I'll see what I can do to address the problem in the default codegen.

@wing328
Copy link
Member

wing328 commented Aug 14, 2021

If it took two hours before, how long does it take after this change?

Down to a few minutes if I'm not mistaken.

@vvb
Copy link
Contributor Author

vvb commented Aug 14, 2021

If it took two hours before, how long does it take after this change?

1h56m -> 4m

@wing328
Copy link
Member

wing328 commented Aug 16, 2021

LGTM. I may submit another PR later to try to address similar problem for all generators.

@wing328 wing328 merged commit 849fec2 into OpenAPITools:master Aug 16, 2021
@vvb vvb deleted the fix/enum_slowness branch October 11, 2023 08:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants