Skip to content

Commit cad31ea

Browse files
GarlicGoYucohny
andauthored
docs(cn): translate reference/react/Profiler into Chinese (#1180)
Co-authored-by: Yucohny <[email protected]>
1 parent d495631 commit cad31ea

File tree

1 file changed

+28
-28
lines changed

1 file changed

+28
-28
lines changed

src/content/reference/react/Profiler.md

+28-28
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ title: <Profiler>
44

55
<Intro>
66

7-
`<Profiler>` lets you measure rendering performance of a React tree programmatically.
7+
`<Profiler>` 允许你编程式测量 React 树的渲染性能。
88

99
```js
1010
<Profiler id="App" onRender={onRender}>
@@ -18,55 +18,55 @@ title: <Profiler>
1818

1919
---
2020

21-
## Reference {/*reference*/}
21+
## 参考 {/*reference*/}
2222

2323
### `<Profiler>` {/*profiler*/}
2424

25-
Wrap a component tree in a `<Profiler>` to measure its rendering performance.
25+
使用 `<Profiler>` 包裹组件树,以测量其渲染性能。
2626

2727
```js
2828
<Profiler id="App" onRender={onRender}>
2929
<App />
3030
</Profiler>
3131
```
3232

33-
#### Props {/*props*/}
33+
#### 参数 {/*props*/}
3434

35-
* `id`: A string identifying the part of the UI you are measuring.
36-
* `onRender`: An [`onRender` callback](#onrender-callback) that React calls every time components within the profiled tree update. It receives information about what was rendered and how much time it took.
35+
* `id`:字符串,用于标识正在测量的 UI 部分。
36+
* `onRender`[`onRender` 回调函数](#onrender-callback),当 profiled 树中的组件更新时,React 都会调用它。它接收有关渲染内容和所花费时间的信息。
3737

38-
#### Caveats {/*caveats*/}
38+
#### 注意 {/*caveats*/}
3939

40-
* Profiling adds some additional overhead, so **it is disabled in the production build by default.** To opt into production profiling, you need to enable a [special production build with profiling enabled.](https://fb.me/react-profiling)
40+
* 进行性能分析会增加一些额外的开销,因此 **在默认情况下,它在生产环境中是被禁用的**。如果要启用生产环境下的性能分析,你需要启用一个 [特殊的带有性能分析功能的生产构建](https://fb.me/react-profiling)
4141

4242
---
4343

44-
### `onRender` callback {/*onrender-callback*/}
44+
### `onRender` 回调函数 {/*onrender-callback*/}
4545

46-
React will call your `onRender` callback with information about what was rendered.
46+
React 会使用渲染的相关信息调用你的 `onRender` 回调函数。
4747

4848
```js
4949
function onRender(id, phase, actualDuration, baseDuration, startTime, commitTime) {
50-
// Aggregate or log render timings...
50+
// 对渲染时间进行汇总或记录...
5151
}
5252
```
5353

54-
#### Parameters {/*onrender-parameters*/}
54+
#### 参数 {/*onrender-parameters*/}
5555

56-
* `id`: The string `id` prop of the `<Profiler>` tree that has just committed. This lets you identify which part of the tree was committed if you are using multiple profilers.
57-
* `phase`: `"mount"`, `"update"` or `"nested-update"`. This lets you know whether the tree has just been mounted for the first time or re-rendered due to a change in props, state, or hooks.
58-
* `actualDuration`: The number of milliseconds spent rendering the `<Profiler>` and its descendants for the current update. This indicates how well the subtree makes use of memoization (e.g. [`memo`](/reference/react/memo) and [`useMemo`](/reference/react/useMemo)). Ideally this value should decrease significantly after the initial mount as many of the descendants will only need to re-render if their specific props change.
59-
* `baseDuration`: The number of milliseconds estimating how much time it would take to re-render the entire `<Profiler>` subtree without any optimizations. It is calculated by summing up the most recent render durations of each component in the tree. This value estimates a worst-case cost of rendering (e.g. the initial mount or a tree with no memoization). Compare `actualDuration` against it to see if memoization is working.
60-
* `startTime`: A numeric timestamp for when React began rendering the current update.
61-
* `endTime`: A numeric timestamp for when React committed the current update. This value is shared between all profilers in a commit, enabling them to be grouped if desirable.
56+
* `id``<Profiler>` 树的字符串 `id` 属性,用于标识刚刚提交的部分。如果你使用多个 profiler,可以通过此属性识别已提交的树的哪个部分。
57+
* `phase``"mount"``"update"` `"nested-update"`。这可以让你知道树是首次挂载还是由于属性、状态或 hook 的更改而重新渲染。
58+
* `actualDuration`:当前更新期间用于渲染 `<Profiler>` 及其后代的时间,以毫秒为单位。显示子树在使用记忆化(例如 [`memo`](/reference/react/memo) [`useMemo`](/reference/react/useMemo))方面的效果如何。理想情况下,此值在初始挂载后应显著减少,因为许多后代组件只会在其特定的 props 变化时需要重新渲染。
59+
* `baseDuration`:估计在没有任何优化的情况下重新渲染整个 `<Profiler>` 子树所需的时间,以毫秒为单位。它通过累加树中每个组件的最近一次渲染持续时间来计算。此值估计了渲染的最差情况成本(例如初始挂载或没有记忆化的树)。与 `actualDuration` 进行比较,以确定记忆化是否起作用。
60+
* `startTime`:当 React 开始渲染当前更新时的时间戳。
61+
* `endTime`:当 React 提交当前更新时的时间戳。此值在提交的所有性能分析器之间共享,如果需要,可以对它们进行分组。
6262

6363
---
6464

65-
## Usage {/*usage*/}
65+
## 用法 {/*usage*/}
6666

67-
### Measuring rendering performance programmatically {/*measuring-rendering-performance-programmatically*/}
67+
### 编程式测量渲染性能 {/*measuring-rendering-performance-programmatically*/}
6868

69-
Wrap the `<Profiler>` component around a React tree to measure its rendering performance.
69+
使用 `<Profiler>` 组件包裹 React 树以测量其渲染性能。
7070

7171
```js {2,4}
7272
<App>
@@ -77,25 +77,25 @@ Wrap the `<Profiler>` component around a React tree to measure its rendering per
7777
</App>
7878
```
7979

80-
It requires two props: an `id` (string) and an `onRender` callback (function) which React calls any time a component within the tree "commits" an update.
80+
这需要两个属性:`id`(字符串)和 `onRender` 回调函数(函数),React 在树中的任何组件“提交”更新时调用该函数。
8181

8282
<Pitfall>
8383

84-
Profiling adds some additional overhead, so **it is disabled in the production build by default.** To opt into production profiling, you need to enable a [special production build with profiling enabled.](https://fb.me/react-profiling)
84+
进行性能分析会增加一些额外的开销,因此 **在默认情况下,它在生产环境中是被禁用的**。如果要启用生产环境下的性能分析,你需要启用一个 [特殊的带有性能分析功能的生产构建](https://fb.me/react-profiling)
8585

8686
</Pitfall>
8787

8888
<Note>
8989

90-
`<Profiler>` lets you gather measurements programmatically. If you're looking for an interactive profiler, try the Profiler tab in [React Developer Tools](/learn/react-developer-tools). It exposes similar functionality as a browser extension.
90+
`<Profiler>` 允许你编程式收集性能测量数据。如果你正在寻找一个交互式的性能分析工具,可以尝试使用 [React Developer Tools](/learn/react-developer-tools) 中的 Profiler 标签页。它提供了类似浏览器扩展的功能。
9191

9292
</Note>
9393

9494
---
9595

96-
### Measuring different parts of the application {/*measuring-different-parts-of-the-application*/}
96+
### 测量应用的不同部分 {/*measuring-different-parts-of-the-application*/}
9797

98-
You can use multiple `<Profiler>` components to measure different parts of your application:
98+
你可以使用多个 `<Profiler>` 组件来测量你的应用的不同部分:
9999

100100
```js {5,7}
101101
<App>
@@ -108,7 +108,7 @@ You can use multiple `<Profiler>` components to measure different parts of your
108108
</App>
109109
```
110110

111-
You can also nest `<Profiler>` components:
111+
你还可以嵌套 `<Profiler>` 组件:
112112

113113
```js {5,7,9,12}
114114
<App>
@@ -126,7 +126,7 @@ You can also nest `<Profiler>` components:
126126
</App>
127127
```
128128

129-
Although `<Profiler>` is a lightweight component, it should be used only when necessary. Each use adds some CPU and memory overhead to an application.
129+
虽然 `<Profiler>` 是一个轻量级组件,但它应该仅在必要时使用。每次使用都会给应用增加一些 CPU 和内存开销。
130130

131131
---
132132

0 commit comments

Comments
 (0)