Skip to content

Commit

Permalink
Fix performance for large objects (#192)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ulimo authored Dec 14, 2023
1 parent 34dd06f commit d0b21f6
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/FlowtideDotNet.Core/Compute/FlxValueComparer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public static int CompareTo(FlxValue a, FlxValue b)
// Check for string comparison
if (a.ValueType == FlexBuffers.Type.String)
{
return string.Compare(a.AsString, b.AsString);
return FlxString.Compare(a.AsFlxString, b.AsFlxString);
}
if (a.ValueType == FlexBuffers.Type.Int)
{
Expand Down
33 changes: 32 additions & 1 deletion src/FlowtideDotNet.Core/Flexbuffer/FlxValue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,38 @@ public bool AsBool
throw new Exception($"Type {_type} is not convertible to bool");
}
}


public FlxString AsFlxString
{
get
{
var span = _buffer.Span;
if (_type == Type.String)
{
var indirectOffset = ComputeIndirectOffset(span, _offset, _parentWidth);
var size = (int)ReadULong(span, indirectOffset - _byteWidth, _byteWidth);
var sizeWidth = (int)_byteWidth;
while (span[indirectOffset + size] != 0)
{
sizeWidth <<= 1;
size = (int)ReadULong(span, indirectOffset - sizeWidth, (byte)sizeWidth);
}
return new FlxString(span.Slice(indirectOffset, size));
}
if (_type == Type.Key)
{
var indirectOffset = ComputeIndirectOffset(span, _offset, _parentWidth);
var size = 0;
while (indirectOffset + size < _buffer.Length && span[indirectOffset + size] != 0)
{
size++;
}
return new FlxString(span.Slice(indirectOffset, size));
}
throw new InvalidOperationException("Can only be used on strings");
}
}

public string AsString
{
get
Expand Down
2 changes: 1 addition & 1 deletion src/FlowtideDotNet.Storage/Tree/BPlusTreeOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace FlowtideDotNet.Storage.Tree
{
public class BPlusTreeOptions<K, V>
{
public int BucketSize { get; set; } = 256;
public int BucketSize { get; set; } = 64;

public required IComparer<K> Comparer { get; set; }

Expand Down

0 comments on commit d0b21f6

Please sign in to comment.