brpc icon indicating copy to clipboard operation
brpc copied to clipboard

Small FlatMap optimization with default initialization

Open chenBright opened this issue 1 year ago • 2 comments

What problem does this PR solve?

Issue Number:

Problem Summary:

目前FlatMap是两阶段初始化:构造函数+init函数。这种初始化方式很容易用错,甚至出core,所以使用上必须小心翼翼,体验不好。

What is changed and the side effects?

Changed:

FlatMap构造完成即完成初始化。使用sso、IOBuf::SmallView的策略,初始化_buckets和_thumbnail使用类内的内存块,没有init函数中Alloc失败的顾虑。

Side effects:

  • Performance effects(性能影响):

  • Breaking backward compatibility(向后兼容性):


Check List:

  • Please make sure your changes are compilable(请确保你的更改可以通过编译).
  • When providing us with a new feature, it is best to add related tests(如果你向我们增加一个新的功能, 请添加相关测试).
  • Please follow Contributor Covenant Code of Conduct.(请遵循贡献者准则).

chenBright avatar Apr 27 '24 15:04 chenBright

Because the usage difference with std::map, FlatMap is unfriendly to use. I think this PR is a good improvement.

javeme avatar May 22 '24 13:05 javeme

There are some unknown crash issues. This PR will be opened after these issues are resolved.

chenBright avatar May 23 '24 03:05 chenBright

@wwbmmm 有空看看

chenBright avatar Nov 02 '24 06:11 chenBright

对FlatMap的性能有影响吗?

wwbmmm avatar Nov 03 '24 07:11 wwbmmm

对FlatMap的性能有影响吗?

没有影响。理论上来说,内联的内存块对cache更优化。

chenBright avatar Nov 03 '24 10:11 chenBright

LGTM

wwbmmm avatar Nov 04 '24 04:11 wwbmmm

@javeme cc

chenBright avatar Dec 09 '24 02:12 chenBright