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

Possible memory optimization #3

Closed
ledvinap opened this issue Jun 10, 2019 · 2 comments

Comments

@ledvinap
Copy link

commented Jun 10, 2019

Hello,
when computing w[] array in https://github.com/amosnier/sha-2/blob/master/sha-256.c#L168, only last 16 entries are necessary and only w[round] is used in compression loop.
Splitting compression function into 4*16 nested loop will allow computing next w[16] entries on the fly, considerably reducing stack usage (192 bytes saved), with small performance impact ...

@amosnier amosnier self-assigned this Aug 3, 2019

amosnier added a commit that referenced this issue Aug 3, 2019

Issue #3: implementation as proposed (hopefully)
The full test suite runs fine and the performance number are:

Before:
real	1m7,040s
user	1m6,319s
sys	0m0,716s

After:
real	1m6,707s
user	1m6,035s
sys	0m0,672s

Not bad. But mostly, it saves stack. Nice. :-)

amosnier added a commit that referenced this issue Aug 3, 2019

Issue #3: implementation as proposed (hopefully)
The full test suite runs fine and the performance numbers are:

Before:
real	1m7,040s
user	1m6,319s
sys	0m0,716s

After:
real	1m6,707s
user	1m6,035s
sys	0m0,672s

Not bad. But mostly, it saves stack. Nice. :-)
@amosnier

This comment has been minimized.

Copy link
Owner

commented Aug 3, 2019

This cleverness made my evening. Thanks a lot!

@ledvinap, I'll happily take further comments.

I will try to react a little faster in the future.

@amosnier

This comment has been minimized.

Copy link
Owner

commented Aug 4, 2019

I close the issue for now. We'll reopen it if necessary.

@amosnier amosnier closed this Aug 4, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.