summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjacqueline <me@jacqueline.id.au>2024-01-17 15:31:23 +1100
committerjacqueline <me@jacqueline.id.au>2024-01-17 15:31:23 +1100
commit1f5249de6f7e81aa6ff2586e386f526676e67c81 (patch)
tree5fcc9737e71b3b6b20b7156ea4e759b558f732a3
parent08d16e858075e66df1bae3fea9d955e1b6cb73a9 (diff)
downloadtangara-fw-1f5249de6f7e81aa6ff2586e386f526676e67c81.tar.gz
shift some long-lived allocs into spi ram
-rw-r--r--src/database/include/tag_parser.hpp2
-rw-r--r--src/database/include/track.hpp2
-rw-r--r--src/database/tag_parser.cpp4
-rw-r--r--src/database/track.cpp7
-rw-r--r--src/lua/include/property.hpp4
-rw-r--r--src/lua/property.cpp6
-rw-r--r--src/util/include/lru_cache.hpp9
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<TrackTags>> cache_;
+ util::LruCache<8, std::pmr::string, std::shared_ptr<TrackTags>> 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>;
+
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<TrackTags> {
libtags::Aux aux;
- auto out = std::make_shared<TrackTags>();
+ 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<TrackTags>();
+ 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 <iomanip>
#include <iostream>
+#include <memory_resource>
#include <sstream>
#include <string>
@@ -90,6 +91,12 @@ auto tagToString(const TagValue& val) -> std::string {
return "";
}
+auto TrackTags::create() -> std::shared_ptr<TrackTags> {
+ return std::allocate_shared<TrackTags,
+ std::pmr::polymorphic_allocator<TrackTags>>(
+ &memory::kSpiRamResource);
+}
+
template <typename T>
auto valueOrMonostate(std::optional<T> 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<std::function<bool(const LuaValue&)>> cb_;
- std::vector<std::pair<lua_State*, int>> bindings_;
+ std::pmr::vector<std::pair<lua_State*, int>> bindings_;
};
class PropertyBindings {
@@ -61,7 +61,7 @@ class PropertyBindings {
auto GetFunction(size_t i) -> const LuaFunction&;
private:
- std::vector<LuaFunction> functions_;
+ std::pmr::vector<LuaFunction> 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 <class... Ts>
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<bool(const LuaValue& val)> 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 <optional>
#include <unordered_map>
#include <utility>
+#include "memory_resource.hpp"
namespace util {
@@ -25,7 +26,9 @@ namespace util {
template <int Size, typename K, typename V>
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<std::pair<K, V>> entries_;
- std::unordered_map<K, decltype(entries_.begin())> key_to_it_;
+ std::pmr::list<std::pair<K, V>> entries_;
+ std::pmr::unordered_map<K, decltype(entries_.begin())> key_to_it_;
};
} // namespace util