-
Notifications
You must be signed in to change notification settings - Fork 79
perf: cache effect (#218) #223
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| --- | ||
| title: First Render | ||
| nav: | ||
| title: Demo | ||
| path: /demo | ||
| --- | ||
|
|
||
| <code src="../examples/first-render.tsx"></code> |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,49 @@ | ||||||||||||||||||||||||||||||||
| import React from 'react'; | ||||||||||||||||||||||||||||||||
| import './basic.less'; | ||||||||||||||||||||||||||||||||
| import Button from './components/Button'; | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| const Demo = () => { | ||||||||||||||||||||||||||||||||
| const renderStart = React.useRef(Date.now()); | ||||||||||||||||||||||||||||||||
| const [renderTime, setRenderTime] = React.useState(0); | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| React.useEffect(() => { | ||||||||||||||||||||||||||||||||
| setRenderTime(Date.now() - renderStart.current); | ||||||||||||||||||||||||||||||||
| }, []); | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| return ( | ||||||||||||||||||||||||||||||||
| <> | ||||||||||||||||||||||||||||||||
| <p>Render Time: {renderTime}ms</p> | ||||||||||||||||||||||||||||||||
| {Array(10000) | ||||||||||||||||||||||||||||||||
| .fill(1) | ||||||||||||||||||||||||||||||||
| .map((_, key) => ( | ||||||||||||||||||||||||||||||||
| <div key={key}> | ||||||||||||||||||||||||||||||||
| <Button>Default</Button> | ||||||||||||||||||||||||||||||||
| <Button type="primary">Primary</Button> | ||||||||||||||||||||||||||||||||
| <Button type="ghost">Ghost</Button> | ||||||||||||||||||||||||||||||||
| <Button className="btn-override">Override By ClassName</Button> | ||||||||||||||||||||||||||||||||
| </div> | ||||||||||||||||||||||||||||||||
| ))} | ||||||||||||||||||||||||||||||||
| </> | ||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| export default function App() { | ||||||||||||||||||||||||||||||||
| const [show, setShow] = React.useState(false); | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| return ( | ||||||||||||||||||||||||||||||||
| <div style={{ background: 'rgba(0,0,0,0.1)', padding: 16 }}> | ||||||||||||||||||||||||||||||||
| <h3>默认情况下不会自动删除添加的样式</h3> | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| <label> | ||||||||||||||||||||||||||||||||
| <input type="checkbox" checked={show} onChange={() => setShow(!show)} /> | ||||||||||||||||||||||||||||||||
| Show Components | ||||||||||||||||||||||||||||||||
| </label> | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| {show && ( | ||||||||||||||||||||||||||||||||
| <div> | ||||||||||||||||||||||||||||||||
| <Demo /> | ||||||||||||||||||||||||||||||||
| </div> | ||||||||||||||||||||||||||||||||
| )} | ||||||||||||||||||||||||||||||||
| </div> | ||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
|
Comment on lines
+41
to
+49
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion 考虑添加更多上下文信息 当前示例缺乏与PR修改(缓存效果)的明确关联说明。建议添加解释文本,说明此示例如何展示缓存效果优化及其性能影响。 {show && (
<div>
+ <p>此示例展示了优化后的缓存效果如何提高大量样式组件的首次渲染性能。较低的渲染时间表明缓存效果改进有效。</p>
<Demo />
</div>
)}📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents (early access) |
||||||||||||||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.