diff --git a/src/attribute_store.cpp b/src/attribute_store.cpp index 73ed4775..93b813e8 100644 --- a/src/attribute_store.cpp +++ b/src/attribute_store.cpp @@ -101,8 +101,8 @@ const AttributePair& AttributePairStore::getPairUnsafe(uint32_t i) const { thread_local uint64_t tlsPairLookups = 0; thread_local uint64_t tlsPairLookupsUncached = 0; -thread_local std::vector cachedAttributePairPointers(64); -thread_local std::vector cachedAttributePairIndexes(64); +thread_local std::vector cachedAttributePairPointers(256); +thread_local std::vector cachedAttributePairIndexes(256); uint32_t AttributePairStore::addPair(AttributePair& pair, bool isHot) { if (isHot) { { @@ -300,8 +300,8 @@ void AttributeSet::finalize() { // Remember recently queried/added sets so that we can return them in the // future without taking a lock. -thread_local std::vector cachedAttributeSetPointers(64); -thread_local std::vector cachedAttributeSetIndexes(64); +thread_local std::vector cachedAttributeSetPointers(256); +thread_local std::vector cachedAttributeSetIndexes(256); thread_local uint64_t tlsSetLookups = 0; thread_local uint64_t tlsSetLookupsUncached = 0; diff --git a/src/osm_lua_processing.cpp b/src/osm_lua_processing.cpp index bc5271a4..541a8a81 100644 --- a/src/osm_lua_processing.cpp +++ b/src/osm_lua_processing.cpp @@ -10,6 +10,7 @@ #include "node_store.h" #include "polylabel.h" #include +#include using namespace std; @@ -18,6 +19,8 @@ thread_local kaguya::State *g_luaState = nullptr; thread_local OsmLuaProcessing* osmLuaProcessing = nullptr; std::mutex vectorLayerMetadataMutex; +thread_local const LayerDefinition* vectorLayerMetadataCacheLayers = nullptr; +thread_local std::vector> vectorLayerMetadataCache; std::unordered_map OsmLuaProcessing::dataStore; std::mutex OsmLuaProcessing::dataStoreMutex; @@ -1032,8 +1035,23 @@ std::string OsmLuaProcessing::FindInRelation(const std::string &key) { // Record attribute name/type for vector_layers table void OsmLuaProcessing::setVectorLayerMetadata(const uint_least8_t layer, const string &key, const uint type) { - std::lock_guard lock(vectorLayerMetadataMutex); - layers.layers[layer].attributeMap[key] = type; + if (vectorLayerMetadataCacheLayers != &layers) { + vectorLayerMetadataCache.clear(); + vectorLayerMetadataCacheLayers = &layers; + } + if (vectorLayerMetadataCache.size() <= layer) + vectorLayerMetadataCache.resize(layer + 1); + + auto &metadataCache = vectorLayerMetadataCache[layer]; + const auto it = metadataCache.find(key); + if (it != metadataCache.end() && it->second == type) + return; + + { + std::lock_guard lock(vectorLayerMetadataMutex); + layers.layers[layer].attributeMap[key] = type; + } + metadataCache[key] = type; } // Scan relation (but don't write geometry)