ForeverZer0 / SharpNBT

A pure CLS-compliant C# implementation of the Named Binary Tag (NBT) format specification commonly used with Minecraft applications, allowing easy reading/writing streams and serialization to other formats.
MIT License
25 stars 9 forks source link

SNBT Parsing Is Horribly Slow #2

Closed LeadAssimilator closed 3 years ago

LeadAssimilator commented 3 years ago

The SNBT parser appears to rely heavily on Regex but the regexes aren't compiled.

Specifying the RegexOptions.Compiled in the Regex constructor will yield a massive speedup.

ForeverZer0 commented 3 years ago

I didn't do extensive benchmarking on the parser with large files, not sure how to interpret the given description in any empirical sense being it is heavily context-dependent, but adding the compiled flag will be a simple fix. It will add some load time to the assembly, but it should be insignificant for all the more there are.

ForeverZer0 commented 3 years ago

As of https://github.com/ForeverZer0/SharpNBT/commit/f27bebf6c9057ab6e2ba9e3726d5911b176c1ab7, regular expressions used in the library use the Compiled flag.

There is also a release for this version, which will likely be updated on NuGet by the time this message is seen.