-
Notifications
You must be signed in to change notification settings - Fork 667
(feature): Created a Heapsize trait and a macro to derive it #8795
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
base: main
Are you sure you want to change the base?
(feature): Created a Heapsize trait and a macro to derive it #8795
Conversation
e20efee to
fc3340e
Compare
orizi
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@orizi reviewed 15 of 21 files at r1, all commit messages.
Reviewable status: 15 of 21 files reviewed, 3 unresolved discussions (waiting on @eytan-starkware and @TomerStarkware)
crates/cairo-lang-utils/Cargo.toml line 36 at r1 (raw file):
[features] default = ["std", "tracing"] env_logger = ["tracing"]
?
Code quote:
env_logger = ["tracing"]crates/cairo-lang-debug/src/heap_size.rs line 1 at r1 (raw file):
pub trait HeapSize {
doc trait as well.
crates/cairo-lang-debug/src/heap_size.rs line 14 at r1 (raw file):
} pub fn heap_size<T: HeapSize>(t: &T) -> usize {
why? and doc.
c9d4de7 to
9187d52
Compare
orizi
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@orizi reviewed 3 of 45 files at r2, all commit messages.
Reviewable status: 4 of 46 files reviewed, 4 unresolved discussions (waiting on @eytan-starkware and @TomerStarkware)
.github/workflows/ci.yml line 204 at r2 (raw file):
- uses: actions/checkout@v6 with: fetch-depth: "0"
revert.
orizi
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@orizi reviewed 37 of 45 files at r2.
Reviewable status: 41 of 46 files reviewed, 7 unresolved discussions (waiting on @eytan-starkware and @TomerStarkware)
crates/cairo-lang-utils/src/heap_size.rs line 397 at r2 (raw file):
} pub fn heap_size<T: HeapSize>(t: &T) -> usize {
check if deletable.
crates/cairo-lang-proc-macros/tests/heap_size.rs line 44 at r2 (raw file):
let test_enum3 = TestEnum::Variant3; let size3 = test_enum3.heap_size(); assert_eq!(size3, 0);
Suggestion:
let test_struct =
TestStruct { a: vec![1, 2, 3], b: "hello".to_string(), c: Arc::new("world".to_string()) };
assert_eq!(test_struct.a.heap_size(), 12);
assert_eq!(test_struct.b.heap_size(), 5);
assert_eq!(test_struct.c.heap_size(), 0);
assert_eq!(test_struct.heap_size(), test_struct.a.heap_size() + test_struct.b.heap_size() + test_struct.c.heap_size());
...
let test_enum1 = TestEnum::Variant1 { a: vec![1, 2, 3], b: String::from("test") };
let size1 = test_enum1.heap_size();
assert!(size1 > 0);
let test_enum2 = TestEnum::Variant2("hello".to_string(), Arc::new(vec![1, 2, 3]));
let size2 = test_enum2.heap_size();
assert!(size2 > 0);
let test_enum3 = TestEnum::Variant3;
let size3 = test_enum3.heap_size();
assert_eq!(size3, 0);crates/cairo-lang-lowering/Cargo.toml line 33 at r2 (raw file):
[dev-dependencies]
revert
9187d52 to
55163f0
Compare
eytan-starkware
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: 41 of 46 files reviewed, 7 unresolved discussions (waiting on @orizi and @TomerStarkware)
.github/workflows/ci.yml line 204 at r2 (raw file):
Previously, orizi wrote…
revert.
Done.
crates/cairo-lang-lowering/Cargo.toml line 33 at r2 (raw file):
Previously, orizi wrote…
revert
Done.
crates/cairo-lang-utils/Cargo.toml line 36 at r1 (raw file):
Previously, orizi wrote…
?
Unrelated (it is from the move to tracing to be backward compatible)
crates/cairo-lang-utils/src/heap_size.rs line 397 at r2 (raw file):
Previously, orizi wrote…
check if deletable.
Done.
crates/cairo-lang-debug/src/heap_size.rs line 1 at r1 (raw file):
Previously, orizi wrote…
doc trait as well.
Done.
crates/cairo-lang-debug/src/heap_size.rs line 14 at r1 (raw file):
Previously, orizi wrote…
why? and doc.
Done.
crates/cairo-lang-proc-macros/tests/heap_size.rs line 44 at r2 (raw file):
let test_enum3 = TestEnum::Variant3; let size3 = test_enum3.heap_size(); assert_eq!(size3, 0);
Done.
55163f0 to
4b8ee1d
Compare
TomerStarkware
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@TomerStarkware reviewed 1 of 45 files at r2, 12 of 12 files at r3, all commit messages.
Reviewable status: all files reviewed, 8 unresolved discussions (waiting on @eytan-starkware and @orizi)
crates/cairo-lang-utils/src/heap_size.rs line 168 at r3 (raw file):
impl HeapSize for smol_str::SmolStr { fn heap_size(&self) -> usize { 0
SmolStr can be allocated on the heap,
eytan-starkware
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: all files reviewed, 8 unresolved discussions (waiting on @orizi and @TomerStarkware)
crates/cairo-lang-utils/src/heap_size.rs line 168 at r3 (raw file):
Previously, TomerStarkware wrote…
SmolStr can be allocated on the heap,
SmolStr uses an Arc, and can allow memory deduplication, which will cause us to double count so currently it is not counted.
TomerStarkware
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: all files reviewed, 7 unresolved discussions (waiting on @orizi)

TL;DR
First step in adding support for measuring heap memory usage of compiler data structures.
What changed?
HeapSizetrait incairo-lang-utilsHeapSizeincairo-lang-proc-macros