You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@iotdb.apache.org by GitBox <gi...@apache.org> on 2021/07/14 09:29:58 UTC

[GitHub] [iotdb] limeng32 opened a new issue #3570: 提高枚举类检索的效率

limeng32 opened a new issue #3570:
URL: https://github.com/apache/iotdb/issues/3570


   大家好!
   
   我花了两星期阅读IoTDB的代码,整体水平非常高,受益匪浅。然而部分代码性能有较大提升空间,为了让IoTDB质量更上一层楼,冒昧的提一下。
   
   整个项目有几百行代码是做不同enum元数据之间的映射,而且查找的复杂度是O(n)。其实只要在枚举类中加一个HashMap就可以达到O(1)的性能,同时极大的减少代码,以tsfile模块的TSEncoding类为例:
   
   private static final Map<Byte, TSEncoding> map = new HashMap<>();
   
     static {
       TSEncoding[] array = TSEncoding.values();
       for (TSEncoding e : array) {
         map.put(e.type, e);
       }
     }
   
     private static TSEncoding getTsEncoding(byte encoding) {
       TSEncoding ret = map.get(encoding);
       if (ret == null) {
         throw new IllegalArgumentException("Invalid input: " + encoding);
       }
       return ret;
     }
   
   这样就完成了在枚举类TSEncoding中通过type检索TSEncoding的功能。如果是在两个枚举类之间相互检索,也可以用这种方式,定义不同的HashMap就行。
   
   我会把这个代码写成一个pr,望采纳。


-- 
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: reviews-unsubscribe@iotdb.apache.org

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



[GitHub] [iotdb] HTHou commented on issue #3570: 提高枚举类检索的效率

Posted by GitBox <gi...@apache.org>.
HTHou commented on issue #3570:
URL: https://github.com/apache/iotdb/issues/3570#issuecomment-880001388


   > 而且查找的复杂度是O(n)
   
   https://blog.csdn.net/weixin_28750379/article/details/114595592
   目前版本使用的switch 也不是O(n)吧。。。


-- 
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: reviews-unsubscribe@iotdb.apache.org

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



[GitHub] [iotdb] github-actions[bot] commented on issue #3570: 提高枚举类检索的效率

Posted by GitBox <gi...@apache.org>.
github-actions[bot] commented on issue #3570:
URL: https://github.com/apache/iotdb/issues/3570#issuecomment-879743252


   Hi, this is your first issue in IoTDB project. Thanks for your report. Welcome to join the community!


-- 
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: reviews-unsubscribe@iotdb.apache.org

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



[GitHub] [iotdb] limeng32 closed issue #3570: 提高枚举类检索的效率

Posted by GitBox <gi...@apache.org>.
limeng32 closed issue #3570:
URL: https://github.com/apache/iotdb/issues/3570


   


-- 
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: reviews-unsubscribe@iotdb.apache.org

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



[GitHub] [iotdb] limeng32 commented on issue #3570: 提高枚举类检索的效率

Posted by GitBox <gi...@apache.org>.
limeng32 commented on issue #3570:
URL: https://github.com/apache/iotdb/issues/3570#issuecomment-880385071


   受教了,我压测了,这个场景下确实是swith更快!


-- 
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: reviews-unsubscribe@iotdb.apache.org

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



[GitHub] [iotdb] HTHou edited a comment on issue #3570: 提高枚举类检索的效率

Posted by GitBox <gi...@apache.org>.
HTHou edited a comment on issue #3570:
URL: https://github.com/apache/iotdb/issues/3570#issuecomment-880001388


   > 而且查找的复杂度是O(n)
   
   https://blog.csdn.net/weixin_28750379/article/details/114595592
   https://blog.csdn.net/weixin_31188807/article/details/114711433
   
   目前版本使用的switch 也不是O(n)吧。。。


-- 
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: reviews-unsubscribe@iotdb.apache.org

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