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 --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:
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. They must be strings: Lynx drops any other value, so convert numbers withString().isRecording()tells you whether a trace is recording. Check it before you compute expensiveargs.profileFlowId()returns an ID. Pass it asflowIdtoprofileStart()orprofileMark()to link sections and marks, for example across threads.flowIdslinks 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:
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.
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():
- 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 Drawnpoint marks the screen being complete. - Android:
adb logcat | grep "Fully drawn"prints the time from the tap, and Macrobenchmark'sStartupTimingMetricreads 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 serveandng build -c development. In a production build,stats()stays at zero. LynxPerformancecalls 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.
