Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Small FlatMap optimization with default initialization #2620

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

chenBright
Copy link
Contributor

@chenBright chenBright commented Apr 27, 2024

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失败的顾虑。后续可以不用调init进行初始化,可以只在需要桶数比较大或者修改load factor才调init。即使init失败了,FlatMap还是可以正常使用的。

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 chenBright force-pushed the opt_flat_map branch 7 times, most recently from d95b54c to b59d76d Compare April 27, 2024 16:58
@chenBright chenBright marked this pull request as draft April 27, 2024 17:04
@chenBright chenBright closed this Apr 27, 2024
@chenBright chenBright reopened this Apr 27, 2024
@chenBright chenBright force-pushed the opt_flat_map branch 3 times, most recently from 2556087 to dcdf77f Compare April 27, 2024 17:27
@chenBright chenBright closed this Apr 27, 2024
@javeme
Copy link

javeme commented May 22, 2024

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

@chenBright
Copy link
Contributor Author

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

@chenBright chenBright reopened this Jun 23, 2024
@chenBright chenBright force-pushed the opt_flat_map branch 13 times, most recently from 62db1f9 to 34a1429 Compare June 23, 2024 18:36
@chenBright chenBright force-pushed the opt_flat_map branch 7 times, most recently from a3e0668 to 614f82e Compare November 1, 2024 15:51
@chenBright chenBright marked this pull request as ready for review November 2, 2024 06:32
@chenBright
Copy link
Contributor Author

@wwbmmm 有空看看

@wwbmmm
Copy link
Contributor

wwbmmm commented Nov 3, 2024

对FlatMap的性能有影响吗?

@chenBright
Copy link
Contributor Author

对FlatMap的性能有影响吗?

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

@wwbmmm
Copy link
Contributor

wwbmmm commented Nov 4, 2024

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants