YamlDotNet
YamlDotNet copied to clipboard
Use string interning
trafficstars
This cuts about 20% of parsing cost and probably more in final object graph size, depending on input data.
In terms of the LoadLarge benchmark:
| Method | Mean | Error | StdDev | Gen0 | Gen1 | Gen2 | Allocated |
|---|---|---|---|---|---|---|---|
| LoadLarge before | 136.9 ms | 3.11 ms | 9.03 ms | 7500.0000 | 3500.0000 | 1500.0000 | 39.65 MB |
| LoadLarge after | 114.4 ms | 3.70 ms | 10.67 ms | 6000.0000 | 2000.0000 | 1000.0000 | 39.65 MB |
This is just a simple string.Intern call. It might make sense to emplyor pass a pool, like a XmlNameTable does with XML, to save on scalar objects not just strings.