Skip to content

IncludeXmlComments performance issues #2164

@coronabytes

Description

@coronabytes

Version 6.1.4 on .NET 5

We were using the following code to include multiple XMLs for comments (model dlls, app parts etc).
This was working for years until a dev referenced an external commercial library with it's own XML comment file (130k lines / 7 MB) and the generation time for the swagger.json went from ~600ms to 40s+ for each request.

Of course filtering out this file fixed the issue, however I don't think performance degradation should be that bad for a mere 130k lines of additional xml and even if it takes 40s why the swagger.json is it taking so long for subsequent requests.

I havn't looked at your code, yet it feels like you're not using a dictionary lookup and just search the xml nodes over and over again and the end result is not cached at all.

c.IncludeXmlComments(() =>
{
    try
    {
        var directory = Path.GetDirectoryName(typeof(Startup).Assembly.Location);

        var xdocs = Directory.EnumerateFiles(directory, "*.xml")
            .Select(x => XDocument.Load(x).Element("doc")?.Descendants()).ToList();

        var doc = new XDocument(new XElement("doc", xdocs));
        return new XPathDocument(doc.CreateReader());
    }
    catch (Exception)
    {
        var doc = new XDocument(new XElement("doc"));
        return new XPathDocument(doc.CreateReader());
    }
}, true);

Update:

var paramNode = _xmlNavigator.SelectSingleNode(
                $"/doc/members/member[@name='{methodMemberName}']/param[@name='{parameterInfo.Name}']");

eww xpath.. that explains it

Metadata

Metadata

Assignees

No one assigned

    Labels

    p3Low priority

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions