-
Notifications
You must be signed in to change notification settings - Fork 225
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
fix: Reduce memory usage in mem2reg #7053
Merged
Merged
+21
−1
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Compilation Report
|
Execution Report
|
Execution Memory Report
|
Compilation Memory Report
|
aakoshh
changed the title
fix: Use OrdSet for AliasSet
test: Try to reduce memory usage in mem2reg
Jan 14, 2025
aakoshh
changed the title
test: Try to reduce memory usage in mem2reg
fix: Try to reduce memory usage in mem2reg
Jan 14, 2025
5 tasks
aakoshh
changed the title
fix: Try to reduce memory usage in mem2reg
fix: Reduce memory usage in mem2reg
Jan 14, 2025
TomAFrench
approved these changes
Jan 14, 2025
5 tasks
…into 7001-fix-mem2reg-mem-req
5 tasks
aakoshh
force-pushed
the
7001-fix-mem2reg-mem-req
branch
from
January 14, 2025 16:17
d376513
to
8a25fab
Compare
Now merged #7058 the results are very similar 👍 |
Sorry, didn't see the usage of |
AztecBot
added a commit
to AztecProtocol/aztec-packages
that referenced
this pull request
Jan 14, 2025
…oir-lang/noir#7066) feat!: Handle generic fields in `StructDefinition::fields` and move old functionality to `StructDefinition::fields_as_written` (noir-lang/noir#7067) chore(ci): Check various inliner aggressiveness setttings in Brillig reports (noir-lang/noir#7049) chore: reenable reports on rollup root circuits (noir-lang/noir#7061) fix: don't always select trait impl when verifying trait constraints (noir-lang/noir#7041) chore: mark some critical libraries as good again (noir-lang/noir#7065) fix: Reduce memory usage in mem2reg (noir-lang/noir#7053) feat: Allow associated types to be ellided from trait constraints (noir-lang/noir#7026) chore(perf): try using vec-collections's VecSet in AliasSet (noir-lang/noir#7058) chore: reduce number of iterations of `acvm::compiler::compile` (noir-lang/noir#7050) chore: add `noir_check_shuffle` as a critical library (noir-lang/noir#7056) chore: clippy warning fix (noir-lang/noir#7051) chore(ci): Unify compilation/execution report jobs that take averages with single runs (noir-lang/noir#7048) fix(nargo_fmt): let doc comment could come after regular comment (noir-lang/noir#7046) fix(nargo_fmt): don't consider identifiers the same if they are equal… (noir-lang/noir#7043) feat: auto-import traits when suggesting trait methods (noir-lang/noir#7037) feat: avoid inserting `inc_rc` instructions into ACIR (noir-lang/noir#7036) fix(lsp): suggest all possible trait methods, but only visible ones (noir-lang/noir#7027) chore: add more protocol circuits to reports (noir-lang/noir#6977) feat: avoid generating a new witness when checking if linear expression is zero (noir-lang/noir#7031) feat: skip codegen of zero iteration loops (noir-lang/noir#7030)
AztecBot
added a commit
to AztecProtocol/aztec-packages
that referenced
this pull request
Jan 14, 2025
…ir#7066) feat!: Handle generic fields in `StructDefinition::fields` and move old functionality to `StructDefinition::fields_as_written` (noir-lang/noir#7067) chore(ci): Check various inliner aggressiveness setttings in Brillig reports (noir-lang/noir#7049) chore: reenable reports on rollup root circuits (noir-lang/noir#7061) fix: don't always select trait impl when verifying trait constraints (noir-lang/noir#7041) chore: mark some critical libraries as good again (noir-lang/noir#7065) fix: Reduce memory usage in mem2reg (noir-lang/noir#7053) feat: Allow associated types to be ellided from trait constraints (noir-lang/noir#7026) chore(perf): try using vec-collections's VecSet in AliasSet (noir-lang/noir#7058) chore: reduce number of iterations of `acvm::compiler::compile` (noir-lang/noir#7050) chore: add `noir_check_shuffle` as a critical library (noir-lang/noir#7056) chore: clippy warning fix (noir-lang/noir#7051) chore(ci): Unify compilation/execution report jobs that take averages with single runs (noir-lang/noir#7048) fix(nargo_fmt): let doc comment could come after regular comment (noir-lang/noir#7046) fix(nargo_fmt): don't consider identifiers the same if they are equal… (noir-lang/noir#7043) feat: auto-import traits when suggesting trait methods (noir-lang/noir#7037) feat: avoid inserting `inc_rc` instructions into ACIR (noir-lang/noir#7036) fix(lsp): suggest all possible trait methods, but only visible ones (noir-lang/noir#7027) chore: add more protocol circuits to reports (noir-lang/noir#6977) feat: avoid generating a new witness when checking if linear expression is zero (noir-lang/noir#7031) feat: skip codegen of zero iteration loops (noir-lang/noir#7030)
5 tasks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Problem*
Resolves #7001
Summary*
Changes
mem2reg::block::Block
to only use the mutable APIs ofOrdMap
if unifying the alias sets would cause something to change. That should save some memory, because doingself.aliases.entry(...).and_modify(...).or_insert_with(...)
causesOrdMap::get_mut
to be called, which callsArc::make_mut
to prepare the entry for modification, which involves making a clone and a newArc
if theArc
is shared, which it will be because we cloned aBlock
to get the folding started.This resulted in the memory required for mem2reg to go down to ~1GB, with later peaks corresponding to
convert_ssa_instruction
during ACIR generation:With #7057 merged the results are even better:
TODO in followup PR:
Additional Context
Profiling on Mac
I couldn't compile the heaptrack_gui. Instead tried cargo-instruments which requires Xcode to be installed, but it stopped working after a while, and I ended up using Instruments directly (a profiler tool on Mac, part of Xcode).
Executing the following command:
Compiled with:
The following is needed for Instruments to be able to start the executable:
where
debug.plist
has the following content:Memory profile
Original memory profile over time:
EXPERIMENT: Changed
AliasSet
to useOrdSet
instead ofBTreeSet
to utilise structural sharing.When I tried this on
aztec-packages
it was promising butperhaps I didn't run it long enoughI accidentally got the 2nd mem2reg commented out. Profiling again locally onnoir
revealed this version uses 21GB of memory 😖 :The increase seems to come from the allocation of a large number of
Arc
s:After having a second look at the size of the
AliasSet
s, they seem to actually only contain a single item, so I was barking up the wrong tree.Other tweaks I tried:
Expression
inaliases: OrdMap<Expression, AliasSet>
withu64
calculated byfxhash::hash64
, just to see the impact of not storing clones ofExpression
s; the result is the exact same memory usage, because as it turns out the memory allocated byOrdMap::get_mut
call is still forArc
s, it has always been.aliases: OrdMap<Expression, AliasSet>
withstd::HashMap
orstd::BTreeMap
; the memory usage in this case went from 5GB to 11GB; this is because of the increased cost of cloning these mapsim
withim_rc
to see ifArc
vsRc
makes any difference, although it's probably just faster than smaller. Can't because ofrayon
.Documentation*
Check one:
PR Checklist*
cargo fmt
on default settings.