-
Notifications
You must be signed in to change notification settings - Fork 449
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
7591 abi encoding optimization #7617
Closed
ssonthal
wants to merge
6
commits into
NethermindEth:master
from
ssonthal:7591_abi_encoding_optimization
Closed
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
7b83f4b
initial changes
ssonthal 6b322b2
change 2
ssonthal 5f06eb8
changes
ssonthal ab54dcf
Merge branch 'master' into 7591_abi_encoding_optimization
ssonthal d5244e1
Merge branch 'master' into 7591_abi_encoding_optimization
ssonthal f598838
Merge branch 'master' into 7591_abi_encoding_optimization
ssonthal File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using DotNetty.Buffers; | ||
using DotNetty.Common.Utilities; | ||
using Nethermind.Serialization.Rlp; | ||
|
||
namespace Nethermind.Abi | ||
{ | ||
public sealed class NettyAbiStream : IDisposable | ||
{ | ||
|
||
private readonly IByteBuffer _buffer; | ||
|
||
private readonly int _initialPosition; | ||
|
||
public NettyAbiStream(IByteBuffer buffer) | ||
{ | ||
_buffer = buffer; | ||
_initialPosition = buffer.ReaderIndex; | ||
} | ||
|
||
public void Write(ReadOnlySpan<byte> bytesToWrite) | ||
{ | ||
_buffer.EnsureWritable(bytesToWrite.Length); | ||
|
||
Span<byte> target = | ||
_buffer.Array.AsSpan(_buffer.ArrayOffset + _buffer.WriterIndex, bytesToWrite.Length); | ||
bytesToWrite.CopyTo(target); | ||
int newWriterIndex = _buffer.WriterIndex + bytesToWrite.Length; | ||
|
||
_buffer.SetWriterIndex(newWriterIndex); | ||
} | ||
|
||
public void Write(IReadOnlyList<byte> bytesToWrite) | ||
{ | ||
_buffer.EnsureWritable(bytesToWrite.Count); | ||
Span<byte> target = | ||
_buffer.Array.AsSpan(_buffer.ArrayOffset + _buffer.WriterIndex, bytesToWrite.Count); | ||
for (int i = 0; i < bytesToWrite.Count; ++i) | ||
{ | ||
target[i] = bytesToWrite[i]; | ||
} | ||
|
||
int newWriterIndex = _buffer.WriterIndex + bytesToWrite.Count; | ||
_buffer.SetWriterIndex(newWriterIndex); | ||
} | ||
|
||
public void WriteByte(byte byteToWrite) | ||
{ | ||
_buffer.EnsureWritable(1); | ||
_buffer.WriteByte(byteToWrite); | ||
} | ||
|
||
public void WriteZero(int length) | ||
{ | ||
_buffer.EnsureWritable(length); | ||
_buffer.WriteZero(length); | ||
} | ||
|
||
public byte ReadByte() | ||
{ | ||
return _buffer.ReadByte(); | ||
} | ||
|
||
public Span<byte> Read(int length) | ||
{ | ||
Span<byte> span = _buffer.Array.AsSpan(_buffer.ArrayOffset + _buffer.ReaderIndex, length); | ||
_buffer.SkipBytes(span.Length); | ||
return span; | ||
} | ||
|
||
public Span<byte> Peek(int offset, int length) | ||
{ | ||
Span<byte> span = _buffer.Array.AsSpan(_buffer.ArrayOffset + _buffer.ReaderIndex + offset, length); | ||
return span; | ||
} | ||
|
||
public byte PeekByte() | ||
{ | ||
byte result = _buffer.ReadByte(); | ||
_buffer.SetReaderIndex(_buffer.ReaderIndex - 1); | ||
return result; | ||
} | ||
|
||
public byte PeekByte(int offset) | ||
{ | ||
_buffer.MarkReaderIndex(); | ||
_buffer.SkipBytes(offset); | ||
byte result = _buffer.ReadByte(); | ||
_buffer.ResetReaderIndex(); | ||
return result; | ||
} | ||
|
||
public void SkipBytes(int length) | ||
{ | ||
_buffer.SkipBytes(length); | ||
} | ||
|
||
public int Position | ||
{ | ||
get => _buffer.ReaderIndex - _initialPosition; | ||
set => _buffer.SetReaderIndex(_initialPosition + value); | ||
} | ||
|
||
public int Length => _buffer.ReadableBytes + (_buffer.ReaderIndex - _initialPosition); | ||
|
||
public bool HasBeenRead => _buffer.ReadableBytes <= 0; | ||
|
||
public string Description => "|NettyAibStream|description missing|"; | ||
|
||
/// <summary> | ||
/// Note: this include already read bytes, not just the remaining one. | ||
/// </summary> | ||
/// <returns></returns> | ||
public Span<byte> AsSpan() => _buffer.AsSpan(_initialPosition); | ||
|
||
public void Dispose() | ||
{ | ||
_buffer.SafeRelease(); | ||
} | ||
} | ||
} |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please ignore this file. Will undo these changes once I have some confirmations from your end. |
Submodule bench_precompiles
updated
92 files
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you allocate both list and array, not achieving goal of removing allocations