基于泛型实现的B-Tree号称比用interface的快20%~30%

测试比较的是在B-Tree里面存放int类型数字这个非常特殊的场景。Google的实现中参数都是interface,因为int类型的数字要转成interface,且发生了逃逸。用泛型减少了数字分配到堆的消耗,同时减少了GC压力。

如果本身要存储的就是指针类的数据,相信不会有这么大的区别。

https://thenewstack.io/shaving-40-off-googles-b-tree-implementation-with-go-generics

posted @ 2022-08-19 15:51  Yii  阅读(27)  评论(0)    收藏  举报