gemini-code-assist[bot] commented on code in PR #18756:
URL: https://github.com/apache/tvm/pull/18756#discussion_r2794896399


##########
src/runtime/vm/executable.cc:
##########
@@ -274,23 +276,23 @@ void VMExecutable::SaveConstantSection(dmlc::Stream* 
strm) const {
     } else if (auto opt_shape = it.as<ffi::Shape>()) {
       ffi::Shape shape = opt_shape.value();
       strm->Write<int32_t>(ffi::TypeIndex::kTVMFFIShape);
-      strm->Write(shape.size());
+      strm->Write<uint64_t>(shape.size());
       for (size_t i = 0; i < shape.size(); ++i) {
-        strm->Write(shape.at(i));
+        strm->Write<int64_t>(shape.at(i));
       }

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   This loop to write shape elements one by one can be made more efficient. 
`dmlc::Stream` supports writing `std::vector` directly, which you can leverage 
here for a more concise and performant implementation.
   
   ```c
         strm->Write(shape->data);
   ```



##########
src/runtime/vm/executable.cc:
##########
@@ -274,23 +276,23 @@ void VMExecutable::SaveConstantSection(dmlc::Stream* 
strm) const {
     } else if (auto opt_shape = it.as<ffi::Shape>()) {
       ffi::Shape shape = opt_shape.value();
       strm->Write<int32_t>(ffi::TypeIndex::kTVMFFIShape);
-      strm->Write(shape.size());
+      strm->Write<uint64_t>(shape.size());
       for (size_t i = 0; i < shape.size(); ++i) {
-        strm->Write(shape.at(i));
+        strm->Write<int64_t>(shape.at(i));
       }
     } else if (auto opt_str = it.as<ffi::String>()) {
       ffi::String str = opt_str.value();
       strm->Write<int32_t>(ffi::TypeIndex::kTVMFFIStr);
-      strm->Write(str.size());
+      strm->Write<uint64_t>(str.size());
       for (size_t i = 0; i < str.size(); ++i) {
-        strm->Write(str.at(i));
+        strm->Write<uint8_t>(str.at(i));
       }

Review Comment:
   ![medium](https://www.gstatic.com/codereviewagent/medium-priority.svg)
   
   This loop for writing string characters individually is inefficient. Since 
`tvm::runtime::String` provides `data()` and `size()` methods, you can write 
the entire string content in a single operation.
   
   ```c
         strm->Write(str.data(), str.size());
   ```



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to