-
Notifications
You must be signed in to change notification settings - Fork 58
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
Eliminate hashing shims for hardcoded tags across the LEM codebase #810
Conversation
c9cf7d5
to
8bd8545
Compare
* Expand LEM's expressiveness to produce that kind of data in the model * Adjust the Store accordingly, providing the appropriate API to create such pointers directly
8bd8545
to
bedb380
Compare
Tag::Cont(Outermost | Error | Dummy | Terminal) => { | ||
// temporary shim for compatibility with Lurk Alpha | ||
ZPtr::from_parts(*tag, store.poseidon_cache.hash8(&[F::ZERO; 8])) | ||
} |
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.
This is gone
// the following is a temporary shim for compatibility with Lurk Alpha | ||
// otherwise we could just have a pointer whose value is zero |
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.
This is gone
Tag::Cont(Outermost | Error | Dummy | Terminal) => { | ||
// temporary shim for compatibility with Lurk Alpha | ||
g.new_const(cs, store.poseidon_cache.hash8(&[F::ZERO; 8])); | ||
} |
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.
This is gone
// temporary shim for compatibility with Lurk Alpha | ||
ctx.global_allocator.get_allocated_const_cloned( | ||
ctx.store.poseidon_cache.hash8(&[F::ZERO; 8]), | ||
)? |
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.
This is gone
Tag::Cont(Outermost | Error | Dummy | Terminal) => { | ||
// temporary shim for compatibility with Lurk Alpha | ||
globals.insert(FWrap(store.poseidon_cache.hash8(&[F::ZERO; 8]))); | ||
} |
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.
This is gone
Tag::Cont(Outermost | ContTag::Error | Dummy | Terminal) => { | ||
// temporary shim for compatibility with Lurk Alpha | ||
Ok(ZPtr::from_parts( | ||
*tag, | ||
self.poseidon_cache.hash8(&[F::ZERO; 8]), | ||
)) | ||
} |
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.
This is gone
let hash3zeros = poseidon_cache.hash3(&[F::ZERO; 3]); | ||
let hash4zeros = poseidon_cache.hash4(&[F::ZERO; 4]); | ||
let hash6zeros = poseidon_cache.hash6(&[F::ZERO; 6]); | ||
let hash8zeros = poseidon_cache.hash8(&[F::ZERO; 8]); |
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.
This is the extra cost of store startup
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.
Could we parallelize this?
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.
I think it can be parallelized, but I am not sure it's worth it since the PoseidonCache
would be a locking bottleneck across threads
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 cache has four different locations per arity, writing to these locations only requires a shared reference thanks to the FrozenMap
, and the locking is internal to each of these. What's the problem?
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.
You're right. But I tried it and the difference in performance wasn't clear enough to justify the increase in complexity:
store_benchmark/store_go_base_bls12/_10_16
time: [152.22 µs 152.32 µs 152.40 µs]
change: [-2.7313% -2.6485% -2.5683%] (p = 0.00 < 0.05)
Performance has improved.
store_benchmark/store_go_base_pallas/_10_16
time: [154.93 µs 155.08 µs 155.24 µs]
change: [-1.0801% -0.7544% -0.2272%] (p = 0.00 < 0.05)
Change within noise threshold.
store_benchmark/store_go_base_bls12/_10_160
time: [158.65 µs 158.75 µs 158.86 µs]
change: [+1.2575% +1.3732% +1.4909%] (p = 0.00 < 0.05)
Performance has regressed.
store_benchmark/store_go_base_pallas/_10_160
time: [157.69 µs 158.22 µs 158.95 µs]
change: [+0.5752% +0.7856% +1.0481%] (p = 0.00 < 0.05)
Change within noise threshold.
This is how I did it:
let hashes = (0..4).into_par_iter().map(|i| {
match i {
0 => poseidon_cache.hash3(&[F::ZERO; 3]),
1 => poseidon_cache.hash4(&[F::ZERO; 4]),
2 => poseidon_cache.hash6(&[F::ZERO; 6]),
3 => poseidon_cache.hash8(&[F::ZERO; 8]),
_ => unreachable!(),
}
}).collect::<Vec<_>>();
hash3zeros: hashes[0],
hash4zeros: hashes[1],
hash6zeros: hashes[2],
hash8zeros: hashes[3],
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.
Thanks for the thorough evaluation!
Changes:
Performance:
Note: I tried an approach with
OnceCell
s. It made the store interning and hydration benchmarks have no change wrtmaster
, but it backfired with a 2% slowdown in evaluation, which is worse than paying a small cost on the store startup.Closes #796