> For AI agents: the complete documentation index is available at /next/zh/llms.txt, the full documentation bundle is available at /next/zh/llms-full.txt.

# deprecated MetricFcpEntry

:::warning
该事件在 Lynx SDK 3.7 版本已废弃，相关数据可从 [`LoadBundleEntry`](/next/zh/api/lynx-api/performance-api/performance-entry/load-bundle-entry.md) / [`ReloadBundleEntry`](/next/zh/api/lynx-api/performance-api/performance-entry/reload-bundle-entry.md) 中获取.
:::

APISummary
FCP 是衡量页面首次渲染完成所需时间的关键性能指标。它指的是用户第一次看到 Lynx 页面中任意内容（如文本、图片等）所需的时间。`MetricFcpEntry` 是用于描述该指标的数据类型，继承自 [`PerformanceEntry`](/next/zh/api/lynx-api/performance-api/performance-entry.md)。

FCP 事件在 Lynx 绘制完页面第一帧时触发。对于依赖网络请求或异步 IO 获取数据的页面，FCP 通常监测到的状态是 Loading 页或框架图，如下图：

![](https://lf-lynx.tiktok-cdns.com/obj/lynx-artifacts-oss-sg/lynx-website/assets/doc/performance-metrics-fcp.png)
根据不同起始点，Lynx 提供了 `fcp`、`lynxFcp`、`totalFcp` 三个指标。在渲染流程中，每个指标的定义如下图：

![](https://lf-lynx.tiktok-cdns.com/obj/lynx-artifacts-oss-sg/lynx-website/assets/doc/metric-fcp-entry.png)
## 示例

该示例展示了如何获取 `MetricFcpEntry`。

Lynx 在首帧渲染完成时计算 FCP。如果已经通过 [LynxView.setExtraTiming](/next/zh/api/lynx-native-api/lynx-view/set-extra-timing.md) 提供了[容器](/next/zh/guide/spec.md#container)时间戳，那么收到的 `MetricFcpEntry` 里会包含 `fcp`、`lynxFcp` 和 `totalFcp` 三项指标。否则，`MetricFcpEntry` 只包含 `lynxFcp`。补充容器时间戳后，其余指标将被重新计算。重新计算完成后，Lynx 将发送一个新的包含所有指标的 `MetricFcpEntry`。

**下面是一个示例: performance-api**

**Entry:** `src/fcp-entry`
**Bundle:** `dist/fcp-entry.lynx.bundle`

```tsx {10-20}
import * as React from "@lynx-js/react";
import { root, useMemo, useState } from "@lynx-js/react";
import type { MetricFcpEntry, PerformanceEntry } from "@lynx-js/types";
import "./index.scss";

export default function MetricFcpEntryExample(this: any) {
  const [fcpEntry, setFcpEntry] = useState<string>("");

  useMemo(() => {
    "background-only";
    // 1. Create a performance observer.
    const observer = lynx.performance.createObserver((entry: PerformanceEntry) => {
      if (entry.entryType == "metric" && entry.name == "fcp") {
        // 3. Received "metric.fcp" event.
        const fcpEntry = entry as MetricFcpEntry;
        setFcpEntry(JSON.stringify(fcpEntry, null, 4));
      }
    });
    // 2. Register to listen to the "metric.fcp" event.
    observer.observe(["metric.fcp"]);
  }, []);

  return (
    <view className="container">
      <text className="title">Hello MetricFcpEntry~</text>
      <text className="entry">{fcpEntry}</text>
    </view>
  );
}

root.render(<MetricFcpEntryExample />);

if (import.meta.webpackHot) {
  import.meta.webpackHot.accept();
}

```

v0.8.0



## 实例属性

### [entryType](/next/zh/api/lynx-api/performance-api/performance-entry.md#entrytype)

```ts
entryType: string;
```

性能事件的类型，当前类所有实例的值均固定为 `metric`。

### [name](/next/zh/api/lynx-api/performance-api/performance-entry.md#name)

```ts
name: string;
```

性能事件的具体名称，当前类所有实例的值均固定为 `fcp`。

### fcp

```ts
fcp?: PerformanceMetric;
```

从准备 [TemplateBundle](/next/zh/api/lynx-native-api/template-bundle.md) 至首次渲染完成的耗时，数据类型为 [`PerformanceMetric`](/next/zh/api/lynx-api/performance-api/performance-metric.md)。

计算公式为：`fcp = LoadBundleEntry.paintEnd - InitContainerEntry.prepareTemplateStart`。

### lynxFcp

```ts
lynxFcp: PerformanceMetric;
```

从加载 [TemplateBundle](/next/zh/api/lynx-native-api/template-bundle.md) 至首次渲染完成的耗时，数据类型为 [`PerformanceMetric`](/next/zh/api/lynx-api/performance-api/performance-metric.md)。

计算公式为：`lynxFcp = LoadBundleEntry.paintEnd - LoadBundleEntry.loadBundleStart`。

### totalFcp

```ts
totalFcp?: PerformanceMetric;
```

从用户打开页面至首次渲染完成的耗时，数据类型为 [`PerformanceMetric`](/next/zh/api/lynx-api/performance-api/performance-metric.md)。

计算公式为：`totalFcp = LoadBundleEntry.paintEnd - InitContainerEntry.openTime`。

## 兼容性

**Compatibility Table**

**Query:** `lynx-api.performance-api.performance-entry.metric-fcp-entry`

[Source](https://github.com/lynx-family/lynx-website/tree/main/packages/lynx-compat-data/lynx-api/performance-api/performance-entry/metric-fcp-entry.json)

| Feature | Android | HarmonyOS | iOS | macOS | Windows | Web |
| --- | --- | --- | --- | --- | --- | --- |
| metric-fcp-entry | Yes (3.1) | Yes (3.4) | Yes (3.1) | Yes (3.7) | Yes (3.7) | No |

