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

Remove Linq from ECDSA and UInt classes #1208

Closed
wants to merge 19 commits into from

Conversation

shargon
Copy link
Member

@shargon shargon commented Nov 7, 2019

Related to: #939
Wait for: #1178

With the following example, and avoiding Linq, we can obtain more than 216% of performance with 1000 ECPoint.

Result

Old: 00:00:00.0016608
New: 00:00:00.0007658
Environment: Release/x64
[TestMethod]
        public void Bench()
        {
            var iterations = 1000;
            var hashesNew = new List<ECPoint>();
            var hashesOld = new List<ECPointOld>();
            Parallel.For(0, iterations, (i) =>
            {
                var k = generateCertainKey(32).PublicKey;
                hashesNew.Add(k);
                hashesOld.Add(new ECPointOld(k.X, k.Y, k.Curve));
            });

            var trees1 = new List<byte[]>();
            var trees2 = new List<byte[]>();
            Stopwatch sw1 = Stopwatch.StartNew();

            for (int x = 0; x < iterations; x++)
            {
                trees1.Add(hashesOld[x].EncodePoint(false));
            }

            sw1.Stop();
            Stopwatch sw2 = Stopwatch.StartNew();

            for (int x = 0; x < iterations; x++)
            {
                trees2.Add(hashesNew[x].EncodePoint(false));
            }

            sw2.Stop();

            Console.WriteLine("Old: " + sw1.Elapsed.ToString());
            Console.WriteLine("New: " + sw2.Elapsed.ToString());

            Assert.AreEqual(trees1.Count, trees2.Count);
            for (int x = 0; x < trees1.Count; x++)
            {
                CollectionAssert.AreEqual(trees1[x], trees2[x]);
            }
        }
  • Also was added the check of the curve in equals methods, because currently different curve points could be equal

@shargon shargon added Enhancement Type - Changes that may affect performance, usability or add new features to existing modules. port-to-2.x labels Nov 7, 2019
@shargon shargon requested a review from erikzhang November 7, 2019 09:42
@shargon shargon changed the title Optimize ECPoint Optimize Reverse method Nov 7, 2019
@shargon shargon changed the title Optimize Reverse method Optimize Reverse and ECPoint Nov 7, 2019
@erikzhang
Copy link
Member

There is a better way to optimize BigInteger.ToByteArray() in .NET Standard 2.1. Let's close this and wait for #1178

@shargon
Copy link
Member Author

shargon commented Nov 7, 2019

There are more optimizations like Reverse I prefer to wait without close it

@shargon shargon mentioned this pull request Nov 11, 2019
@shargon shargon changed the title Optimize Reverse and ECPoint Remove Linq from ECDSA and UInt classes Nov 11, 2019
@shargon
Copy link
Member Author

shargon commented Nov 19, 2019

There is a better way to optimize BigInteger.ToByteArray() in .NET Standard 2.1. Let's close this and wait for #1178

@erikzhang Te goal of this PR is more about for remove Linq from certains critical areas, Is totally compatible with other improves. So I don't understand very well why It should wait for #1178.
Could you explain me what way are you thinking about in order to adapt this PR for the next changes?

Copy link
Contributor

@lock9 lock9 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Shargon.
Hi @erikzhang #1178 is merged.
Shargon just replaced methods that we were using Linq with some helper methods.

@erikzhang
Copy link
Member

Please wait for me. I will make a PR to make some improvement.

shargon added a commit to shargon/neo that referenced this pull request Nov 26, 2019
@shargon
Copy link
Member Author

shargon commented Nov 26, 2019

Closed in favor of #1283

@shargon shargon closed this Nov 26, 2019
@shargon shargon deleted the avoid-linq-ecpoint branch November 26, 2019 11:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement Type - Changes that may affect performance, usability or add new features to existing modules.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants