mrhhsg commented on code in PR #10386:
URL: https://github.com/apache/doris/pull/10386#discussion_r905877588


##########
be/src/olap/rowset/segment_v2/segment_iterator.cpp:
##########
@@ -872,9 +872,11 @@ Status SegmentIterator::_read_columns_by_index(uint32_t 
nrows_read_limit, uint32
                 _read_columns(_first_read_column_ids, _current_return_columns, 
rows_to_read));
         _cur_rowid += rows_to_read;
         if (set_block_rowid) {
-            for (uint32_t rid = range_from; rid < range_to; rid++) {
-                _block_rowids[nrows_read++] = rid;
-            }
+            // Here use std::iota is better performance than for-loop, maybe 
for-loop is not vectorized

Review Comment:
   I tested with the code below(compile command: ` g++ test.cc -O3 
-fopt-info-vec-all`:
   1. `nrows_read` as reference:
   ```c++
   #include <string>
   #include <vector>
   
   std::vector<uint32_t> _block_rowids;
   
   void func(uint32_t range_from, uint32_t range_to, uint32_t& nrows_read) {
       uint32_t* data = _block_rowids.data();
       for (uint32_t rid = range_from; rid < range_to; rid++) {
           data[nrows_read++] = rid;
       }
   }
   
   int main(int argc, char* argv[]) {
       uint32_t nrows_read = 0;
       _block_rowids.resize(4096);
       func(100, 2000, nrows_read);
       return 0;
   }
   ```
   got:
   <img width="1223" alt="image" 
src="https://user-images.githubusercontent.com/1179834/175503549-988a66e8-1ebc-42bc-a4bc-2e241ad165ee.png";>
   
   2. `nrows_read` as value and signed.
   ```c++
   #include <string>
   #include <vector>
   
   std::vector<uint32_t> _block_rowids;
   
   void func(uint32_t range_from, uint32_t range_to, int32_t nrows_read) {
       uint32_t* data = _block_rowids.data();
       for (uint32_t rid = range_from; rid < range_to; rid++) {
           data[nrows_read++] = rid;
       }
   }
   
   int main(int argc, char* argv[]) {
       uint32_t nrows_read = 0;
       _block_rowids.resize(4096);
       func(100, 2000, nrows_read);
       return 0;
   }
   ```
   <img width="1220" alt="image" 
src="https://user-images.githubusercontent.com/1179834/175503955-171ece10-0d2c-4d66-b7c6-5ab0e0fb012d.png";>
   



-- 
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-unsubscr...@doris.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to