Skip to content

Commit 9299517

Browse files
Add comment on the performance of LINQ for reading BSATN (#309)
1 parent a75a552 commit 9299517

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/SpacetimeDBClient.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,12 +356,23 @@ private static QueryUpdate DecompressDecodeQueryUpdate(CompressableQueryUpdate u
356356

357357
/// <summary>
358358
/// Prepare to read a BsatnRowList.
359-
///
359+
///
360360
/// This could return an IEnumerable, but we return the reader and row count directly to avoid an allocation.
361361
/// It is legitimate to repeatedly call <c>IStructuralReadWrite.Read<T></c> <c>rowCount</c> times on the resulting
362362
/// BinaryReader:
363363
/// Our decoding infrastructure guarantees that reading a value consumes the correct number of bytes
364364
/// from the BinaryReader. (This is easy because BSATN doesn't have padding.)
365+
///
366+
/// Previously here we were using LINQ to do what we're now doing with a custsom reader.
367+
///
368+
/// Why are we no longer using LINQ?
369+
///
370+
/// The calls in question, namely `Skip().Take()`, were fast under the Mono runtime,
371+
/// but *much* slower when compiled AOT with IL2CPP.
372+
/// Apparently Mono's JIT is smart enough to optimize away these LINQ ops,
373+
/// resulting in a linear scan of the `BsatnRowList`.
374+
/// Unfortunately IL2CPP could not, resulting in a quadratic scan.
375+
/// See: https://github.com/clockworklabs/com.clockworklabs.spacetimedbsdk/pull/306
365376
/// </summary>
366377
/// <param name="list"></param>
367378
/// <returns>A reader for the rows of the list and a count of rows.</returns>

0 commit comments

Comments
 (0)