feat: optimizing SharedMutable storage slots#11817
Conversation
This stack of pull requests is managed by Graphite. Learn more about stacking. |
1278371 to
ce4f5ab
Compare
| } | ||
|
|
||
| impl<T, let INITIAL_DELAY: u32, let N: u32> SharedMutable<T, INITIAL_DELAY, UnconstrainedContext> | ||
| impl<T, let INITIAL_DELAY: u32, let M: u32> SharedMutable<T, INITIAL_DELAY, UnconstrainedContext> |
There was a problem hiding this comment.
T now represents the whole WithHash thing and not just svc so I change N to M to keep it consistent with the rest of this file.
There was a problem hiding this comment.
I don't think so, in the declaration above you wrote
SharedMutable<T, INITIAL_DELAY, Context>
where
WithHash<SharedMutableValues<T, INITIAL_DELAY>, _>: Packable<M
so T is not packed into M, WithHash<SharedMutableValues<T is packed into M.
You also do SharedMutableValues<T> below. T is whatever we're storing.
There was a problem hiding this comment.
You are right. Good catch. Reverted the change in c6329b7
|
|
||
| global TEST_INITIAL_DELAY: u32 = 13; | ||
|
|
||
| unconstrained fn assert_equal_after_conversion(original: ScheduledDelayChange<TEST_INITIAL_DELAY>) { |
There was a problem hiding this comment.
sdc now doesn't implement Packable so I had to delete these tests. They were moved with modifications to tests of SharedMutableValues.
|
|
||
| pub fn get_value_change_storage_slot(shared_mutable_storage_slot: Field) -> Field { | ||
| shared_mutable_storage_slot + (SCHEDULED_DELAY_CHANGE_PCKD_LEN as Field) | ||
| pub(crate) fn unpack_delay_change(packed: Field) -> ScheduledDelayChange<INITIAL_DELAY> { |
There was a problem hiding this comment.
Using modulo operation in this func was not much of an option since the packed value does not fit in U128 and Field does not support it. For this reason I went with the "tmp value approach".
SharedMutable storage slots
7358134 to
2c0ff83
Compare
Changes to public function bytecode sizes
🧾 Summary (100% most significant diffs)
Full diff report 👇
|
| } | ||
|
|
||
| impl<T, let INITIAL_DELAY: u32, let N: u32> SharedMutable<T, INITIAL_DELAY, UnconstrainedContext> | ||
| impl<T, let INITIAL_DELAY: u32, let M: u32> SharedMutable<T, INITIAL_DELAY, UnconstrainedContext> |
There was a problem hiding this comment.
I don't think so, in the declaration above you wrote
SharedMutable<T, INITIAL_DELAY, Context>
where
WithHash<SharedMutableValues<T, INITIAL_DELAY>, _>: Packable<M
so T is not packed into M, WithHash<SharedMutableValues<T is packed into M.
You also do SharedMutableValues<T> below. T is whatever we're storing.
c6329b7 to
b1729c5
Compare
e383986 to
9b57e85
Compare
9b57e85 to
f2bf543
Compare
2b03a57 to
7dcbc29
Compare
| pub(crate) post: Option<u32>, | ||
| // Block at which `post` value is used instead of `pre` | ||
| block_of_change: u32, | ||
| pub(crate) block_of_change: u32, |
There was a problem hiding this comment.
Had to do this change because now we need direct access to it when packing in shared_mutable_values.nr. Not great.
nventuro
left a comment
There was a problem hiding this comment.
Thanks a lot!
It's unfortunate that this got much uglier and we need to change TS files etc given that we use it in TS for upgrades. But at least that's not our problem now.
e91050f to
5155ac6
Compare
| import type { UInt32 } from '../shared.js'; | ||
|
|
||
| export class ScheduledDelayChange { | ||
| constructor(public previous: UInt32 | undefined, public blockOfChange: UInt32, public post: UInt32 | undefined) {} |
There was a problem hiding this comment.
Order of args was different here from the Noir implementation because @sirasistant hates me 😝
There was a problem hiding this comment.
Ugh, I was also caught by this at some point, I thought I changed it to the noir one, clearly I didn't ):
Co-authored-by: Nicolás Venturo <nicolas.venturo@gmail.com>
…utable/scheduled_delay_change/test.nr Co-authored-by: Nicolás Venturo <nicolas.venturo@gmail.com>
…utable/shared_mutable_values.nr Co-authored-by: Nicolás Venturo <nicolas.venturo@gmail.com>
0b08c43 to
3668ecf
Compare

It was possible to shrink the number of storage slots occupied by
SharedMutableby 1 field by packingScheduledDelayChangeandScheduledValueChange.block_of_changetogether in a single storage slot. This makes the code uglier but overall I think this change is worth it.