summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorjacqueline <me@jacqueline.id.au>2024-04-02 19:36:35 +1100
committerjacqueline <me@jacqueline.id.au>2024-04-02 19:36:35 +1100
commit1e278d55c4dc0a9ae7b5b4511904202824e5c5df (patch)
tree8a456b5dfec45aafa55fcad54afbffd296521357 /lib
parent313c021c3b42c664808af4885fb6d0a122180137 (diff)
downloadtangara-fw-1e278d55c4dc0a9ae7b5b4511904202824e5c5df.tar.gz
tweak db performance
- leveldb cache pinned to spiram - actually use it during indexing lol - all up, saves about 10ms per file (amortised) for an incremental reindex
Diffstat (limited to 'lib')
-rw-r--r--lib/leveldb/util/cache.cc21
1 files changed, 15 insertions, 6 deletions
diff --git a/lib/leveldb/util/cache.cc b/lib/leveldb/util/cache.cc
index ad1e9a28..043b37a3 100644
--- a/lib/leveldb/util/cache.cc
+++ b/lib/leveldb/util/cache.cc
@@ -8,6 +8,7 @@
#include <cstdio>
#include <cstdlib>
+#include "esp_heap_caps.h"
#include "port/port.h"
#include "port/thread_annotations.h"
#include "util/hash.h"
@@ -157,7 +158,9 @@ class LRUCache {
void SetCapacity(size_t capacity) { capacity_ = capacity; }
// Like Cache methods, but with an extra "hash" parameter.
- Cache::Handle* Insert(const Slice& key, uint32_t hash, void* value,
+ Cache::Handle* Insert(const Slice& key,
+ uint32_t hash,
+ void* value,
size_t charge,
void (*deleter)(const Slice& key, void* value));
Cache::Handle* Lookup(const Slice& key, uint32_t hash);
@@ -264,14 +267,16 @@ void LRUCache::Release(Cache::Handle* handle) {
Unref(reinterpret_cast<LRUHandle*>(handle));
}
-Cache::Handle* LRUCache::Insert(const Slice& key, uint32_t hash, void* value,
+Cache::Handle* LRUCache::Insert(const Slice& key,
+ uint32_t hash,
+ void* value,
size_t charge,
void (*deleter)(const Slice& key,
void* value)) {
MutexLock l(&mutex_);
- LRUHandle* e =
- reinterpret_cast<LRUHandle*>(malloc(sizeof(LRUHandle) - 1 + key.size()));
+ LRUHandle* e = reinterpret_cast<LRUHandle*>(
+ heap_caps_malloc(sizeof(LRUHandle) - 1 + key.size(), MALLOC_CAP_SPIRAM));
e->value = value;
e->deleter = deleter;
e->charge = charge;
@@ -356,7 +361,9 @@ class ShardedLRUCache : public Cache {
}
}
~ShardedLRUCache() override {}
- Handle* Insert(const Slice& key, void* value, size_t charge,
+ Handle* Insert(const Slice& key,
+ void* value,
+ size_t charge,
void (*deleter)(const Slice& key, void* value)) override {
const uint32_t hash = HashSlice(key);
return shard_[Shard(hash)].Insert(key, hash, value, charge, deleter);
@@ -396,6 +403,8 @@ class ShardedLRUCache : public Cache {
} // end anonymous namespace
-Cache* NewLRUCache(size_t capacity) { return new ShardedLRUCache(capacity); }
+Cache* NewLRUCache(size_t capacity) {
+ return new ShardedLRUCache(capacity);
+}
} // namespace leveldb