shift some long-lived allocs into spi ram

custom
jacqueline 1 year ago
parent 08d16e8580
commit 1f5249de6f
  1. 2
      src/database/include/tag_parser.hpp
  2. 2
      src/database/include/track.hpp
  3. 4
      src/database/tag_parser.cpp
  4. 7
      src/database/track.cpp
  5. 4
      src/lua/include/property.hpp
  6. 6
      src/lua/property.cpp
  7. 9
      src/util/include/lru_cache.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

@ -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) {}

@ -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);

@ -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) {

@ -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

@ -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(

@ -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

Loading…
Cancel
Save