The Sapling parameters defined in ironfish::sapling_bls12::SAPLING are behind a lazy_static. As such, the parameters are not loaded until accessed fo the first time. The purpose of initializeSapling is to acccess the parameters to ensure that they get loaded early.
The current implementation of initializeSapling was calling .clone() on ironfish::sapling_bls12::SAPLING, causing large amounts of memory to be allocated and written, only to be discarded shortly afterwards. The implementation has been changed to just dereference SAPLING, without doing anything else. This is enough to trigger lazy_static to load the parameters.
Also:
Removed the Arc from ironfish::sapling_bls12::SAPLING: Arc is used to extend lifetimes in multithreaded environments, but the lifetime of SAPLING is static, so there's no point in extending it.
Removed ironfish::sapling_bls12::load because it's not public and redundant
Testing Plan
Add debug instrumentation to initializeSapling and Sapling::load. Verify that:
Sapling::load is called when initializeSapling is called, not earlier/after
Sapling::load is called exactly once (the way the worker pool is written makes me think that this is not true on all platforms, and on some platforms Sapling::load may be called once per worker thread)
Summary
The Sapling parameters defined in
ironfish::sapling_bls12::SAPLING
are behind alazy_static
. As such, the parameters are not loaded until accessed fo the first time. The purpose ofinitializeSapling
is to acccess the parameters to ensure that they get loaded early.The current implementation of
initializeSapling
was calling.clone()
onironfish::sapling_bls12::SAPLING
, causing large amounts of memory to be allocated and written, only to be discarded shortly afterwards. The implementation has been changed to just dereferenceSAPLING
, without doing anything else. This is enough to triggerlazy_static
to load the parameters.Also:
Removed the
Arc
fromironfish::sapling_bls12::SAPLING
:Arc
is used to extend lifetimes in multithreaded environments, but the lifetime ofSAPLING
is static, so there's no point in extending it.Removed
ironfish::sapling_bls12::load
because it's not public and redundantTesting Plan
Add debug instrumentation to
initializeSapling
andSapling::load
. Verify that:Sapling::load
is called wheninitializeSapling
is called, not earlier/afterSapling::load
is called exactly once (the way the worker pool is written makes me think that this is not true on all platforms, and on some platformsSapling::load
may be called once per worker thread)Documentation
N/A
Breaking Change
N/A