perf(GraphEngine): more caching
Added more agressive caching, regained about another 50% performance gain. Solar model over 10Gyr now takes roughly 400ms (as opposed to 1 second before)
This commit is contained in:
@@ -882,6 +882,7 @@ namespace gridfire::engine {
|
||||
mutable CppAD::ADFun<double> m_epsADFun; ///< CppAD function for the energy generation rate.
|
||||
mutable CppAD::sparse_jac_work m_jac_work; ///< Work object for sparse Jacobian calculations.
|
||||
mutable std::vector<double> m_local_abundance_cache;
|
||||
mutable std::unordered_map<size_t, StepDerivatives<double>> m_stepDerivativesCache;
|
||||
|
||||
bool m_has_been_primed = false; ///< Flag indicating if the engine has been primed.
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include <cstdint>
|
||||
#include <functional>
|
||||
|
||||
#include "fourdst/composition/utils/composition_hash.h"
|
||||
#include "gridfire/exceptions/exceptions.h"
|
||||
#include "gridfire/reaction/reaction.h"
|
||||
|
||||
@@ -69,4 +70,21 @@ namespace gridfire::utils {
|
||||
seed ^= hasher(v) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
|
||||
return seed;
|
||||
}
|
||||
|
||||
inline std::size_t hash_state(
|
||||
const fourdst::composition::CompositionAbstract& comp,
|
||||
const double T9,
|
||||
const double rho,
|
||||
const reaction::ReactionSet& reactions
|
||||
) noexcept {
|
||||
constexpr std::size_t seed = 0;
|
||||
std::size_t comp_hash = fourdst::composition::utils::CompositionHash::hash_exact(comp);
|
||||
for (const auto& reaction : reactions) {
|
||||
comp_hash = hash_combine(comp_hash, hash_reaction(*reaction));
|
||||
}
|
||||
std::size_t hash = hash_combine(seed, comp_hash);
|
||||
hash = hash_combine(hash, std::bit_cast<std::size_t>(T9));
|
||||
hash = hash_combine(hash, std::bit_cast<std::size_t>(rho));
|
||||
return hash;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user