Author: omtcyfz Date: Thu Sep 13 03:02:48 2018 New Revision: 342124 URL: http://llvm.org/viewvc/llvm-project?rev=342124&view=rev Log: [clangd] Don't create child AND and OR iterators with one posting list
`AND( AND( Child ) ... )` -> `AND( Child ... )` `AND( OR( Child ) ... )` -> `AND( Child ... )` This simple optimization results in 5-6% performance improvement in the benchmark with 2000 serialized `FuzzyFindRequest`s. Reviewed By: ilya-biryukov Differential Revision: https://reviews.llvm.org/D52016 Modified: clang-tools-extra/trunk/clangd/index/dex/Iterator.cpp Modified: clang-tools-extra/trunk/clangd/index/dex/Iterator.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/dex/Iterator.cpp?rev=342124&r1=342123&r2=342124&view=diff ============================================================================== --- clang-tools-extra/trunk/clangd/index/dex/Iterator.cpp (original) +++ clang-tools-extra/trunk/clangd/index/dex/Iterator.cpp Thu Sep 13 03:02:48 2018 @@ -198,7 +198,7 @@ class OrIterator : public Iterator { public: explicit OrIterator(std::vector<std::unique_ptr<Iterator>> AllChildren) : Children(std::move(AllChildren)) { - assert(Children.size() > 0 && "OR iterator must have at least one child."); + assert(!Children.empty() && "OR iterator should have at least one child."); } /// Returns true if all children are exhausted. @@ -405,12 +405,16 @@ std::unique_ptr<Iterator> create(Posting std::unique_ptr<Iterator> createAnd(std::vector<std::unique_ptr<Iterator>> Children) { - return llvm::make_unique<AndIterator>(move(Children)); + // If there is exactly one child, pull it one level up: AND(Child) -> Child. + return Children.size() == 1 ? std::move(Children.front()) + : llvm::make_unique<AndIterator>(move(Children)); } std::unique_ptr<Iterator> createOr(std::vector<std::unique_ptr<Iterator>> Children) { - return llvm::make_unique<OrIterator>(move(Children)); + // If there is exactly one child, pull it one level up: OR(Child) -> Child. + return Children.size() == 1 ? std::move(Children.front()) + : llvm::make_unique<OrIterator>(move(Children)); } std::unique_ptr<Iterator> createTrue(DocID Size) { _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits