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.
- Connect Lynx Explorer to Lynx DevTool, as in Debugging.
- In Lynx DevTool, choose Trace from the top bar, and pick your app.
- Press Start, use the slow part of your app, then press Stop.
- 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.
Only development builds of the Lynx engine can record traces. Lynx Explorer has one. The apps ng build --platform makes 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:
profileStart(name)andprofileEnd()wrap a section. Sections nest: eachprofileEnd()closes the most recentprofileStart().profileMark(name)adds a single point in time.argsattaches values you can read in the trace. Lynx expects strings.isRecording()tells you whether a trace is recording. Check it before you compute expensiveargs.profileFlowId()returns an ID. Pass it asflowIdto link sections across threads.
The calls do nothing when no trace is recording, and outside Lynx, e.g. in tests.
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:
stats()updates only when you ask. Callrefresh()to read the latest counts, orreset()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.- The counts cover the copy of your app that draws the screen. See Threads.
Profiling in production builds
AngularLynx's own profiling code is removed from production builds:
- The counters only count in development builds, such as
ng serveandng build -c development. In a production build,stats()stays at zero. LynxPerformancecalls stay in. They cost little when no trace is recording, and the release Lynx engine records none.
