Skip to content

Conversation

Tarmil
Copy link
Owner

@Tarmil Tarmil commented Jun 9, 2025

Fixes #118

An initial naive implementation gives interesting results: memory allocations are lower for a small list, as expected, but somehow higher for a longer list and in both cases the time performance is much worse.

Method ListLength Mean Error StdDev Gen0 Gen1 Allocated
ListCollector 10 1,693.5 ns 12.15 ns 11.37 ns 0.0420 - 560 B
AsArray 10 237.4 ns 1.38 ns 1.29 ns 0.0458 - 600 B
ListCollector 100 15,422.6 ns 101.09 ns 89.62 ns 0.4272 - 5600 B
AsArray 100 1,627.9 ns 11.57 ns 10.82 ns 0.3662 0.0019 4808 B

@Tarmil Tarmil force-pushed the listcollector branch 2 times, most recently from 6471d1d to e8eb074 Compare June 9, 2025 09:07
@Tarmil
Copy link
Owner Author

Tarmil commented Jun 9, 2025

Of course, the memory allocation discrepancy was caused by the use of a boxing version of JsonSerializer.Deserialize. Updating System.Text.Json to a recent enough version to be able to use JsonTypeInfo solves this discrepancy. The time performance is still much worse than when using arrays though.

Method ListLength Mean Error StdDev Gen0 Gen1 Allocated
ListCollector 10 1,555.7 ns 4.95 ns 4.39 ns 0.0229 - 320 B
AsArray 10 236.4 ns 0.78 ns 0.65 ns 0.0458 - 600 B
ListCollector 100 15,024.3 ns 39.36 ns 32.87 ns 0.2441 - 3200 B
AsArray 100 1,621.1 ns 22.94 ns 20.33 ns 0.3662 0.0019 4808 B

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.

Use ListCollector to construct 'T list during deserialization

1 participant