For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt, and this page is available as Markdown at /guide/profiling.md.

Profiling performance

Find out what makes your app slow. Record a trace of the running app in Lynx DevTool, mark your own code in it with LynxPerformance, and watch AngularLynx's render counters with LynxDevTools.

Record a trace

A trace is a timeline of what the app did during a recording, on every thread. You record one with Lynx DevTool.

  1. Connect Lynx Explorer to Lynx DevTool, as in Debugging.
  2. In Lynx DevTool, choose Trace from the top bar, and pick your app.
  3. Press Start, use the slow part of your app, then press Stop.
  4. Press Analyze to look at the timeline. Download saves the trace as a file, which you can open in Perfetto.

To trace the app's launch, use Startup Trace in the top bar instead. Lynx's trace guide covers both.

Traces need Lynx Explorer

Only development builds of the Lynx engine can record traces. Lynx Explorer has one. The apps --platform builds, with ng build or ng serve, use the release engine, which can't.

Mark your own code in the trace

LynxPerformance adds named sections and marks to the trace, so you can find your own code in the timeline:

src/app/feed.ts
import { Component, inject, signal } from '@angular/core';
import { LYNX_ELEMENTS, LynxPerformance } from '@blotch/angular-lynx';

@Component({
  selector: 'app-feed',
  imports: [LYNX_ELEMENTS],
  template: `
    <view (bindtap)="sort()">
      <text>Sort {{ items().length }} items</text>
    </view>
  `,
})
export class Feed {
  readonly items = signal<readonly number[]>([3, 1, 2]);
  readonly #perf = inject(LynxPerformance);

  sort(): void {
    this.#perf.profileStart('Feed::sort', {
      args: { count: String(this.items().length) },
    });
    this.items.update((list) => [...list].sort((a, b) => a - b));
    this.#perf.profileEnd();

    this.#perf.profileMark('Feed::sorted');
  }
}
  • profileStart(name) and profileEnd() wrap a section. Sections nest: each profileEnd() closes the most recent profileStart().
  • profileMark(name) adds a single point in time.
  • args attaches values you can read in the trace. They must be strings: Lynx drops any other value, so convert numbers with String().
  • isRecording() tells you whether a trace is recording. Check it before you compute expensive args.
  • profileFlowId() returns an ID. Pass it as flowId to profileStart() or profileMark() to link sections and marks, for example across threads. flowIds links one to several flows.

On a device, the calls do nothing while no trace is recording. Outside Lynx, e.g. in tests, they do nothing at all.

In the web preview

The web preview has no Lynx DevTool trace. There, LynxPerformance writes to the browser's performance timeline instead: a section becomes a User Timing measure, and a mark a User Timing mark. Record in the Performance panel of Chrome DevTools, and find them in the Timings track. isRecording() always returns true there.

Watch render counters

LynxDevTools counts AngularLynx's rendering work and exposes the counts as a signal. Put them on screen to spot extra work, such as a tap that re-renders far more than you expect:

src/app/debug-overlay.ts
import { Component, inject } from '@angular/core';
import { LYNX_ELEMENTS, LynxDevTools } from '@blotch/angular-lynx';

@Component({
  selector: 'app-debug-overlay',
  imports: [LYNX_ELEMENTS],
  template: `
    <view>
      <text>Change detection runs: {{ devtools.stats().cdCycles }}</text>
      <text>
        Elements: +{{ devtools.stats().elementCreated }} / -{{
          devtools.stats().elementRemoved
        }}
      </text>
      <text>Flushes: {{ devtools.stats().flushCount }}</text>
      <text>Last run: {{ devtools.stats().lastCdDurationMs }} ms</text>
      <view (bindtap)="devtools.refresh()">
        <text>Refresh</text>
      </view>
      <view (bindtap)="devtools.reset()">
        <text>Reset</text>
      </view>
    </view>
  `,
})
export class DebugOverlay {
  readonly devtools = inject(LynxDevTools);
}
CounterWhat it shows
cdCyclesChange detection runs
elementCreatedNative elements created
elementRemovedNative elements removed
flushCountTimes AngularLynx sent a batch of changes to the screen
lastCdDurationMsHow long the last change detection run took, in ms, including sending its changes to the screen
  • stats() updates only when you ask. Call refresh() to read the latest counts, or reset() to set them back to zero. The counters change on every render, so updating the signal each time would cause renders of its own.
  • snapshot() returns the counts once, without a signal, e.g. to log them.

Measure startup on a phone

A trace shows what the app does. To time how long it takes to start, mark the moment its first screen is complete with reportFullyDrawn():

effect(() => {
  if (this.items.hasValue()) reportFullyDrawn();
});
  • iOS: record the release app with Instruments' App Launch template plus the Points of Interest instrument. The launch phases end at the first frame; the Fully Drawn point marks the screen being complete.
  • Android: adb logcat | grep "Fully drawn" prints the time from the tap, and Macrobenchmark's StartupTimingMetric reads it as time to full display.

Measure a release build (ng build --platform) on a real phone. A development build and the simulator are both slower in ways that have nothing to do with your app.

Profiling in production builds

AngularLynx's own profiling code is removed from production builds:

  • The counters only count in development builds, such as ng serve and ng build -c development. In a production build, stats() stays at zero.
  • LynxPerformance calls stay in, so you can trace the build you ship, without development mode's extra work in the timeline. They cost little when no trace is recording, and the release Lynx engine records none.