Improve IncludeXmlComments performance #2443
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR seeks to address the performance issues highlighted in #2164
The slow performance mainly stems from the use of SelectSingleNode to search for member nodes. By creating a dictionary of all the member nodes once, the nodes can later be looked up against this dictionary much more efficiently.
In one app I work on - with a few hundred endpoints and lots of XML comments - this took swagger generation down from 25 seconds to 4 seconds.
I've tried to keep changes to a minimum and backwards compatible to increase chances of an early patch or minor release. For example, the existing set of constructors on the filters remain for external backwards compatibility but are no longer used within swashbuckle itself. The new set of constructors take a dictionary instead, which allows one to be created in the extension method and shared between all of the filters.
You may also get some further gains by fully parsing the XML document into a model of some kind, but I think that would be unnecessary as it was really the search for member nodes that was the killer.