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

# Mark Rendering Pipelines

[Lynx Pipeline](/next/guide/spec.md#lynx-pipeline) defines the complete process from triggering the rendering to displaying it on the screen. If you care about rendering performance of certain key components, you can set the component’s `__lynx_timing_flag` property to mark its Lynx Pipeline and monitor its performance.

When the flagged Lynx Pipeline finishes and the screen is refreshed, a [`PipelineEntry`](/next/api/lynx-api/performance-api/performance-entry/pipeline-entry.md) performance event is generated. You can obtain it via [`PerformanceObserver`](/next/api/lynx-api/performance-api/performance-observer.md).

## Usage rules

- The `__lynx_timing_flag` attribute must be a non-empty string. Empty values or invalid types will not trigger [`PerformanceObserver`](/next/api/lynx-api/performance-api/performance-observer.md) callbacks.
- When the `__lynx_timing_flag` attribute value is `__lynx_timing_actual_fmp`, an additional [`MetricActualFmpEntry`](/next/api/lynx-api/performance-api/performance-entry/metric-actual-fmp-entry.md) performance event is generated.

## Examples

1. Mark a node: set the `__lynx_timing_flag` attribute on the target component. When the node finishes rendering, the framework automatically collects performance data for its Lynx Pipeline.
2. Get data: register an observer (`PerformanceObserver`) via [`lynx.performance.createObserver()`](/next/api/lynx-api/lynx/lynx-performance/create-observer.md) to receive the corresponding performance data (`PipelineEntry`).

**This is an example below: performance-api**

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

```tsx {11-21,34}
import { root, useEffect, useState } from "@lynx-js/react";
import type { PerformanceEntry, PipelineEntry } from "@lynx-js/types";
import { ScrollItem } from "../common/scroll-item/index.jsx";
import "./index.scss";

export default function PipelineEntryExample() {
  const [pipelineEntry, setPipelineEntry] = useState("");
  const [myName, setMyName] = useState<string | undefined>(undefined);

  useEffect(() => {
    "background-only";
    // 1. Create a performance observer.
    const observer = lynx.performance.createObserver((entry: PerformanceEntry) => {
      if (entry.entryType == "pipeline") {
        // 3. Received "pipeline" event of "myPipeline".
        const pipelineEntry = entry as PipelineEntry;
        // `PerformanceEntry.identifier` is equal to `view.__lynx_timing_flag`.
        if (pipelineEntry.identifier == "myNamePipeline") {
          setPipelineEntry(JSON.stringify(pipelineEntry, null, 4));
        }
      }
    });
    // 2. Register to listen to the "pipeline" event.
    observer.observe(["pipeline"]);

    // Update real data after simulating a network request.
    setTimeout(() => {
      setMyName("PipelineEntry");
    }, 2000);
  }, []);

  return (
    <view className="container">
      <text className="title" __lynx_timing_flag={myName ? "myNamePipeline" : ""}>Hello {myName}~</text>
      <ScrollItem title="PipelineEntry" value={pipelineEntry} />
    </view>
  );
}

root.render(<PipelineEntryExample />);

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

```

v0.8.0



## Notes

### 1. Multiple components set the same `__lynx_timing_flag` attribute

```ts
export default function App() {
  const [showImage, setShowImage] = useState(false);

  useEffect(() => {
    setTimeout(() => {
      setShowImage(true);
    }, 3000);
  }, []);

  return (
    <view className="container">
      <text __lynx_timing_flag="__lynx_timing_actual_fmp">Hello World</text>
      {showImage && <image __lynx_timing_flag="__lynx_timing_actual_fmp" src="xxxx.png" />}
    </view>
  );
}
```

In this case, only the Lynx Pipeline data of the first component that appears on screen will be recorded:

1. Compute `ActualFMP` once and send one [`MetricActualFmpEntry`](/next/api/lynx-api/performance-api/performance-entry/metric-actual-fmp-entry.md).
2. Send one [`PipelineEntry`](/next/api/lynx-api/performance-api/performance-entry/pipeline-entry.md).

If you want to record the moment when both components finish rendering, use different `__lynx_timing_flag` values.

### 2. The same component renders multiple times

```ts
export default function App(this: any) {
  return (
    <view className="container">
      {
         // needShow: true -> false -> true
         data.needShow ? <text __lynx_timing_flag="__lynx_timing_actual_fmp">{data.msg}</text> : null
      }
    </view>
  );
}
```

In this scenario, only the Lynx Pipeline data for the component’s first appearance is recorded:

1. Compute `ActualFMP` once and send one [`MetricActualFmpEntry`](/next/api/lynx-api/performance-api/performance-entry/metric-actual-fmp-entry.md).
2. Send one [`PipelineEntry`](/next/api/lynx-api/performance-api/performance-entry/pipeline-entry.md).

If you need to measure each render individually, implement as follows:

```ts
let isFirst = true;
export default function App(this: any) {
  return (
    <view className="container">
      {
         // needShow: true -> false -> true
         data.needShow ? <text __lynx_timing_flag={"__lynx_timing_actual_fmp" + (isFirst ? "" : +data.id)}>{data.msg}</text> : null
      }
    </view>
  );
}
```

## Compatibility

**Compatibility Table**

**Query:** `lynx-api.performance-api.timing-flag`

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

| Feature | Android | HarmonyOS | iOS | macOS | Windows | Web |
| --- | --- | --- | --- | --- | --- | --- |
| timing-flag | Yes (3.1) | Yes (3.4) | Yes (3.1) | Yes (3.7) | Yes (3.7) | No |

