swagger-api / swagger-api/swagger-core

hashCode / toString performance issue on fully resolved OpenAPI objects

Open
#4,470 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

backlog
Dominant language
Java
Stars
7.5k
Forks
2.3k
Avg merge
18h 1m
Merged PRs (30d)
10

Description

The recursive hashCode and toString implementation can become very expensive on fully resolved OpenAPI objects. Attached is a sample openapi file of 200KB which bloats to 168MB of string data if you print or log it or check it with a java debugger. The hashcode calculation takes > 300ms which can slow down programs a lot.

I wonder if hashCode really needs to traverse the entire object graph. toString can be optimized a lot if values are stripped.

sample-openapi.zip

        ParseOptions options = new ParseOptions();
        options.setResolveFully(true);
        URL resource = Main.class.getResource("/sample-openapi.yaml");
        SwaggerParseResult result = new OpenAPIParser().readLocation(resource.toExternalForm(), Collections.emptyList(), options);
        OpenAPI openAPI = result.getOpenAPI();

        long start = System.currentTimeMillis();
        System.out.println(openAPI.hashCode());
        System.out.println((System.currentTimeMillis() - start) + "ms");

        FileUtils.writeStringToFile(new File("\tmp\dump.dat"), openAPI.toString());

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 by reproducing the reported timings with the attached sample-openapi.zip and the Java example using ParseOptions.setResolveFully(true). Trace the generated OpenAPI object's hashCode and toString behavior, then compare performance and output size after any change. Done means substantially less hashCode work and toString string data for fully resolved objects without losing required object information.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
api
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.