[#43] Client: Memory optimization

Signed-off-by: Pavel Gross <p.gross@yadro.com>
This commit is contained in:
Pavel Gross 2025-03-26 16:51:42 +03:00
parent 5e86f53b0e
commit 87fe8db674
76 changed files with 399 additions and 3668 deletions

View file

@ -91,10 +91,13 @@ public class FrostFsContainerInfo
throw new ArgumentNullException("PlacementPolicy is null");
}
Span<byte> nonce = stackalloc byte[16];
Nonce.ToBytes(nonce);
this.container = new Container.Container()
{
PlacementPolicy = PlacementPolicy.Value.GetPolicy(),
Nonce = ByteString.CopyFrom(Nonce.ToBytes()),
Nonce = ByteString.CopyFrom(nonce),
OwnerId = Owner?.OwnerID,
Version = Version?.VersionID
};

View file

@ -11,7 +11,7 @@ public class CheckSum
public static CheckSum CreateCheckSum(byte[] content)
{
return new CheckSum { hash = content.Sha256() };
return new CheckSum { hash = DataHasher.Sha256(content.AsSpan()) };
}
public override string ToString()

View file

@ -353,7 +353,7 @@ internal struct Context
var start = hasPrefix ? likeWildcard.Length : 0;
var end = hasSuffix ? f.Value.Length - likeWildcard.Length : f.Value.Length;
var str = f.Value.Substring(start, end-start);
var str = f.Value.Substring(start, end - start);
if (hasPrefix && hasSuffix)
return nodeInfo.Attributes[f.Key].Contains(str);

View file

@ -4,10 +4,6 @@ namespace FrostFS.SDK;
public class FrostFsObject
{
// private byte[]? _payloadBytes;
// private ReadOnlyMemory<byte> _payloadMemory;
// private bool _isInitPayloadMemory;
/// <summary>
/// Creates new instance from <c>ObjectHeader</c>
/// </summary>
@ -49,25 +45,6 @@ public class FrostFsObject
public ReadOnlyMemory<byte> SingleObjectPayload { get; set; }
//public ReadOnlyMemory<byte> SingleObjectPayloadMemory
//{
// get
// {
// if (!_isInitPayloadMemory)
// {
// _payloadMemory = _payloadBytes.AsMemory();
// _isInitPayloadMemory = true;
// }
// return _payloadMemory;
// }
// set
// {
// _payloadMemory = value;
// _isInitPayloadMemory = true;
// }
//}
/// <summary>
/// Provide SHA256 hash of the payload. If null, the hash is calculated by internal logic
/// </summary>

View file

@ -1,4 +1,7 @@
using System.Collections.ObjectModel;
using System.Linq;
using FrostFS.Object;
using FrostFS.SDK.Client.Mappers.GRPC;
namespace FrostFS.SDK;
@ -9,6 +12,8 @@ public class FrostFsSplit(SplitId splitId,
FrostFsSignature? parentSignature = null,
ReadOnlyCollection<FrostFsObjectId>? children = null)
{
private Header.Types.Split? _split;
public FrostFsSplit() : this(new SplitId())
{
}
@ -24,4 +29,25 @@ public class FrostFsSplit(SplitId splitId,
public FrostFsObjectHeader? ParentHeader { get; set; } = parentHeader;
public ReadOnlyCollection<FrostFsObjectId>? Children { get; } = children;
public Header.Types.Split GetSplit()
{
if (_split == null)
{
_split = new Header.Types.Split
{
SplitId = SplitId?.GetSplitId(),
Parent = Parent?.ToMessage(),
ParentHeader = ParentHeader?.GetHeader(),
ParentSignature = ParentSignature?.ToMessage()
};
if (Children != null)
{
_split.Children.AddRange(Children.Select(x => x.ToMessage()));
}
}
return _split;
}
}

View file

@ -47,16 +47,11 @@ public class SplitId
return this.id.ToString();
}
public byte[]? ToBinary()
{
if (this.id == Guid.Empty)
return null;
return this.id.ToBytes();
}
public ByteString? GetSplitId()
{
return this.message ??= ByteString.CopyFrom(ToBinary());
Span<byte> span = stackalloc byte[16];
id.ToBytes(span);
return this.message ??= ByteString.CopyFrom(span);
}
}

View file

@ -4,9 +4,9 @@ public class FrostFsResponseStatus(FrostFsStatusCode code, string? message = nul
{
public FrostFsStatusCode Code { get; set; } = code;
public string Message { get; set; } = message ?? string.Empty;
public string Details { get; set; } = details ?? string.Empty;
public bool IsSuccess => Code == FrostFsStatusCode.Success;
public override string ToString()