sapling/eden/fs/model/Tree.cpp
Katie Mancini 1a02401df9 create a custom in memory tree cache
Summary:
Chad first noted that deserializing trees from the local store can be expensive.
From the thrift side EdenFS does not have a copy of trees in memory. This
means for glob files each of the trees that have not been materialized will be
read from the local store. Since reading an deserializing trees from the local
store can be expensive lets add an in memory cache so that some of these
reads can be satisfied from here instead.

This introduces the class for the in memory cache and is based on the existing
BlobCache. note that we keep the minimum number of entries functionality from
the blob cache. This is unlikely to be needed as trees are much less likely
than blobs to exceed a reasonable cache size limit, but kept since we already
have it.

Reviewed By: chadaustin

Differential Revision: D27050285

fbshipit-source-id: 9dd46419761d32387b6f55ff508b60105edae3af
2021-04-27 17:38:39 -07:00

36 lines
969 B
C++

/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This software may be used and distributed according to the terms of the
* GNU General Public License version 2.
*/
#include "Tree.h"
namespace facebook {
namespace eden {
bool operator==(const Tree& tree1, const Tree& tree2) {
return (tree1.getHash() == tree2.getHash()) &&
(tree1.getTreeEntries() == tree2.getTreeEntries());
}
bool operator!=(const Tree& tree1, const Tree& tree2) {
return !(tree1 == tree2);
}
size_t Tree::getSizeBytes() const {
// TODO: we should consider using a standard memory framework across
// eden for this type of thing. D17174143 is one such idea.
size_t internal_size = sizeof(*this);
size_t indirect_size =
folly::goodMallocSize(sizeof(TreeEntry) * entries_.capacity());
for (auto& entry : entries_) {
indirect_size += entry.getIndirectSizeBytes();
}
return internal_size + indirect_size;
}
} // namespace eden
} // namespace facebook