Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RavenDB-20700 - expose the managed allocations for the term cache #61

Merged
merged 1 commit into from
Jul 27, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading