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

halo2_proofs: Reduce memory usage of poly::Evaluator #642

Merged
merged 1 commit into from
Aug 24, 2022

Conversation

str4d
Copy link
Contributor

@str4d str4d commented Aug 23, 2022

poly::Evaluator stores all of the polynomials registered with it in memory for the duration of its existence. When evaluating an AST, it additionally caches the rotated polynomials in memory, and then chunks all of the rotated polynomials for parallel evaluation.

Previously, it stored a polynomial for every unique AST leaf, regardless of whether that leaf required a rotation or not. This resulted in the unrotated polynomials being stored twice in memory. However, the chunks simply refer to slices over cached polynomials, so we can reference the unrotated polynomials stored in poly::Evaluator instead of copies of them stored in the rotated polynomial HashMap. This strictly reduces memory usage during proving with no effect on correctness.

Part of #548.

`poly::Evaluator` stores all of the polynomials registered with it in
memory for the duration of its existence. When evaluating an AST, it
additionally caches the rotated polynomials in memory, and then chunks
all of the rotated polynomials for parallel evaluation.

Previously, it stored a polynomial for every unique AST leaf, regardless
of whether that leaf required a rotation or not. This resulted in the
unrotated polynomials being stored twice in memory. However, the chunks
simply refer to slices over cached polynomials, so we can reference the
unrotated polynomials stored in `poly::Evaluator` instead of copies of
them stored in the rotated polynomial `HashMap`. This strictly reduces
memory usage during proving with no effect on correctness.
@str4d
Copy link
Contributor Author

str4d commented Aug 23, 2022

Running heaptrack on the Orchard test circuit::tests::round_trip (which runs MockProver and then creates and verifies a single proof), I get the following memory usage measurements before and after this change:

❯ heaptrack --analyze heaptrack.circuit.before.zst | tail -n 7
total runtime: 5.17s.
bytes allocated in total (ignoring deallocations): 2.99GB (578.10MB/s)
calls to allocation functions: 1125475 (217693/s)
temporary memory allocations: 267839 (51806/s)
peak heap memory consumption: 132.75MB
peak RSS (including heaptrack overhead): 939.88MB
total memory leaked: 637.82KB

❯ heaptrack --analyze heaptrack.circuit.after.zst | tail -n 7
total runtime: 5.20s.
bytes allocated in total (ignoring deallocations): 2.95GB (567.03MB/s)
calls to allocation functions: 1125346 (216412/s)
temporary memory allocations: 266765 (51300/s)
peak heap memory consumption: 96.05MB
peak RSS (including heaptrack overhead): 680.80MB
total memory leaked: 684.67KB

So for the Orchard circuit, this is a 27.6% reduction in both peak heap memory consumption and peak RSS.

Copy link
Contributor

@daira daira left a comment

Choose a reason for hiding this comment

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

utACK

Copy link
Collaborator

@therealyingtong therealyingtong left a comment

Choose a reason for hiding this comment

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

utACK

@str4d str4d merged commit 8fa116a into main Aug 24, 2022
@str4d str4d deleted the reduce-ast-evaluator-memory-usage branch August 24, 2022 23:00
@str4d str4d added this to the 0.3.0 milestone Mar 2, 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.

3 participants