mikegoatly / lifti

A lightweight full text indexer for .NET
MIT License
184 stars 9 forks source link

Consider switching to using ValueTask across the library #89

Closed mikegoatly closed 10 months ago

mikegoatly commented 11 months ago

Mutation methods such as FullTextIndex.AddAsync are async only because it's possible that an index modification action may be present and may be async, e.g. serializing an index using async methods whenever an index is mutated.

This will save a few allocations per invocation to a mutation, though in the grand scheme of things may not be a big deal, so it needs to be measured.

mikegoatly commented 10 months ago

A quick experiment shows it makes next to no difference at all.

Before

Method Mean Error StdDev Rank Gen0 Gen1 Gen2 Allocated
IndexingAlwaysSupportIntraNodeText 1.887 s 2.4127 s 0.1322 s 2 55000.0000 14000.0000 2000.0000 317.06 MB
IndexingIntraNodeTextAt4Characters 1.505 s 0.5183 s 0.0284 s 1 55000.0000 14000.0000 2000.0000 319.68 MB
IndexingOneByOneAlwaysSupportIntraNodeText 1.942 s 1.4130 s 0.0775 s 3 114000.0000 78000.0000 3000.0000 666.5 MB
IndexingOneByOneIntraNodeTextAt4Characters 2.056 s 1.3604 s 0.0746 s 4 115000.0000 77000.0000 3000.0000 674.7 MB

After

Method Mean Error StdDev Rank Gen0 Gen1 Gen2 Allocated
IndexingAlwaysSupportIntraNodeText 1.879 s 1.0342 s 0.0567 s 2 55000.0000 14000.0000 2000.0000 317.06 MB
IndexingIntraNodeTextAt4Characters 1.484 s 0.3221 s 0.0177 s 1 55000.0000 14000.0000 2000.0000 319.68 MB
IndexingOneByOneAlwaysSupportIntraNodeText 1.948 s 0.3818 s 0.0209 s 4 114000.0000 78000.0000 3000.0000 666.5 MB
IndexingOneByOneIntraNodeTextAt4Characters 1.918 s 0.4472 s 0.0245 s 3 116000.0000 74000.0000 3000.0000 674.7 MB