platoneko commented on code in PR #13993:
URL: https://github.com/apache/doris/pull/13993#discussion_r1015506921


##########
be/src/olap/rowset/rowset_meta.h:
##########
@@ -53,12 +53,14 @@ class RowsetMeta {
     }
 
     virtual bool init_from_pb(const RowsetMetaPB& rowset_meta_pb) {
-        _rowset_meta_pb = rowset_meta_pb;
-        if (_rowset_meta_pb.has_tablet_schema()) {
+        if (rowset_meta_pb.has_tablet_schema()) {
             _schema = TabletSchemaCache::instance()->insert(
-                    _rowset_meta_pb.tablet_schema().SerializeAsString());
-            _rowset_meta_pb.clear_tablet_schema();
+                    rowset_meta_pb.tablet_schema().SerializeAsString());
         }
+        auto& mut_rowset_meta_pb = const_cast<RowsetMetaPB&>(rowset_meta_pb);

Review Comment:
   This is a trick to reduce unnecessary memory allocation and release 
overhead. A common solution to release TabletSchemaPB memory is:
   ```c++
   _rowset_meta_pb = rowset_meta_pb;
   _rowset_meta_pb.set_allocated_tablet_schema(nullptr); // release 
TabletSchemaPB
   ```
   However, here we copy TabletSchemaPB from `rowset_meta_pb` to 
`_rowset_meta_pb` but release it right away.
   Another more efficient way: release ownership of TabletSchemaPB from 
`rowset_meta_pb` and then set it back to `rowset_meta_pb`, this won't break 
const semantics of `rowset_meta_pb`, because `rowset_meta_pb` is not changed 
before and after call this method.
   



-- 
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