Improve performance of surveying => faster search

- def.h: changed vectors for inorganics to contain uint8_t instead of bool which improves the performance when using std::fill and std::memset to batch-set the whole array
- survey.cpp: using std::memset instead of direct assignment to reset the inorganic vectors, also using the actual size of each vector for the call
- changelog.txt: add note concerning the changes
develop
bseiller 2021-05-23 11:28:48 +02:00
parent dbe77d08a1
commit 838285e925
3 changed files with 12 additions and 9 deletions

@ -42,6 +42,7 @@ changelog.txt uses a syntax similar to RST, with a few special sequences:
## Misc Improvements ## Misc Improvements
- `tweak` hide-priority: changed so that priorities stay hidden (or visible) when exiting and re-entering the designations menu - `tweak` hide-priority: changed so that priorities stay hidden (or visible) when exiting and re-entering the designations menu
- `embark-assistant`: slightly improved performance of surveying and improved code a little
## Lua ## Lua
- ``gui.Painter``: fixed error when calling ``viewport()`` method - ``gui.Painter``: fixed error when calling ``viewport()`` method

@ -91,9 +91,12 @@ namespace embark_assist {
int16_t river_elevation = 100; int16_t river_elevation = 100;
int8_t adamantine_level; // -1 = none, 0 .. 3 = cavern 1 .. magma sea. Currently not used beyond present/absent. int8_t adamantine_level; // -1 = none, 0 .. 3 = cavern 1 .. magma sea. Currently not used beyond present/absent.
int8_t magma_level; // -1 = none, 0 .. 3 = cavern 3 .. surface/volcano int8_t magma_level; // -1 = none, 0 .. 3 = cavern 3 .. surface/volcano
std::vector<bool> metals; // using uint8_t instead of bool as vector<bool> gets optimized for a small memory footprint which leads to a significant overhead when iterating over all entries,
std::vector<bool> economics; // also there seems to be no template specialization for std::fill in MSVS C++11 in regards to std::vector<bool> and std::memset does not work as expected (=> not at all that is)
std::vector<bool> minerals; // have a look here https://github.com/DFHack/dfhack/pull/1771#discussion_r579498636 for the related discussion and furter resources
std::vector<uint8_t> metals;
std::vector<uint8_t> economics;
std::vector<uint8_t> minerals;
}; };
typedef std::array<std::array<mid_level_tile, 16>, 16> mid_level_tiles; typedef std::array<std::array<mid_level_tile, 16>, 16> mid_level_tiles;

@ -909,15 +909,14 @@ void inline copy_incursion_values(embark_assist::defs::mid_level_tile_incursion_
//================================================================================= //=================================================================================
void reset_mlt_inorganics(embark_assist::defs::mid_level_tiles &mlts) { void reset_mlt_inorganics(embark_assist::defs::mid_level_tiles &mlts) {
const uint16_t size = mlts[0][0].metals.size();
for (uint8_t i = 0; i < 16; i++) { for (uint8_t i = 0; i < 16; i++) {
for (uint8_t k = 0; k < 16; k++) { for (uint8_t k = 0; k < 16; k++) {
embark_assist::defs::mid_level_tile &mlt = mlts[i][k]; embark_assist::defs::mid_level_tile &mlt = mlts[i][k];
for (uint16_t l = 0; l < size; l++) { // std::memset is much faster than std::fill and also faster than direct assignment - also std::fill might be compiled to std::memset but is not guaranteed to happen
mlt.metals[l] = false; // have a look here for why: https://travisdowns.github.io/blog/2020/01/20/zero.html
mlt.economics[l] = false; std::memset(&mlt.metals[0], false, mlt.metals.size() * sizeof(mlt.metals[0]));
mlt.minerals[l] = false; std::memset(&mlt.economics[0], false, mlt.economics.size() * sizeof(mlt.economics[0]));
} std::memset(&mlt.minerals[0], false, mlt.minerals.size() * sizeof(mlt.minerals[0]));
} }
} }
} }