# Get updated performance statistics

Start from base library version 2.12.0. Please remaining backward compatible.

If you want to know the cost of an update to the interface caused by setData, you can use the update performance statistics interface. It returns the timestamp of the major update steps in each update and can be used to generally estimate the update performance of a custom component (or page). For example:

Component({
  attached() { // 调用时机不能早于 attached
    this.setUpdatePerformanceListener({withDataPaths: true}, (res) => {
      console.log(res)
    })
  }
})

The method setUpdatePerformanceListeneraccepts anoptionsobject and a callback functionlisteneras parameters.

Where theoptionsobject contains the following fields:

field type Introductions
withDataPaths Boolean Whether to return changed data field information

Listenersreturns anresobject that represents a update procedure triggered by setData.Depending on the timing of the setData call, the update process can be roughly divided into three categories:

  1. Basic update , which has a uniqueupdateProcessId;
  2. Sub-update , which is a sub-step of another basic update, also has a unique updateProcessId,But there is aparentUpdateProcessId`;
  3. Merged update , which is merged into another basic update or sub-update process and cannot be independently counted.

Each successful setData call generates an update that causes thelistenerto call back once.However, it is difficult to judge what kind of update process is triggered by setData, and the performance of the update is not necessarily related to what kind of update it is, but their return value parameters are different.

The rescontains the following fields:

field type Introductions
updateProcessId Number The ID of this update process
parentUpdateProcessId Number For a child update, return the update process ID to which it belongs
isMergedUpdate Boolean If so,updateProcessIdindicates the update process ID to be merged
dataPaths Array The updated data field information will be returned only whenwithDataPathsis set totrue
pendingStartTimestamp Number This update enters a time stamp while waiting in the queue
updateStartTimestamp Number Update the time stamp at the start of the operation
updateEndTimestamp Number Update the time stamp at the end of the operation

Dxplaination:

  • SetUpdatePerformanceListeneronly activates statistics for the current component or page,parentUpdateProcessIdIt may be the update process ID of other components or pages that have not been called back statistically. If you want to know all the update processes in the page, you need to callsetUpdatePerformanceListener
  • The statistics themselves have a little overhead. If you want to disable statistics, callsetUpdatePerformanceListenerThe second argumentlistenerisnull.