Skip to content

Small FlatMap optimization with default initialization#2620

Merged
wwbmmm merged 2 commits into
apache:masterfrom
chenBright:opt_flat_map
Dec 9, 2024
Merged

Small FlatMap optimization with default initialization#2620
wwbmmm merged 2 commits into
apache:masterfrom
chenBright:opt_flat_map

Conversation

@chenBright

@chenBright chenBright commented Apr 27, 2024

Copy link
Copy Markdown
Contributor

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

javeme commented May 22, 2024

Copy link
Copy Markdown

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

@chenBright

Copy link
Copy Markdown
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 9 times, most recently from 410b67c to 0426dc9 Compare June 24, 2024 03:56
@chenBright chenBright force-pushed the opt_flat_map branch 2 times, most recently from 96841c6 to 3ac6e31 Compare August 3, 2024 17:35
@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
Copy Markdown
Contributor Author

@wwbmmm 有空看看

@wwbmmm

wwbmmm commented Nov 3, 2024

Copy link
Copy Markdown
Contributor

对FlatMap的性能有影响吗?

@chenBright

Copy link
Copy Markdown
Contributor Author

对FlatMap的性能有影响吗?

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

@wwbmmm

wwbmmm commented Nov 4, 2024

Copy link
Copy Markdown
Contributor

LGTM

@wwbmmm wwbmmm merged commit 53026cd into apache:master Dec 9, 2024
@chenBright chenBright deleted the opt_flat_map branch December 9, 2024 02:18
@chenBright

Copy link
Copy Markdown
Contributor Author

@javeme cc

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