Skip to content

Commit

Permalink
RavenDB-20700 - expose the managed allocations for the term cache
Browse files Browse the repository at this point in the history
  • Loading branch information
grisha-kotler authored and ppekrol committed Jul 27, 2023
1 parent f5d6558 commit ca720d1
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/Lucene.Net/Index/ArrayHolder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,16 @@ public class ArrayHolder : IDisposable
private readonly Term[] _termArray;
private readonly TermInfo[] _termInfoArray;
private int _usages;
private long _managedAllocations;

public Span<long> LongArray => _longArray.AsSpan(0, _size);
public Span<TermInfo> InfoArray => _termInfoArray.AsSpan(0, _size);
public Span<Term> IndexTerms => _termArray.AsSpan(0, _size);

public static Action<long> OnArrayHolderCreated;

public static Action<long> OnArrayHolderDisposed;

public ArrayHolder(int size, Directory directory, string name)
{
_size = size;
Expand Down Expand Up @@ -49,6 +54,8 @@ public static ArrayHolder GenerateArrayHolder(Directory directory, string name,
int indexSize = 1 + ((int)indexEnum.size - 1) / indexDivisor; // otherwise read index

var holder = new ArrayHolder(indexSize, directory, name);

var before = GC.GetAllocatedBytesForCurrentThread();

for (int i = 0; indexEnum.Next(state); i++)
{
Expand All @@ -61,11 +68,16 @@ public static ArrayHolder GenerateArrayHolder(Directory directory, string name,
break;
}

holder._managedAllocations = GC.GetAllocatedBytesForCurrentThread() - before;

OnArrayHolderCreated?.Invoke(holder._managedAllocations);

return holder;

}
finally
{

indexEnum?.Close();
}
}
Expand All @@ -74,6 +86,8 @@ public void Dispose()
{
GC.SuppressFinalize(this);

OnArrayHolderDisposed?.Invoke(_managedAllocations);

if (_size > 256 * 1024)
return;

Expand Down

0 comments on commit ca720d1

Please sign in to comment.