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

Timo/fix quadr complexity #11

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

timohanke
Copy link

Copying the whole data with every chunk caused quadratic complexity.

Nat32.fromIntWrap(Nat8.toNat(p[j + 1])) << 16 |
Nat32.fromIntWrap(Nat8.toNat(p[j + 2])) << 08 |
Nat32.fromIntWrap(Nat8.toNat(p[j + 3])) << 00;
Nat32.fromIntWrap(Nat8.toNat(data[start + j + 0])) << 24 |
Copy link

Choose a reason for hiding this comment

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

Can't these just be Nat32.fromNat or do you want to avoid the redundant overflow check?

Copy link
Author

Choose a reason for hiding this comment

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

You mean Nat32.fromNat(Nat8.toNat(..))?

Copy link

Choose a reason for hiding this comment

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

Yup. But perhaps the existing is faster since it doesn't check for overflow

Copy link
Author

Choose a reason for hiding this comment

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

I tested it. fromIntWrap is slightly cheaper than fromNat.

while (p.size() >= 64) {
var start = 0;
var len = data.size();
while (len >= 64) {
var j = 0;
for (i in Iter.range(0, 15)) {
Copy link

Choose a reason for hiding this comment

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

The for loop might be quicker as a while loop starting j from start, incrementing by 4 up to a pre-computed bound.

Copy link
Author

Choose a reason for hiding this comment

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

But i has to increment, too.
Why exactly would it be quicker?

skilesare added a commit to skilesare/crypto.mo that referenced this pull request Jan 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants