Skip to content
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

significant performance improvement by making availableMethods in MethodPool a Map/HashMap #159

Open
bseiller opened this issue May 8, 2018 · 2 comments

Comments

@bseiller
Copy link

bseiller commented May 8, 2018

We are using jaxrs-analyzer-maven-plugin/jaxrs-analyzer to generate swagger for our service endpoints.
The generation process got exponentially slower with every service class we added to the scanned packages.
When it got unbearable we investigated and found the culprit in the class
com.sebastian_daschner.jaxrs_analyzer.analysis.bytecode.simulation.MethodPool
There the LinkedList availableMethods is being used as 'cache' which scanned/iterated completely for every get(MethodIdentifier) in the worst case => O(n).
Also addProjectMethod does not check if a method is already in the list, which results in duplicate entries.
This resulted in a runtime of
~ 160s with 28512 entries.

Making availableMethods a Map/HashMap resulted in a runtime of
~ 14s with now only 7769 entries.
=> both faster and smaller memorywise

To make using a HashMap possible we introduced a method
MethodIdentifier getIdentifier()
in the interface com.sebastian_daschner.jaxrs_analyzer.model.methods.IdentifiableMethod
and implemented it for all classes implementing IdentifiableMethod.

The resulting swagger.json was almost the same but for one minor difference;
On of the scanned services returns a object with a member
private Map<Integer, List<Message>> messages
With the original code this was translated to

"messages": {
      "type": "array",
      "items": {
            "$ref": "#/definitions/Messages"
      }
}

which is close, but still...
in the changed code it became

"messages": {
      "type": "object"
}

really can't explain is the reason for this is...

If you are interested I could create a pull request, but since it changes your design I wanted to run it by you.

Cheers & thanks for this very nice tool!

@bseiller bseiller changed the title significant performance improvement by making availableMethods of MethodPool a Map/HashMap significant performance improvement by making availableMethods in MethodPool a Map/HashMap May 8, 2018
@sdaschner
Copy link
Owner

Hi there,

Thanks for using this tool and raising awareness! Yes, a PR would help me a lot, either for merging it directly or as a starting point.

@bseiller
Copy link
Author

Ok - we are nearing a release, so time is a little short, but i'll try to do a PR with our modifications next week.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants