You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@graphar.apache.org by "SYaoJun (via GitHub)" <gi...@apache.org> on 2026/02/14 01:50:18 UTC

[PR] feat(c++): add LRU chunk cache to Arrow chunk readers to avoid redundandt file IO [incubator-graphar]

SYaoJun opened a new pull request, #861:
URL: https://github.com/apache/incubator-graphar/pull/861

   
   
   <!--
   Thanks for contributing to GraphAr.
   If this is your first pull request you can find detailed information on [CONTRIBUTING.md](https://github.com/apache/graphar/blob/main/CONTRIBUTING.md)
   
   The Apache GraphAr (incubating) community has restrictions on the naming of pr title. You can find instructions in
   [CONTRIBUTING.md](https://github.com/apache/graphar/blob/main/CONTRIBUTING.md#title) too.
   -->
   issue: #860 
   
   ### Reason for this PR
   <!-- 
   Why are you proposing this change? If this is already tracked in an issue, please link to the issue here.
   Explaining clearly why this change is beneficial is important for the reviewers to understand the context.
   -->
   
   I need to do more tests
   
   ### What changes are included in this PR?
   <!-- 
   There is no need to duplicate the description in the issue here but it is sometimes worth providing a summary of the individual changes in this PR.
   -->
   
   ### Are these changes tested?
   <!--
   We typically require tests for all PRs in order to:
   1. Prevent the code from being accidentally broken by subsequent changes
   2. Serve as another way to document the expected behavior of the code
   
   If tests are not included in your PR, please explain why (for example, are they covered by existing tests)?
   -->
   
   ### Are there any user-facing changes?
   <!--
   If there are user-facing changes then we may require documentation to be updated before approving the PR.
   -->
   
   <!--
   If there are any breaking changes to public APIs, please uncomment the line below and explain which changes are breaking.
   -->
   <!-- **BREAKING CHANGE: <description>** -->
   
   <!--
   Please uncomment the line below (and provide explanation) if the changes fix either
   (a) a security vulnerability,
   (b) a bug that caused incorrect or invalid data to be produced, or
   (c) a bug that causes a crash (even when the API contract is upheld). 
   We use this to highlight fixes to issues that may affect users without their knowledge. For this reason, fixing bugs that cause errors don't count, since those are usually obvious.
   -->
   <!-- **Critical Fix: <description>** -->
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@graphar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@graphar.apache.org
For additional commands, e-mail: commits-help@graphar.apache.org


Re: [PR] feat(c++): add LRU chunk cache to Arrow chunk readers to avoid redundandt file IO [incubator-graphar]

Posted by "yangxk1 (via GitHub)" <gi...@apache.org>.
yangxk1 commented on code in PR #861:
URL: https://github.com/apache/incubator-graphar/pull/861#discussion_r2870268637


##########
cpp/src/graphar/arrow/chunk_reader.cc:
##########
@@ -352,17 +354,22 @@ Status VertexPropertyArrowChunkReader::next_chunk() {
         vertex_info_->GetType(), " chunk num ", chunk_num_);
   }
   seek_id_ = chunk_index_ * vertex_info_->GetChunkSize();
-  chunk_table_.reset();
+  auto* cached = chunk_cache_.Get(chunk_index_);
+  chunk_table_ = cached ? *cached : nullptr;
 
   return Status::OK();
 }
 
 void VertexPropertyArrowChunkReader::Filter(util::Filter filter) {
   filter_options_.filter = filter;
+  chunk_table_ = nullptr;
+  chunk_cache_.Clear();
 }
 
 void VertexPropertyArrowChunkReader::Select(util::ColumnNames column_names) {
   filter_options_.columns = column_names;
+  chunk_table_ = nullptr;

Review Comment:
   Should it be initialized in this `xxxSelect` function?



##########
cpp/src/graphar/arrow/chunk_reader.cc:
##########
@@ -352,17 +354,22 @@ Status VertexPropertyArrowChunkReader::next_chunk() {
         vertex_info_->GetType(), " chunk num ", chunk_num_);
   }
   seek_id_ = chunk_index_ * vertex_info_->GetChunkSize();
-  chunk_table_.reset();
+  auto* cached = chunk_cache_.Get(chunk_index_);
+  chunk_table_ = cached ? *cached : nullptr;
 
   return Status::OK();
 }
 
 void VertexPropertyArrowChunkReader::Filter(util::Filter filter) {
   filter_options_.filter = filter;
+  chunk_table_ = nullptr;

Review Comment:
   Should it be initialized in this `xxxFilter` function?



##########
cpp/src/graphar/arrow/chunk_reader.h:
##########
@@ -267,6 +268,7 @@ class VertexPropertyArrowChunkReader {
   IdType vertex_num_;
   std::shared_ptr<arrow::Schema> schema_;
   std::shared_ptr<arrow::Table> chunk_table_;
+  LRUCache<IdType, std::shared_ptr<arrow::Table>> chunk_cache_{4};

Review Comment:
   chunk_cache **size** can judge based on memory or let the user control it will be better?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@graphar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@graphar.apache.org
For additional commands, e-mail: commits-help@graphar.apache.org


Re: [PR] feat(c++): add LRU chunk cache to Arrow chunk readers to avoid redundandt file IO [incubator-graphar]

Posted by "SYaoJun (via GitHub)" <gi...@apache.org>.
SYaoJun commented on code in PR #861:
URL: https://github.com/apache/incubator-graphar/pull/861#discussion_r2872399748


##########
cpp/src/graphar/arrow/chunk_reader.cc:
##########
@@ -352,17 +354,22 @@ Status VertexPropertyArrowChunkReader::next_chunk() {
         vertex_info_->GetType(), " chunk num ", chunk_num_);
   }
   seek_id_ = chunk_index_ * vertex_info_->GetChunkSize();
-  chunk_table_.reset();
+  auto* cached = chunk_cache_.Get(chunk_index_);
+  chunk_table_ = cached ? *cached : nullptr;
 
   return Status::OK();
 }
 
 void VertexPropertyArrowChunkReader::Filter(util::Filter filter) {
   filter_options_.filter = filter;
+  chunk_table_ = nullptr;

Review Comment:
   Yes, After filter the cache is outdated.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@graphar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@graphar.apache.org
For additional commands, e-mail: commits-help@graphar.apache.org


Re: [PR] feat(c++): add LRU chunk cache to Arrow chunk readers to avoid redundandt file IO [incubator-graphar]

Posted by "yangxk1 (via GitHub)" <gi...@apache.org>.
yangxk1 commented on PR #861:
URL: https://github.com/apache/incubator-graphar/pull/861#issuecomment-3995769646

   I don't think the existing benchmarks can be used to reflect performance changes. For example, `AdjListPropertyArrowChunkReaderReadChunk` creates a reader and uses this reader to read `chunk0` and `chunk1` multiple times, which will cause all data to be hit in the cache. A better way is to create a separate benchmark file and test the chunksize as 0/1/n respectively.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@graphar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@graphar.apache.org
For additional commands, e-mail: commits-help@graphar.apache.org


Re: [PR] feat(c++): add LRU chunk cache to Arrow chunk readers to avoid redundandt file IO [incubator-graphar]

Posted by "yangxk1 (via GitHub)" <gi...@apache.org>.
yangxk1 commented on code in PR #861:
URL: https://github.com/apache/incubator-graphar/pull/861#discussion_r2872293840


##########
cpp/src/graphar/arrow/chunk_reader.h:
##########
@@ -267,6 +268,7 @@ class VertexPropertyArrowChunkReader {
   IdType vertex_num_;
   std::shared_ptr<arrow::Schema> schema_;
   std::shared_ptr<arrow::Table> chunk_table_;
+  LRUCache<IdType, std::shared_ptr<arrow::Table>> chunk_cache_{4};

Review Comment:
   Putting it in the options and having a default value is a good temporary solution. Maybe we can open a new issue to track it until we can come up with a solution that balances memory, user experience, and efficiency.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@graphar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@graphar.apache.org
For additional commands, e-mail: commits-help@graphar.apache.org


Re: [PR] feat(c++): add LRU chunk cache to Arrow chunk readers to avoid redundandt file IO [incubator-graphar]

Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #861:
URL: https://github.com/apache/incubator-graphar/pull/861#discussion_r2867118392


##########
cpp/src/graphar/lru_cache.h:
##########
@@ -0,0 +1,86 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#pragma once
+
+#include <cstddef>
+#include <list>
+#include <unordered_map>
+#include <utility>
+
+namespace graphar {
+
+template <typename Key, typename Value, typename Hash = std::hash<Key>>
+class LRUCache {
+ public:
+  explicit LRUCache(size_t capacity) : capacity_(capacity) {}
+
+  Value* Get(const Key& key) {
+    auto it = map_.find(key);
+    if (it == map_.end()) {
+      return nullptr;
+    }
+    items_.splice(items_.begin(), items_, it->second);
+    return &it->second->second;
+  }
+
+  void Put(const Key& key, Value value) {
+    auto it = map_.find(key);
+    if (it != map_.end()) {
+      it->second->second = std::move(value);
+      items_.splice(items_.begin(), items_, it->second);
+      return;
+    }
+    if (capacity_ == 0) {
+      return;
+    }
+    if (map_.size() >= capacity_) {
+      auto& back = items_.back();
+      map_.erase(back.first);
+      items_.pop_back();
+    }
+    items_.emplace_front(key, std::move(value));
+    map_[key] = items_.begin();
+  }
+
+  void Clear() {
+    map_.clear();
+    items_.clear();
+  }
+
+  size_t Size() const { return map_.size(); }
+
+ private:
+  size_t capacity_;
+  std::list<std::pair<Key, Value>> items_;
+  std::unordered_map<Key, typename std::list<std::pair<Key, Value>>::iterator,
+                     Hash>
+      map_;
+};
+
+struct PairHash {
+  template <typename T1, typename T2>
+  size_t operator()(const std::pair<T1, T2>& p) const {
+    auto h1 = std::hash<T1>{}(p.first);
+    auto h2 = std::hash<T2>{}(p.second);
+    return h1 ^ (h2 << 32);

Review Comment:
   `PairHash` combines hashes via `h1 ^ (h2 << 32)`. Shifting by 32 is undefined behavior when `size_t` is 32-bit, and even on 64-bit this is a weak combiner (high collision risk). Please switch to a portable hash-combine that doesn't assume `size_t` width (e.g., `h1 ^ (h2 + 0x9e3779b97f4a7c15ULL + (h1<<6) + (h1>>2))` or an equivalent width-agnostic approach).
   ```suggestion
       size_t h1 = std::hash<T1>{}(p.first);
       size_t h2 = std::hash<T2>{}(p.second);
       // Width-agnostic hash combine (inspired by boost::hash_combine)
       constexpr size_t kMul =
           static_cast<size_t>(0x9e3779b97f4a7c15ULL);
       h1 ^= h2 + kMul + (h1 << 6) + (h1 >> 2);
       return h1;
   ```



##########
cpp/src/graphar/lru_cache.h:
##########
@@ -0,0 +1,86 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#pragma once
+
+#include <cstddef>
+#include <list>
+#include <unordered_map>
+#include <utility>
+
+namespace graphar {
+
+template <typename Key, typename Value, typename Hash = std::hash<Key>>
+class LRUCache {
+ public:

Review Comment:
   `LRUCache` uses `std::hash<Key>` as the default `Hash` template parameter but this header doesn't include `<functional>`. Relying on transitive includes from `<unordered_map>` is non-portable and can break builds on some standard library implementations; please include `<functional>` explicitly here.



##########
cpp/src/graphar/arrow/chunk_reader.cc:
##########
@@ -1024,6 +1051,8 @@ AdjListPropertyArrowChunkReader::GetChunk() {
       GAR_RETURN_NOT_OK(
           CastTableWithSchema(chunk_table_, schema_, &chunk_table_));
     }
+    chunk_cache_.Put(std::make_pair(vertex_chunk_index_, chunk_index_),
+                     chunk_table_);
   }

Review Comment:
   `AdjListPropertyArrowChunkReader` caches `chunk_table_` only by `(vertex_chunk_index_, chunk_index_)`, but the actual table content/shape depends on `filter_options_` (Filter/Select). If Filter/Select is changed and the reader returns to an already-cached chunk, it may return stale results from the previous filter/projection. Please invalidate the cache on Filter/Select changes or incorporate the effective filter/projection into the cache key.



##########
cpp/src/graphar/arrow/chunk_reader.cc:
##########
@@ -260,6 +259,7 @@ VertexPropertyArrowChunkReader::GetChunkV2() {
       GAR_RETURN_NOT_OK(
           CastTableWithSchema(chunk_table_, schema_, &chunk_table_));
     }
+    chunk_cache_.Put(chunk_index_, chunk_table_);
   }

Review Comment:
   `VertexPropertyArrowChunkReader` now caches `chunk_table_` only by `chunk_index_`, but the loaded table also depends on `filter_options_` (Filter/Select) and `property_names_` / selected columns. If a caller changes Filter/Select and seeks back to a previously-read chunk, the cache can return a table produced with the old options, which is a behavior regression versus reloading. Please either (a) include the effective filter/projection in the cache key, or (b) clear/invalidate `chunk_cache_` (and `chunk_table_`) whenever Filter/Select options change.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@graphar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@graphar.apache.org
For additional commands, e-mail: commits-help@graphar.apache.org


Re: [PR] feat(c++): add LRU chunk cache to Arrow chunk readers to avoid redundandt file IO [incubator-graphar]

Posted by "SYaoJun (via GitHub)" <gi...@apache.org>.
SYaoJun commented on PR #861:
URL: https://github.com/apache/incubator-graphar/pull/861#issuecomment-3984517435

   ## Added LRU Cache 
   
   [benchmark](https://github.com/apache/incubator-graphar/actions/runs/22577682031/job/65401070442?pr=861)
   
   ## Summary
   
   After adding the cache, the initialization and creation times have increased. Since filtering and selection operations affect the cache, we currently invalidate all caches aggressively. This has caused performance regressions in filter operations.
   I believe this issue requires a more careful design—there is still significant room for substantial improvement.
   
   
   ### Performance Improvements
   | Benchmark | Before (ns) | After (ns) | Improvement |
   |-----------|-------------|------------|-------------|
   | AdjListPropertyArrowChunkReaderReadChunk | 166224 | 3927 | 42.33x |
   | AdjListArrowChunkReaderReadChunk | 152848 | 6095 | 25.08x |
   | AdjListOffsetArrowChunkReaderReadChunk | 136690 | 3808 | 35.90x |
   | VertexPropertyArrowChunkReaderReadChunk_firstGraph_AllColumns_V1 | 189591 | 10307 | 18.39x |
   | VertexPropertyArrowChunkReaderReadChunk_firstGraph_TwoColumns_V1 | 201011 | 7756 | 25.92x |
   | VertexPropertyArrowChunkReaderReadChunk_firstGraph_OneColumns_V1 | 179371 | 6139 | 29.22x |
   | VertexPropertyArrowChunkReaderReadChunk_firstGraph_AllColumns_V2 | 133497 | 9883 | 13.51x |
   | VertexPropertyArrowChunkReaderReadChunk_firstGraph_TwoColumns_V2 | 108899 | 7876 | 13.83x |
   | VertexPropertyArrowChunkReaderReadChunk_firstGraph_OneColumns_V2 | 82066 | 5830 | 14.08x |
   | VertexPropertyArrowChunkReaderReadChunk_secondGraph_AllColumns_V1 | 396302 | 10402 | 38.10x |
   | VertexPropertyArrowChunkReaderReadChunk_secondGraph_TwoColumns_V1 | 301181 | 8218 | 36.65x |
   | VertexPropertyArrowChunkReaderReadChunk_secondGraph_OneColumns_V1 | 191486 | 5875 | 32.59x |
   | VertexPropertyArrowChunkReaderReadChunk_secondGraph_AllColumns_V2 | 775914 | 9723 | 79.80x |
   | VertexPropertyArrowChunkReaderReadChunk_secondGraph_TwoColumns_V2 | 462362 | 8328 | 55.52x |
   | VertexPropertyArrowChunkReaderReadChunk_secondGraph_OneColumns_V2 | 188513 | 5899 | 31.96x |
   ### Minor Performance Changes
   | Benchmark | Before (ns) | After (ns) | Ratio |
   |-----------|-------------|------------|-------|
   | CreateAdjListArrowChunkReader | 3577 | 38150 | 0.09x |
   | CreateAdjListOffsetArrowChunkReader | 3550 | 38338 | 0.09x |
   ### Performance Regressions
   | Benchmark | Before (ns) | After (ns) | Regression |
   |-----------|-------------|------------|------------|
   | InitialGraphInfo | 202816 | 1824996 | 0.11x |
   | CreateVertexPropertyArrowChunkReader | 6965 | 79185 | 0.09x |
   | SingleLabelFilter | 111611 | 1710060 | 0.07x |
   | SingleLabelFilterbyAcero | 658114 | 2487584 | 0.26x |
   | MultiLabelFilter | 92712 | 1271051 | 0.07x |
   | MultiLabelFilterbyAcero | 465075 | 1909993 | 0.24x |
   | LabelFilterFromSet | 48985 | 824111 | 0.06x |
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@graphar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@graphar.apache.org
For additional commands, e-mail: commits-help@graphar.apache.org


Re: [PR] feat(c++): add LRU chunk cache to Arrow chunk readers to avoid redundandt file IO [incubator-graphar]

Posted by "SYaoJun (via GitHub)" <gi...@apache.org>.
SYaoJun commented on PR #861:
URL: https://github.com/apache/incubator-graphar/pull/861#issuecomment-3995805332

   > I don't think the existing benchmarks can be used to reflect performance changes. For example, `AdjListPropertyArrowChunkReaderReadChunk` creates a reader and uses this reader to read `chunk0` and `chunk1` multiple times, which will cause all data to be hit in the cache. A better way is to create a separate benchmark file and test the chunksize as 0/1/n respectively.
   
   Ok, I also want to add intensive benchmarks. LRU cache affect the whole projects. No rush. After added benchmarks, then go next


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@graphar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@graphar.apache.org
For additional commands, e-mail: commits-help@graphar.apache.org


Re: [PR] feat(c++): add LRU chunk cache to Arrow chunk readers to avoid redundandt file IO [incubator-graphar]

Posted by "codecov-commenter (via GitHub)" <gi...@apache.org>.
codecov-commenter commented on PR #861:
URL: https://github.com/apache/incubator-graphar/pull/861#issuecomment-3900431465

   ## [Codecov](https://app.codecov.io/gh/apache/incubator-graphar/pull/861?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
   :white_check_mark: All modified and coverable lines are covered by tests.
   :white_check_mark: Project coverage is 80.22%. Comparing base ([`02bd3fe`](https://app.codecov.io/gh/apache/incubator-graphar/commit/02bd3fe10a72436f21cf1da889172159273ae224?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)) to head ([`d41751a`](https://app.codecov.io/gh/apache/incubator-graphar/commit/d41751a6f7f3cdef3ee69e98b2daf962e69adbbe?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)).
   :warning: Report is 1 commits behind head on main.
   
   <details><summary>Additional details and impacted files</summary>
   
   
   
   ```diff
   @@            Coverage Diff            @@
   ##               main     #861   +/-   ##
   =========================================
     Coverage     80.21%   80.22%           
     Complexity      615      615           
   =========================================
     Files            93       93           
     Lines         10257    10239   -18     
     Branches       1049     1047    -2     
   =========================================
   - Hits           8228     8214   -14     
   + Misses         1789     1785    -4     
     Partials        240      240           
   ```
   </details>
   
   [:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/apache/incubator-graphar/pull/861?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).   
   :loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
   <details><summary> :rocket: New features to boost your workflow: </summary>
   
   - :snowflake: [Test Analytics](https://docs.codecov.com/docs/test-analytics): Detect flaky tests, report on failures, and find test suite problems.
   </details>


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@graphar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@graphar.apache.org
For additional commands, e-mail: commits-help@graphar.apache.org


Re: [PR] feat(c++): add LRU chunk cache to Arrow chunk readers to avoid redundandt file IO [incubator-graphar]

Posted by "SYaoJun (via GitHub)" <gi...@apache.org>.
SYaoJun commented on code in PR #861:
URL: https://github.com/apache/incubator-graphar/pull/861#discussion_r2867481339


##########
cpp/src/graphar/arrow/chunk_reader.cc:
##########
@@ -260,6 +259,7 @@ VertexPropertyArrowChunkReader::GetChunkV2() {
       GAR_RETURN_NOT_OK(
           CastTableWithSchema(chunk_table_, schema_, &chunk_table_));
     }
+    chunk_cache_.Put(chunk_index_, chunk_table_);
   }

Review Comment:
   accepted



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@graphar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@graphar.apache.org
For additional commands, e-mail: commits-help@graphar.apache.org


Re: [PR] feat(c++): add LRU chunk cache to Arrow chunk readers to avoid redundandt file IO [incubator-graphar]

Posted by "SYaoJun (via GitHub)" <gi...@apache.org>.
SYaoJun commented on code in PR #861:
URL: https://github.com/apache/incubator-graphar/pull/861#discussion_r2870539337


##########
cpp/src/graphar/arrow/chunk_reader.h:
##########
@@ -267,6 +268,7 @@ class VertexPropertyArrowChunkReader {
   IdType vertex_num_;
   std::shared_ptr<arrow::Schema> schema_;
   std::shared_ptr<arrow::Table> chunk_table_;
+  LRUCache<IdType, std::shared_ptr<arrow::Table>> chunk_cache_{4};

Review Comment:
   > chunk_cache **size** can judge based on memory or let the user control it will be better?
   
   Actually, I don't know which place is suitable for keep this parameters(`size`). Do you have any suggestions?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@graphar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@graphar.apache.org
For additional commands, e-mail: commits-help@graphar.apache.org


Re: [PR] feat(c++): add LRU chunk cache to Arrow chunk readers to avoid redundandt file IO [incubator-graphar]

Posted by "SYaoJun (via GitHub)" <gi...@apache.org>.
SYaoJun commented on code in PR #861:
URL: https://github.com/apache/incubator-graphar/pull/861#discussion_r2867476542


##########
cpp/src/graphar/lru_cache.h:
##########
@@ -0,0 +1,86 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#pragma once
+
+#include <cstddef>
+#include <list>
+#include <unordered_map>
+#include <utility>
+
+namespace graphar {
+
+template <typename Key, typename Value, typename Hash = std::hash<Key>>
+class LRUCache {
+ public:

Review Comment:
   added



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@graphar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@graphar.apache.org
For additional commands, e-mail: commits-help@graphar.apache.org


Re: [PR] feat(c++): add LRU chunk cache to Arrow chunk readers to avoid redundandt file IO [incubator-graphar]

Posted by "SYaoJun (via GitHub)" <gi...@apache.org>.
SYaoJun commented on code in PR #861:
URL: https://github.com/apache/incubator-graphar/pull/861#discussion_r2872401272


##########
cpp/src/graphar/arrow/chunk_reader.cc:
##########
@@ -352,17 +354,22 @@ Status VertexPropertyArrowChunkReader::next_chunk() {
         vertex_info_->GetType(), " chunk num ", chunk_num_);
   }
   seek_id_ = chunk_index_ * vertex_info_->GetChunkSize();
-  chunk_table_.reset();
+  auto* cached = chunk_cache_.Get(chunk_index_);
+  chunk_table_ = cached ? *cached : nullptr;
 
   return Status::OK();
 }
 
 void VertexPropertyArrowChunkReader::Filter(util::Filter filter) {
   filter_options_.filter = filter;
+  chunk_table_ = nullptr;
+  chunk_cache_.Clear();
 }
 
 void VertexPropertyArrowChunkReader::Select(util::ColumnNames column_names) {
   filter_options_.columns = column_names;
+  chunk_table_ = nullptr;

Review Comment:
   Same as above.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@graphar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@graphar.apache.org
For additional commands, e-mail: commits-help@graphar.apache.org


Re: [PR] feat(c++): add LRU chunk cache to Arrow chunk readers to avoid redundandt file IO [incubator-graphar]

Posted by "SYaoJun (via GitHub)" <gi...@apache.org>.
SYaoJun commented on PR #861:
URL: https://github.com/apache/incubator-graphar/pull/861#issuecomment-3987885814

   I have updated the benchmark above. The filter performance has degraded slightly, but I think it is acceptable for the first version. I will continue optimizing it over the next few days.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@graphar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@graphar.apache.org
For additional commands, e-mail: commits-help@graphar.apache.org