diff --git a/src/IO/H5/VolumeData.cpp b/src/IO/H5/VolumeData.cpp index 5af993274c1d..76ed7691f7da 100644 --- a/src/IO/H5/VolumeData.cpp +++ b/src/IO/H5/VolumeData.cpp @@ -14,6 +14,7 @@ #include #include #include +#include #include #include "DataStructures/DataVector.hpp" @@ -417,8 +418,13 @@ std::vector VolumeData::list_observation_ids() const { std::vector obs_ids{ boost::make_transform_iterator(names.begin(), helper), boost::make_transform_iterator(names.end(), helper)}; - alg::sort(obs_ids, [this](const size_t lhs, const size_t rhs) { - return this->get_observation_value(lhs) < this->get_observation_value(rhs); + // pre-compute the observation values as they are expensive to evaluate + std::unordered_map obs_values{obs_ids.size()}; + for (const auto& id : obs_ids) { + obs_values[id] = this->get_observation_value(id); + } + alg::sort(obs_ids, [&obs_values](const size_t lhs, const size_t rhs) { + return obs_values[lhs] < obs_values[rhs]; }); return obs_ids; }