shift some long-lived allocs into spi ram
This commit is contained in:
@@ -41,7 +41,7 @@ class TagParserImpl : public ITagParser {
|
|||||||
* cache should be slightly larger than any page sizes in the UI.
|
* cache should be slightly larger than any page sizes in the UI.
|
||||||
*/
|
*/
|
||||||
std::mutex cache_mutex_;
|
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
|
// 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
|
// similar. This hasn't been done yet, as this isn't a common workload in
|
||||||
|
|||||||
@@ -74,6 +74,8 @@ auto tagToString(const TagValue&) -> std::string;
|
|||||||
*/
|
*/
|
||||||
class TrackTags {
|
class TrackTags {
|
||||||
public:
|
public:
|
||||||
|
static auto create() -> std::shared_ptr<TrackTags>;
|
||||||
|
|
||||||
TrackTags()
|
TrackTags()
|
||||||
: encoding_(Container::kUnsupported), genres_(&memory::kSpiRamResource) {}
|
: encoding_(Container::kUnsupported), genres_(&memory::kSpiRamResource) {}
|
||||||
|
|
||||||
|
|||||||
@@ -168,7 +168,7 @@ auto TagParserImpl::ReadAndParseTags(const std::string& path)
|
|||||||
auto GenericTagParser::ReadAndParseTags(const std::string& path)
|
auto GenericTagParser::ReadAndParseTags(const std::string& path)
|
||||||
-> std::shared_ptr<TrackTags> {
|
-> std::shared_ptr<TrackTags> {
|
||||||
libtags::Aux aux;
|
libtags::Aux aux;
|
||||||
auto out = std::make_shared<TrackTags>();
|
auto out = TrackTags::create();
|
||||||
aux.tags = out.get();
|
aux.tags = out.get();
|
||||||
{
|
{
|
||||||
auto lock = drivers::acquire_spi();
|
auto lock = drivers::acquire_spi();
|
||||||
@@ -244,7 +244,7 @@ auto OpusTagParser::ReadAndParseTags(const std::string& path)
|
|||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
auto out = std::make_shared<TrackTags>();
|
auto out = TrackTags::create();
|
||||||
out->encoding(Container::kOpus);
|
out->encoding(Container::kOpus);
|
||||||
for (const auto& pair : kVorbisIdToTag) {
|
for (const auto& pair : kVorbisIdToTag) {
|
||||||
const char* tag = opus_tags_query(tags, pair.first, 0);
|
const char* tag = opus_tags_query(tags, pair.first, 0);
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
|
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <memory_resource>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
@@ -90,6 +91,12 @@ auto tagToString(const TagValue& val) -> std::string {
|
|||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto TrackTags::create() -> std::shared_ptr<TrackTags> {
|
||||||
|
return std::allocate_shared<TrackTags,
|
||||||
|
std::pmr::polymorphic_allocator<TrackTags>>(
|
||||||
|
&memory::kSpiRamResource);
|
||||||
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
auto valueOrMonostate(std::optional<T> t) -> TagValue {
|
auto valueOrMonostate(std::optional<T> t) -> TagValue {
|
||||||
if (t) {
|
if (t) {
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ class Property {
|
|||||||
private:
|
private:
|
||||||
LuaValue value_;
|
LuaValue value_;
|
||||||
std::optional<std::function<bool(const LuaValue&)>> cb_;
|
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 {
|
class PropertyBindings {
|
||||||
@@ -61,7 +61,7 @@ class PropertyBindings {
|
|||||||
auto GetFunction(size_t i) -> const LuaFunction&;
|
auto GetFunction(size_t i) -> const LuaFunction&;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector<LuaFunction> functions_;
|
std::pmr::vector<LuaFunction> functions_;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace lua
|
} // namespace lua
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
#include "lua.hpp"
|
#include "lua.hpp"
|
||||||
#include "lua_thread.hpp"
|
#include "lua_thread.hpp"
|
||||||
#include "lvgl.h"
|
#include "lvgl.h"
|
||||||
|
#include "memory_resource.hpp"
|
||||||
#include "service_locator.hpp"
|
#include "service_locator.hpp"
|
||||||
#include "track.hpp"
|
#include "track.hpp"
|
||||||
#include "types.hpp"
|
#include "types.hpp"
|
||||||
@@ -158,11 +159,12 @@ auto PropertyBindings::GetFunction(size_t i) -> const LuaFunction& {
|
|||||||
template <class... Ts>
|
template <class... Ts>
|
||||||
inline constexpr bool always_false_v = false;
|
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,
|
Property::Property(const LuaValue& val,
|
||||||
std::function<bool(const LuaValue& val)> cb)
|
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 {
|
static auto pushTagValue(lua_State* L, const database::TagValue& val) -> void {
|
||||||
std::visit(
|
std::visit(
|
||||||
|
|||||||
@@ -13,6 +13,7 @@
|
|||||||
#include <optional>
|
#include <optional>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
#include "memory_resource.hpp"
|
||||||
|
|
||||||
namespace util {
|
namespace util {
|
||||||
|
|
||||||
@@ -25,7 +26,9 @@ namespace util {
|
|||||||
template <int Size, typename K, typename V>
|
template <int Size, typename K, typename V>
|
||||||
class LruCache {
|
class LruCache {
|
||||||
public:
|
public:
|
||||||
LruCache() : entries_(), key_to_it_() {}
|
LruCache()
|
||||||
|
: entries_(&memory::kSpiRamResource),
|
||||||
|
key_to_it_(&memory::kSpiRamResource) {}
|
||||||
|
|
||||||
auto Put(K key, V val) -> void {
|
auto Put(K key, V val) -> void {
|
||||||
if (key_to_it_.contains(key)) {
|
if (key_to_it_.contains(key)) {
|
||||||
@@ -62,8 +65,8 @@ class LruCache {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::list<std::pair<K, V>> entries_;
|
std::pmr::list<std::pair<K, V>> entries_;
|
||||||
std::unordered_map<K, decltype(entries_.begin())> key_to_it_;
|
std::pmr::unordered_map<K, decltype(entries_.begin())> key_to_it_;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace util
|
} // namespace util
|
||||||
|
|||||||
Reference in New Issue
Block a user