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

reference-profiler-translate #280

Merged
merged 8 commits into from
Sep 10, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 43 additions & 43 deletions content/docs/reference-profiler.md
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
---
id: profiler
title: Profiler API
title: API Profiler
layout: docs
category: Reference
permalink: docs/profiler.html
---

The `Profiler` measures how often a React application renders and what the "cost" of rendering is.
Its purpose is to help identify parts of an application that are slow and may benefit from [optimizations such as memoization](https://reactjs.org/docs/hooks-faq.html#how-to-memoize-calculations).
El `Profiler` (perfilador o generador de perfiles) mide con qué frecuencia se renderiza una aplicación React y cuál es el "costo" del renderizado.
Su propósito es ayudar a identificar partes de una aplicación que son lentas y pueden beneficiarse de [optimizaciones como la memoización](https://reactjs.org/docs/hooks-faq.html#how-to-memoize-calculations).

> Note:
> Nota:
>
> Profiling adds some additional overhead, so **it is disabled in [the production build](https://reactjs.org/docs/optimizing-performance.html#use-the-production-build)**.
> La creación de perfiles agrega una sobrecarga adicional, por lo que **está deshabilitada en [la compilación de producción](https://reactjs.org/docs/optimizing-performance.html#use-the-production-build)**.
>
> To opt into production profiling, React provides a special production build with profiling enabled.
> Read more about how to use this build at [fb.me/react-profiling](https://fb.me/react-profiling)
> Para acceder al análisis de rendimiento en producción, React proporciona una compilación de producción especial con la generación de perfiles habilitada.
> Lea más sobre cómo usar esta compilación en [fb.me/react-profiling](https://fb.me/react-profiling)

## Usage
## Uso

A `Profiler` can be added anywhere in a React tree to measure the cost of rendering that part of the tree.
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.
Se puede agregar un `Profiler` en cualquier parte de un árbol React para medir el costo de renderizar esa parte del árbol.
Requiere dos props: un `id` (string) y un callback `onRender` (función) que React llama cada vez que un componente dentro del árbol "confirma" una actualización.

For example, to profile a `Navigation` component and its descendants:
Por ejemplo, para perfilar un componente `Navigation` y sus descendientes:

```js{3}
render(
Expand All @@ -34,7 +34,7 @@ render(
);
```

Multiple `Profiler` components can be used to measure different parts of an application:
Se pueden usar múltiples componentes `Profiler` para medir diferentes partes de una aplicación:
```js{3,6}
render(
<App>
Expand All @@ -48,7 +48,7 @@ render(
);
```

`Profiler` components can also be nested to measure different components within the same subtree:
Los componentes `Profiler` también se pueden anidar para medir diferentes componentes dentro del mismo subárbol:
```js{2,6,8}
render(
<App>
Expand All @@ -66,54 +66,54 @@ render(
);
```

> Note
> Nota
>
> Although `Profiler` is a light-weight component, it should be used only when necessary; each use adds some CPU and memory overhead to an application.
> Aunque `Profiler` es un componente liviano, debe usarse solo cuando sea necesario; cada uso agrega algo de sobrecarga de CPU y memoria a una aplicación.

## `onRender` Callback
## Callback `onRender`

The `Profiler` requires an `onRender` function as a prop.
React calls this function any time a component within the profiled tree "commits" an update.
It receives parameters describing what was rendered and how long it took.
El `Profiler` requiere una función `onRender` como una prop.
React llama a esta función cada vez que un componente dentro del árbol perfilado "confirma" una actualización.
Recibe parámetros que describen lo que se procesó y cuánto tiempo tardó.

```js
function onRenderCallback(
id, // the "id" prop of the Profiler tree that has just committed
phase, // either "mount" (if the tree just mounted) or "update" (if it re-rendered)
actualDuration, // time spent rendering the committed update
baseDuration, // estimated time to render the entire subtree without memoization
startTime, // when React began rendering this update
commitTime, // when React committed this update
interactions // the Set of interactions belonging to this update
id, // la prop "id" del árbol Profiler que acaba de ser "confirmado"
phase, // ya sea "mount" (si el árbol acaba de ser montado) o "update" (si se volvió a renderizar)
actualDuration, // tiempo dedicado a procesar la actualización confirmada
baseDuration, // tiempo estimado para renderizar todo el subárbol sin memoización
startTime, // cuando React comenzó a procesar esta actualización
commitTime, // cuando React confirmó esta actualización
interactions // el conjunto de interacciones pertenecientes a esta actualización
) {
// Aggregate or log render timings...
// Agregar o registrar tiempos de renderizado ...
}
```

Let's take a closer look at each of the props:
Echemos un vistazo más de cerca a cada uno de las props:

* **`id: string`** -
The `id` prop of the `Profiler` tree that has just committed.
This can be used to identify which part of the tree was committed if you are using multiple profilers.
La prop `id` del árbol` Profiler` que acaba de ser confirmado.
Esto se puede usar para identificar qué parte del árbol se confirmó si está utilizando varios perfiladores.
* **`phase: "mount" | "update"`** -
Identifies whether the tree has just been mounted for the first time or re-rendered due to a change in props, state, or hooks.
Identifica si el árbol se acaba de montar por primera vez o se vuelve a renderizar debido a un cambio en las props, el estado o los hooks.
* **`actualDuration: number`** -
Time spent rendering the `Profiler` and its descendants for the current update.
This indicates how well the subtree makes use of memoization (e.g. [`React.memo`](/docs/react-api.html#reactmemo), [`useMemo`](/docs/hooks-reference.html#usememo), [`shouldComponentUpdate`](/docs/hooks-faq.html#how-do-i-implement-shouldcomponentupdate)).
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.
Tiempo dedicado a renderizar el `Profiler` y sus descendientes para la actualización actual.
Esto indica qué tan bien el subárbol utiliza la memoización. (e.g. [`React.memo`](/docs/react-api.html#reactmemo), [`useMemo`](/docs/hooks-reference.html#usememo), [`shouldComponentUpdate`](/docs/hooks-faq.html#how-do-i-implement-shouldcomponentupdate)).
Idealmente, este valor debería disminuir significativamente después del montaje inicial, ya que muchos de los descendientes solo necesitarán volver a renderizar si cambian sus props específicas.
* **`baseDuration: number`** -
Duration of the most recent `render` time for each individual component within the `Profiler` tree.
This value estimates a worst-case cost of rendering (e.g. the initial mount or a tree with no memoization).
Duración del tiempo de renderizado más reciente para cada componente individual dentro del árbol de `Profiler`.
Este valor estima el costo de renderizado en el peor de los casos (por ejemplo, el montaje inicial o un árbol sin memoización).
* **`startTime: number`** -
Timestamp when React began rendering the current update.
Marca de tiempo cuando React comenzó a procesar la actualización actual.
* **`commitTime: number`** -
Timestamp when React committed the current update.
This value is shared between all profilers in a commit, enabling them to be grouped if desirable.
Marca de tiempo cuando React confirmó la actualización actual.
Este valor se comparte entre todos los perfiladores en una confirmación, lo que les permite agruparse si lo desean.
* **`interactions: Set`** -
Set of ["interactions"](http://fb.me/react-interaction-tracing) that were being traced the update was scheduled (e.g. when `render` or `setState` were called).
Conjunto de ["interacciones"](http://fb.me/react-interaction-tracing) que se estaban rastreando, la actualización estaba programada (por ejemplo, cuando se llamó a `render` o` setState`).

> Note
> Nota
>
> Interactions can be used to identify the cause of an update, although the API for tracing them is still experimental.
> Las interacciones se pueden usar para identificar la causa de una actualización, aunque la API para rastrearlas aún es experimental.
>
> Learn more about it at [fb.me/react-interaction-tracing](http://fb.me/react-interaction-tracing)
> Obtenga más información al respecto en [fb.me/react-interaction-tracing](http://fb.me/react-interaction-tracing)