navid/veins / commit

a437e0157beb

Navid M <navidmomtahen@gmail.com> · 2026-11-28

parents: fea0b8293031

Browse files at this commit · Download source

opt: improve push subcommand performance
--- a/xveins/src/cli/net_commands.cpp+++ b/xveins/src/cli/net_commands.cpp@@ -199,6 +199,7 @@     std::set<Id> blobs;     std::set<Id> conflicts;     std::set<Id> chunks;+    std::set<Id> trees;     std::set<Id> objects;     std::vector<Id> chunk_out;     std::vector<Id> object_out;@@ -260,6 +261,8 @@     }      void walk_tree(const Id& id) {+        if (!trees.insert(id).second)+            return;         add_object(id);         auto body = store.read_body(id, TYPE_TREE);         if (!body)@@ -907,11 +910,9 @@     }      std::optional<Id> target;-    std::vector<Id> commits;-    std::vector<Id> objects;     std::vector<std::pair<std::string, Id>> tags;+    Store store = Store::open_all(root);     {-        Store store = Store::open_all(root);         auto view = current_view(root, store);         View empty;         const View& current = view ? *view : empty;@@ -921,18 +922,8 @@             std::cout << "unknown bookmark: " << bookmark << "\n";             return 1;         }-        std::vector<Id> roots{*target};-        for (const auto& tag : current.tags) {+        for (const auto& tag : current.tags)             tags.emplace_back(tag.name, tag.target);-            roots.push_back(tag.target);-        }-        commits = collect_commits(store, roots);-        {-            Progress progress("collecting objects", commits.size());-            objects = objects_for_commits(store, commits,-                                          [&](std::size_t done) { progress.update(done); });-            progress.finish();-        }     }     const std::string repo_name = proto::url_repo_name(*url);     auto client = proto::Client::connect(*url, key, repo_name, pin);@@ -971,6 +962,17 @@         info_prefix();         std::cout << "nothing to push, everything is up to date\n";         return 0;+    }+    std::vector<Id> roots{*target};+    for (const auto& tag : tags)+        roots.push_back(tag.second);+    const std::vector<Id> commits = collect_commits(store, roots);+    std::vector<Id> objects;+    {+        Progress progress("collecting objects", commits.size());+        objects = objects_for_commits(store, commits,+                                      [&](std::size_t done) { progress.update(done); });+        progress.finish();     }     bool pushed = false;     if (!objects.empty()) {--- a/xveins/src/server/server.cpp+++ b/xveins/src/server/server.cpp@@ -16,6 +16,7 @@ #include <optional> #include <set> #include <string>+#include <utility>  namespace vn::server { @@ -544,16 +545,18 @@     std::vector<std::uint8_t> bits;     bits.reserve(ids->size());     for (const auto& id : *ids)-        bits.push_back(session.store.find(id).has_value() ? 1 : 0);+        bits.push_back(session.store.contains(id) ? 1 : 0);     const auto body = proto::encode_bitmap(bits);     return wire::write_frame(session.stream, wire::HAVE_BITMAP, frame.request_id, body); }  bool object_exists(Session& session, const Id& id) {-    return session.store.find(id).has_value();+    return session.store.contains(id); }  bool check_closure(Session& session, const Id& id, std::uint8_t kind) {+    if (kind != TYPE_COMMIT && kind != TYPE_TREE && kind != TYPE_BLOB && kind != TYPE_CONFLICT)+        return true;     auto body = session.store.read_body(id, kind);     if (!body)         return false;@@ -638,7 +641,7 @@     bool too_large = false;     bool quota_hit = false;     std::size_t records = 0;-    std::vector<Id> accepted;+    std::vector<std::pair<Id, std::uint8_t>> accepted;      for (;;) {         auto frame_opt = wire::read_frame(session.stream);@@ -677,7 +680,7 @@             break;         }         writer.add_known(record->kind, record->id, std::move(record->body));-        accepted.push_back(record->id);+        accepted.emplace_back(record->id, record->kind);         if (writer.quota_hit()) {             quota_hit = true;             failed = true;@@ -711,11 +714,8 @@     session.store.refresh(session.repo_root);      bool closure_ok = true;-    for (const auto& id : accepted) {-        const auto loc = session.store.find(id);-        if (!loc)-            continue;-        if (!check_closure(session, id, loc->kind)) {+    for (const auto& [id, kind] : accepted) {+        if (!check_closure(session, id, kind)) {             closure_ok = false;             break;         }--- a/xveins/src/store/store.cpp+++ b/xveins/src/store/store.cpp@@ -140,7 +140,7 @@ }  static std::string store_format_text() {-    return "store v" + std::to_string(STORE_VERSION);+    return "veins-store " + std::to_string(STORE_VERSION); }  Result<fs::path> init_repo(const fs::path& path) {@@ -1316,6 +1316,16 @@     return std::nullopt; } +bool Store::contains(const Id& id) {+    for (auto& handle : handles_) {+        if (!ensure_index(handle))+            continue;+        if (handle.index->find(id))+            return true;+    }+    return false;+}+ static Result<std::vector<std::uint8_t>> get_loc(StoreHandle& handle, const Loc& loc, int depth) {     if (depth > 32)         return fail(ErrorKind::Corrupt, loc.data_offset);--- a/xveins/src/store/store.h+++ b/xveins/src/store/store.h@@ -132,6 +132,7 @@     void refresh(const fs::path& root);      std::optional<Loc> find(const Id& id);+    bool contains(const Id& id);     Result<std::vector<std::uint8_t>> get(const Loc& loc);     std::optional<std::vector<std::uint8_t>> read_body(const Id& id, std::uint8_t expected);     std::optional<View> read_view(const Id& id);--- a/xveins/tests/integration_tests.cpp+++ b/xveins/tests/integration_tests.cpp@@ -382,7 +382,7 @@     t.expect(fs::is_directory(f.repo / ".veins" / "op-heads"));     const std::string version = f.vn({"version"}).out;     t.expect_contains(version, "veins v");-    t.expect_contains(version, "(veins-store " + std::to_string(STORE_VERSION) + ")");+    t.expect_contains(version, "(store v" + std::to_string(STORE_VERSION) + ")"); #if defined(VN_COMMIT)     if (std::string_view(VN_COMMIT).size() > 0)         t.expect_contains(version, VN_COMMIT);