Technical Articles
Performance measurement of SAPUI5 Apps
SAPUI5 is a powerful framework for building enterprise-grade web applications. With its rich set of UI controls and powerful data binding capabilities, SAPUI5 enables developers to build complex applications with ease. However, as applications grow in complexity, measuring and optimizing performance becomes increasingly important. In this blog post, we will explore SAPUI5’s Performance Measurement API and how it can be used to measure and optimize application performance.
What is the Performance Measurement API?
The Performance Measurement API is a set of functions and classes provided by SAPUI5 that enable developers to measure the performance of their applications. The API provides a range of metrics that can be used to measure the performance of various aspects of the application, such as data binding, rendering, and network requests.
Using the Performance Measurement API
To use the Performance Measurement API, developers can simply include the sap.ui.performance.measurement library in their application. Once included, they can use the available functions and classes to measure performance metrics.
For example, the sap.ui.performance.measurement.start() function can be used to measure the time it takes for a specific piece of code to execute. This can be useful for identifying performance bottlenecks in the application code.
Another useful function is sap.ui.performance.measurement.end(), which can be used to measure the performance of network requests made by the application. This function returns a list of timing information for each network request, including the time it took to resolve the DNS, establish a connection, send the request, and receive the response.
Additionally, the Performance Measurement API includes several classes, such as sap.ui.Performance.Measurement, that can be used to group performance metrics together and measure the performance of specific tasks or operations within the application.
Benefits of Using the Performance Measurement API
Using the Performance Measurement API can provide several benefits, including:
- Improved Application Performance: By measuring performance metrics, developers can identify and optimize areas of the application that are causing performance issues, leading to a faster and more responsive application.
- Increased User Satisfaction: A faster and more responsive application leads to a better user experience, resulting in higher user satisfaction and engagement.
- Scalability: Measuring performance metrics can help identify scalability issues and ensure that the application can handle increased traffic and load.
The Performance Measurement API provided by SAPUI5 is a powerful tool for measuring and optimizing application performance. By using the API to measure performance metrics, developers can identify and optimize areas of the application that are causing performance issues, leading to a faster and more responsive application, increased user satisfaction, and improved scalability. Incorporating the Performance Measurement API into the software development process can lead to better-performing SAPUI5 applications and happier end-users.
Here is an example of how to use the Performance Measurement API in SAPUI5 to measure the performance of a SAPUI5 application:
sap.ui.define([
"sap/ui/core/mvc/Controller",
"sap/ui/performance/Measurement"
], function(Controller, Measurement) {
"use strict";
return Controller.extend("my.app.controller.Main", {
onInit: function() {
Measurement.setActive(true);
// Start a performance measurement
Measurement.start("MyPerformanceMeasurement");
// Perform some long-running task
this.performLongRunningTask();
// End the performance measurement
Measurement.end("MyPerformanceMeasurement");
// Get the performance measurement results
var measurementResults = Measurement.getMeasurement("MyPerformanceMeasurement");
// Log the results to the console
console.log("Measurement Results:", measurementResults);
},
performLongRunningTask: function() {
// Simulate a long-running task
for (var i = 0; i < 10000000; i++) {
var j = i * 2;
}
}
});
});
In this example, we first include the sap/ui/core/Performance
module. In the onInit
function of the controller, we start a new performance measurement using the Performance.start
function and provide it with a unique name. We then perform a long-running task using the performLongRunningTask
function, and end the performance measurement using the Performance.end
function.
We then retrieve the performance measurement results using the Measurement.getMeasurement function, passing it the name of our performance measurement. This function returns all performance entries with the specified name.
Finally, we log the performance measurement results to the console.
By using the Performance Measurement API in SAPUI5, we can measure the performance of specific parts of our application and identify areas that require optimization.
API Documentation
Performance Measurement API was introduced since SAPUI5 version 1.58. The module is sap/ui/performance/Measurement. The full documentation is available here sap/ui/performance/Measurement – API Reference – Demo Kit – SAPUI5 SDK
Usage of Performance Measurement API
The API is imported in the Base Controller which is reused from all Controllers to minimize repetitions of code and handled in generic fashion. Then we called BaseController’s startMeasurement and endMeasurement to start and finish calculations of time spent in each user interaction. Base controller is calling Measurement.start method to start counting of time and called Measurement.end to finish counting.
The API handles all these counting and give result as duration. Calling of BaseController is done in 2 ways. First way is via javascript and second way is by using expression binding in xml fragments and views. These durations are then captured in Performance Measurement Table (hdbtable) in HANA Cloud Database.
Javascript Example:
this.oTable.bindItems({
path: sPath,
template: this.getView().byId(
that.constants.oTableColumnListItem
),
events: {
dataRequested: function () {
that.startMeasurement(tableId);
},
dataReceived: function () {
that.endMeasurement(tableId);
},
},
});
XML Example:
items="{
events: {
dataRequested: '.startMeasurement',
dataReceived: '.endMeasurement'
},
path: 'Parameter',
parameters:{
id:'aTable'
},
sorter: [
{ path: 'Status', descending: true },
{ path: 'ExecutionTime', descending: true }
]
}"
Measuring performance is a critical part of building high-quality web applications, and SAPUI5 provides a powerful Performance Measurement API to help developers achieve this. In this blog post, we explored how to use the Performance Measurement API in SAPUI5 to measure the performance of specific parts of an application and identify areas that require optimization.
We looked at an example of how to use the API to start and end a performance measurement, perform a long-running task, and retrieve the measurement results. By using the Performance Measurement API in SAPUI5, developers can improve the performance of their applications, increase user satisfaction, and ensure scalability.
In conclusion, the Performance Measurement API in SAPUI5 is a powerful tool that can help developers build better-performing applications, and it should be an essential part of any SAPUI5 developer’s toolkit. With the help of this API, developers can measure performance metrics, identify and optimize areas of the application that are causing performance issues, and ensure that their applications are responsive, scalable, and user-friendly.
Hey Sanjoy, great post, thank you!