Skip to content

Improve IncludeXmlComments performance (2)#3044

Merged
martincostello merged 10 commits intodomaindrivendev:masterfrom
mus65:xml-comment-perf
Aug 27, 2024
Merged

Improve IncludeXmlComments performance (2)#3044
martincostello merged 10 commits intodomaindrivendev:masterfrom
mus65:xml-comment-perf

Conversation

@mus65
Copy link
Contributor

@mus65 mus65 commented Aug 25, 2024

Pull Request

The issue or feature being addressed

Fixes #2164

Details on the issue fix or feature implementation

This is a rebase and enhancement of #2443 (thanks to @stevendarby, added you as co-author).

This significantly improves the performance of the XML comment filters. The original fix #2443 created a dictionary of the members to avoid iterating the whole XPath for every single item.

I made some further improvements by replacing all usages of Select and SelectSingleNode with SelectChildren (added some helper extensions for this). This completely avoids XPath expressions and the documentation even mentions SelectChildren being faster.

I made the new constructors internal for now (which is also why I changed ParameterFilter to AddParameterFilterInstance etc.. DI fails otherwise). It felt wrong to me to make these public, but I can make these public if you want.

Tests

The existing tests imho already cover this code pretty well. I only added a test case for a bug I noticed in #2443 (there was a return instead of a continue in XmlCommentsDocumentFilter).

Performance

#2443 already mentions significant improvements (25s -> 4s). With another local test case I have with a 1.5MB XML file, generation time decreases from ~1900ms to ~200ms.

#2443 also mentions some concern about memory consumption, so I made some manual tests with a very big (30MB) XML document file: the XPathDocument itself already loads the document completely into memory which uses about 60 MB. Creating the dictionary creates an additional 40MB. So there is some additional memory consumption, but considering that 30MB is pretty extreme and most files should be < 1MB, the memory increase should be negligible for most applications. In my local test case with a 1.5 MB File, memory consumption after GC.Collect increased by about 1MB.

Loading
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

Successfully merging this pull request may close these issues.

IncludeXmlComments performance issues

4 participants