swagger-api / swagger-api/swagger-codegen

[JAVA] Performance issues with AbstractJavaCodegen.toModelName()

Open
#12,313 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

Description

We are using swagger-codegen to generate Java code based on some OpenAPI specification. We noticed that the generation was taking a considerable amount of time so we decided to profile the generation. What we saw is that most of the time was spent inside AbstractJavaCodegen.toModelName(String name). After further investigation, we noticed that this method was being called 3390629 times and 3389750 of the times was for duplicated names. This means that only 879 times this method was being called with a unique name argument.

Just as a POC, we introduced a cache into this method and we got execution times up to 3x faster.

Here you can see a call stacktrace:
Call Stacktrace

Let us know if there is more information we can provide.

Swagger-codegen version

4.0.0-beta3

Swagger declaration file content or url
Command line used for generation

Steps to reproduce

Related issues/PRs

I haven't found any

Suggest a fix/enhancement

We were wondering if the introduction of a cache may be something you may want to consider. But we are not sure about the implications of such a cache.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at AbstractJavaCodegen.toModelName(String name) and profile a Java generation run to confirm the repeated-name calls described in the issue. Investigate the implications of caching this method, then validate that generation remains correct and measure whether the reported performance improvement is reproduced; no specific test or reproduction command is provided.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, openapi
Domain
performance, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.