-
-
Notifications
You must be signed in to change notification settings - Fork 233
优化popup组件 #538
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
Closed
Closed
优化popup组件 #538
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这些逻辑可能没有必要,Portal 里已经对 forceRender 做了处理。如果是非 open 且没有 forceRender 是不会渲染的
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
我用修改前和修改后代码,跑了一下一次性创建2w个trigger,上面是用时对比,分别做了三次对比
看到Portal里面也有
React.cloneElement
这个操作There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
所以损耗比较多的是来自 cloneElement 的代码是吧?感谢调试,我想想怎么链路上去优化一下,Portal 本身应该是让人无脑用的,如果上游还要优化就不是封装 Portal 的目的了
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
我拉了一下火焰图(禁用 React Dev Tools),cloneElement 是少于 createElement 的:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
从 createElement 上看,rc-trigger 的 TriggerWrapper 可以省略,但是需要把所有依赖动态 ref 的组件的
getTriggerDOMNode
给收掉。我看看是否可以实现There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
另外还有一点,React 的 dev 和 prod 的对 ReactElement 性能损耗是不一样的。createElement 的慢在于 dev 下会做额外的注入:
而 prod 则不会:
所以对于
createElement
orcloneElement
的优化主要是提升了 dev 下的体验。There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
其实 createElement是必要操作,也不需要关心他们两个谁的效率更高
我的观点是,代码中尽可能的少用不用cloneElement代码,正如你说的TriggerWrapper中的cloneElement可以和外面的cloneElement操作合并成一次
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
假设完成许许多多的性能优化,lim性能趋向于正无穷=
<></>
在大批量的渲染面前,渲染100万个
<></>
和渲染100万个null
肯定也是前者耗时长所以
const childNode =(open && (typeof popup === 'function' ? popup() : popup)) || null;
这行代码的存在是非常有必要的There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
嗯,v6 里不需要 findDOMNode,先干掉一个 #539
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#540 我调了一下,在更外层来处理把 Popup 和 ContextProvider 也省一下,帮我 CR 一下