From 1f5249de6f7e81aa6ff2586e386f526676e67c81 Mon Sep 17 00:00:00 2001 From: jacqueline Date: Wed, 17 Jan 2024 15:31:23 +1100 Subject: [PATCH] shift some long-lived allocs into spi ram --- src/database/include/tag_parser.hpp | 2 +- src/database/include/track.hpp | 2 ++ src/database/tag_parser.cpp | 4 ++-- src/database/track.cpp | 7 +++++++ src/lua/include/property.hpp | 4 ++-- src/lua/property.cpp | 6 ++++-- src/util/include/lru_cache.hpp | 9 ++++++--- 7 files changed, 24 insertions(+), 10 deletions(-) diff --git a/src/database/include/tag_parser.hpp b/src/database/include/tag_parser.hpp index 977c9afc..fe7a95f3 100644 --- a/src/database/include/tag_parser.hpp +++ b/src/database/include/tag_parser.hpp @@ -41,7 +41,7 @@ class TagParserImpl : public ITagParser { * cache should be slightly larger than any page sizes in the UI. */ std::mutex cache_mutex_; - util::LruCache<16, std::pmr::string, std::shared_ptr> cache_; + util::LruCache<8, std::pmr::string, std::shared_ptr> cache_; // We could also consider keeping caches of artist name -> std::string and // similar. This hasn't been done yet, as this isn't a common workload in diff --git a/src/database/include/track.hpp b/src/database/include/track.hpp index 610ab487..76b1c56e 100644 --- a/src/database/include/track.hpp +++ b/src/database/include/track.hpp @@ -74,6 +74,8 @@ auto tagToString(const TagValue&) -> std::string; */ class TrackTags { public: + static auto create() -> std::shared_ptr; + TrackTags() : encoding_(Container::kUnsupported), genres_(&memory::kSpiRamResource) {} diff --git a/src/database/tag_parser.cpp b/src/database/tag_parser.cpp index 0efe5804..a3a05a5c 100644 --- a/src/database/tag_parser.cpp +++ b/src/database/tag_parser.cpp @@ -168,7 +168,7 @@ auto TagParserImpl::ReadAndParseTags(const std::string& path) auto GenericTagParser::ReadAndParseTags(const std::string& path) -> std::shared_ptr { libtags::Aux aux; - auto out = std::make_shared(); + auto out = TrackTags::create(); aux.tags = out.get(); { auto lock = drivers::acquire_spi(); @@ -244,7 +244,7 @@ auto OpusTagParser::ReadAndParseTags(const std::string& path) return {}; } - auto out = std::make_shared(); + auto out = TrackTags::create(); out->encoding(Container::kOpus); for (const auto& pair : kVorbisIdToTag) { const char* tag = opus_tags_query(tags, pair.first, 0); diff --git a/src/database/track.cpp b/src/database/track.cpp index 58097cef..943606ce 100644 --- a/src/database/track.cpp +++ b/src/database/track.cpp @@ -8,6 +8,7 @@ #include #include +#include #include #include @@ -90,6 +91,12 @@ auto tagToString(const TagValue& val) -> std::string { return ""; } +auto TrackTags::create() -> std::shared_ptr { + return std::allocate_shared>( + &memory::kSpiRamResource); +} + template auto valueOrMonostate(std::optional t) -> TagValue { if (t) { diff --git a/src/lua/include/property.hpp b/src/lua/include/property.hpp index 9c5129ae..425cc15c 100644 --- a/src/lua/include/property.hpp +++ b/src/lua/include/property.hpp @@ -48,7 +48,7 @@ class Property { private: LuaValue value_; std::optional> cb_; - std::vector> bindings_; + std::pmr::vector> bindings_; }; class PropertyBindings { @@ -61,7 +61,7 @@ class PropertyBindings { auto GetFunction(size_t i) -> const LuaFunction&; private: - std::vector functions_; + std::pmr::vector functions_; }; } // namespace lua diff --git a/src/lua/property.cpp b/src/lua/property.cpp index 2d702447..14056af7 100644 --- a/src/lua/property.cpp +++ b/src/lua/property.cpp @@ -17,6 +17,7 @@ #include "lua.hpp" #include "lua_thread.hpp" #include "lvgl.h" +#include "memory_resource.hpp" #include "service_locator.hpp" #include "track.hpp" #include "types.hpp" @@ -158,11 +159,12 @@ auto PropertyBindings::GetFunction(size_t i) -> const LuaFunction& { template inline constexpr bool always_false_v = false; -Property::Property(const LuaValue& val) : value_(val), cb_() {} +Property::Property(const LuaValue& val) + : value_(val), cb_(), bindings_(&memory::kSpiRamResource) {} Property::Property(const LuaValue& val, std::function cb) - : value_(val), cb_(cb) {} + : value_(val), cb_(cb), bindings_(&memory::kSpiRamResource) {} static auto pushTagValue(lua_State* L, const database::TagValue& val) -> void { std::visit( diff --git a/src/util/include/lru_cache.hpp b/src/util/include/lru_cache.hpp index 8f955a07..41293901 100644 --- a/src/util/include/lru_cache.hpp +++ b/src/util/include/lru_cache.hpp @@ -13,6 +13,7 @@ #include #include #include +#include "memory_resource.hpp" namespace util { @@ -25,7 +26,9 @@ namespace util { template class LruCache { public: - LruCache() : entries_(), key_to_it_() {} + LruCache() + : entries_(&memory::kSpiRamResource), + key_to_it_(&memory::kSpiRamResource) {} auto Put(K key, V val) -> void { if (key_to_it_.contains(key)) { @@ -62,8 +65,8 @@ class LruCache { } private: - std::list> entries_; - std::unordered_map key_to_it_; + std::pmr::list> entries_; + std::pmr::unordered_map key_to_it_; }; } // namespace util