public static void Main() { var list = LargeImmutableList <Value> .Empty(); var n = 0u; var sw = Stopwatch.StartNew(); for (var i = 0; i < 100_000_000; i++) { if (i % 10_000_000 == 0) { if (i != 0) { Console.WriteLine("In {0} ({1:F0} / ms)", sw.Elapsed, 10_000_000 / sw.ElapsedMilliseconds); } sw.Restart(); var file = "./temp" + (i / 1_000_000) + ".bin"; long length; using (var stream = new FileStream(file, FileMode.Create)) { list.Save(stream); length = stream.Length; } Console.WriteLine("Wrote {0} bytes in {1}", length, sw.Elapsed); sw.Restart(); var mmap = MemoryMappedFile.CreateFromFile(file, FileMode.Open); using (var mem = new MemoryMapper(mmap, 0, length)) list = LargeImmutableList <Value> .Load(new BigMemoryStream(mem)); Console.WriteLine("Read {0} bytes in {1}", length, sw.Elapsed); sw.Restart(); } n = (n * 631) + 237; var pos = (int)(n % 200_000_000); if (pos >= list.Count) { pos = list.Count; list = list.Add(new Value { AsInteger = 0, AsString = "" }); } var old = list[pos]; list = list.SetItem(pos, new Value { AsInteger = old.AsInteger + 1, AsString = old.AsString + i }); } Console.WriteLine("In {0}", sw.Elapsed); sw.Restart(); }
public State( ImmutableDictionary <string, int> index, LargeImmutableList <ImmutableList <int> > documentLists, LargeImmutableList <Document> documents) { Index = index ?? throw new ArgumentNullException(nameof(index)); DocumentLists = documentLists ?? throw new ArgumentNullException(nameof(documentLists)); Documents = documents ?? throw new ArgumentNullException(nameof(documents)); }
private LargeImmutableList <Person> SaveAndReload(LargeImmutableList <Person> p) { var ms = new MemoryStream(); p.Save(ms); var mem = new VolatileMemory(ms.ToArray()); return(LargeImmutableList <Person> .Load(new BigMemoryStream(mem), Options)); }
/// <summary> Load the state from a stream. </summary> public async Task <State> TryLoadAsync(Stream source, CancellationToken cancel) { // Discover if the source can be memory-mapped, or copy it to an in-memory buffer. var stream = await source.AsBigMemoryStream(cancel); var index = await MessagePackSerializer.DeserializeAsync <ImmutableDictionary <string, int> >( stream, State.MessagePackOptions); // LargeImmutableList uses memory-mapping to avoid reloading the entire tables // from the disk. var documentLists = LargeImmutableList <ImmutableList <int> > .Load(stream, State.MessagePackOptions); var documents = LargeImmutableList <State.Document> .Load(stream, State.MessagePackOptions); return(new State(index, documentLists, documents)); }
private static LargeImmutableList <Person> Empty() => LargeImmutableList <Person> .Empty(Options);