swagger-api / swagger-api/swagger-core
hashCode / toString performance issue on fully resolved OpenAPI objects
Nobody has claimed this yet.
- 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.
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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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