mirror of
https://github.com/facebook/sapling.git
synced 2024-10-15 19:29:13 +03:00
1a02401df9
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
36 lines
969 B
C++
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
|