-
Notifications
You must be signed in to change notification settings - Fork 105
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
perf: lower the default allocation for bignums #4102
Conversation
rts/motoko-rts/src/types.rs
Outdated
@@ -921,6 +921,10 @@ pub(crate) unsafe fn block_size(address: usize) -> Words<u32> { | |||
|
|||
TAG_BIGINT => { | |||
let bigint = address as *mut BigInt; | |||
if (*bigint).mp_int.used != (*bigint).mp_int.alloc { | |||
println!(100, "used:{}, alloc: {}", (*bigint).mp_int.used, (*bigint).mp_int.alloc); |
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.
Building up the arr
(wins back 1-2 words)
debug.print: used:3, alloc: 5
debug.print: used:5, alloc: 7
debug.print: used:9, alloc: 11
debug.print: used:18, alloc: 19
debug.print: used:36, alloc: 37
debug.print: used:72, alloc: 73
debug.print: used:143, alloc: 145
debug.print: used:286, alloc: 287
debug.print: used:572, alloc: 573
Deserialising from Candid blob (wins back 1 word consistently)
debug.print: used:3, alloc: 4
debug.print: used:5, alloc: 6
debug.print: used:9, alloc: 10
debug.print: used:18, alloc: 19
debug.print: used:36, alloc: 37
debug.print: used:72, alloc: 73
debug.print: used:143, alloc: 144
debug.print: used:286, alloc: 287
debug.print: used:572, alloc: 573
rts/motoko-rts/src/types.rs
Outdated
if (*bigint).mp_int.used != (*bigint).mp_int.alloc { | ||
println!(100, "used:{}, alloc: {}", (*bigint).mp_int.used, (*bigint).mp_int.alloc); | ||
} | ||
(*bigint).mp_int.alloc = (*bigint).mp_int.used; |
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.
stats are in https://github.com/dfinity/motoko/pull/4102/files/e15afc367f58f61db4756f6f41e513890d7c8163#r1253257503 and also past commits...
7185dc5
to
d4a6d4a
Compare
this addresses #4100, but more improvements are to come
d4a6d4a
to
50420e0
Compare
But probably better to redesign the logic and make BigInt shortening independent of `word_size()`
rts/motoko-rts/src/bigint.rs
Outdated
@@ -51,6 +51,7 @@ unsafe fn mp_alloc<M: Memory>(mem: &mut M, size: Bytes<u32>) -> *mut u8 { | |||
let size = size.as_usize(); | |||
debug_assert_eq!((size % core::mem::size_of::<mp_digit>()), 0); | |||
(*blob).mp_int.alloc = (size / core::mem::size_of::<mp_digit>()) as i32; | |||
(*blob).mp_int.used = (*blob).mp_int.alloc; // Otherwise, `block_size() in `allocation_barrier()` may already shorten the object. |
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.
The problem with this might be that this changes the value of the bignum (mantissa).
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.
Thank you very much. This already improves the BigNum size overhead problem substantially.
this addresses the most pressing aspect of #4100, but more improvements are to come
Possible flanking measures:
HP
still points at the end of the recently allocated bignum after all arithmetic is done, and the bignum's capacity is bigger than its payload, we can cut back theHP
(this probably only makes sense from specific callsites)