-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Removed UIntBase to avoid expensive virtual calls for base data type classes #206
Conversation
neo/Wallets/AssetDescriptor.cs
Outdated
@@ -7,13 +7,15 @@ namespace Neo.Wallets | |||
{ | |||
public class AssetDescriptor | |||
{ | |||
public UIntBase AssetId; | |||
public object AssetId; |
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.
Can we keep UIntBase
but change everything to non-virtual? Or just change it to an interface?
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.
We can keep UIntBase or introduce IUInt interface but only shared contract between UInt160 and UInt256 is ToArray method. The rest methods are either type specific or covered by other interfaces (IEquatable, IComparable, ISerializable). I see the consumer of UIntBase/IUInt always has to cast it the underlying type to work with.
For AssetDescriptor class (and for TransferOutput class) we can come up with more descriptive design. The idea here is to move casting logic outside of the class.
Option #1:
public class AssetDescriptor<TUInt>
{
public TUInt AssetId;
public string AssetName;
public byte Decimals;
public AssetDescriptor(TUInt asset_id)
{
AssetId = asset_id
}
Option #2:
public class AssetDescriptor256 : IAssetDescriptor
{
public UInt256 AssetId;
public string AssetName;
public byte Decimals;
public AssetDescriptor(UInt256 asset_id)
{
AssetId = asset_id
}
public byte[] IAssetDescriptor.GetAssestIdAsByteArray()
{
return AssetId.ToArray();
}
I'd like to elaborate more on the subject but I couldn't have found any example AssetDescriptor class usage.
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.
…rnov/neo into base-types-uint-refactoring
I reviewed neo-gui and neo-cli projects and reverted UIntBase back to API they use. It was discovered to be inheritance from UIntBase and UIntBase.Parse method. Let me know if I missed any. |
Calls through virtual tables are quite expensive for such heavily used classes as base data types. Done: