Skip to content

Commit

Permalink
perf(memory-leaks): introduce Tasks.Texts.Observe
Browse files Browse the repository at this point in the history
  • Loading branch information
LSViana committed Oct 3, 2023
1 parent 5029f2d commit 4a6b62c
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Tests/YDotNet.Tests.Driver/Program.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// See https://aka.ms/new-console-template for more information

using YDotNet.Tests.Driver.Tasks.Branches;
using YDotNet.Tests.Driver.Tasks.Texts;

new StickyIndex().Run();
new Observe().Run();
48 changes: 48 additions & 0 deletions Tests/YDotNet.Tests.Driver/Tasks/Texts/Observe.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using YDotNet.Document;
using YDotNet.Tests.Driver.Abstractions;

namespace YDotNet.Tests.Driver.Tasks.Texts;

public class Observe : ITask
{
public Task Run()
{
var count = 0;

// Create many documents
while (count < 1_000_000)
{
// After 1s, stop and show the user the amount of documents
if (count > 0)
{
Console.WriteLine("Status Report");
Console.WriteLine($"\tTexts:\t{count}");
Console.WriteLine();
}

if (count % 1_000 == 0)
{
Thread.Sleep(millisecondsTimeout: 15);
}

// Create many documents
for (var i = 0; i < 100; i++)
{
var doc = new Doc();
var text = doc.Text($"sample-{i}");
var subscription = text.Observe(_ => { });

var transaction = doc.WriteTransaction();
text.Insert(transaction, index: 0, "YDotNet");
transaction.Commit();

text.Unobserve(subscription);
doc.Dispose();

count++;
}
}

return Task.CompletedTask;
}
}

0 comments on commit 4a6b62c

Please sign in to comment.