Improve XmlDictionaryWriter UTF8 encoding performance (#73336)
authorDaniel Svensson <daniel.svensson@crm.se>
Tue, 4 Apr 2023 22:11:10 +0000 (00:11 +0200)
committerGitHub <noreply@github.com>
Tue, 4 Apr 2023 22:11:10 +0000 (15:11 -0700)
commite0c94f84b47fdd48435a625446123f89268b9c20
treebd416c3683e5a30bd22a1606786b98e94b348dc3
parentb54d6ef10e5d4d7775b45ef242708bf7c0f1f92f
Improve XmlDictionaryWriter UTF8 encoding performance (#73336)

* Speed up text encoding

* Update implementation

* Add tests for binary xml strings

* limit counting code to 256 bit vectors

* reword comment

* rename test

* move bytesmax

* Fix bytesMax after moving variable initialization

* use unicode escape value in test

* fix test typo "*" -> "+"

* Update src/libraries/System.Private.DataContractSerialization/src/System/Xml/XmlStreamNodeWriter.cs

Co-authored-by: Stephen Toub <stoub@microsoft.com>
* Remvoe vectorized code from UnsafeGetUTF8Length

* Fix overfload

* use for loop which seems faster

* remove vector loop

* make sealed encoding to allow devirtualisation

* back some changes

* use uint for UnsafeGetUTF8Chars comparison

* revert more changes

* Fix cutoff based on new measurements

* use BinaryPrimitives.ReverseEndianness as suggested

* Update cutoff from 24 to 32 chars before calling, due to regression for text based DataContractSerializer

* Remove sealed encoding since it only improves XmlConvert

---------

Co-authored-by: Stephen Toub <stoub@microsoft.com>
src/libraries/System.Private.DataContractSerialization/src/System/Xml/XmlStreamNodeWriter.cs
src/libraries/System.Runtime.Serialization.Xml/tests/XmlDictionaryWriterTest.cs