Starting from API version 26.0.0, the Performance Hint (perfHint) feature is supported for system performance optimization.
perfHint enables apps to provide performance scenario information to the system.
Apps can provide performance scenario information to the system. Based on this information, the system optimizes app performance within the effective scope of the APIs whenever possible, thereby improving user experience.
The following performance scenarios are supported: app startup, page transitions, page loading, network file processing, local file processing, page rendering, animations, audio and video playback, and media encoding and decoding.
Scenario state control: scenario start and end.
Duration hints: short duration, medium duration, and long duration. Different interval requirements are defined for each duration type to enable differentiated optimization strategies. The duration types are defined as follows:
Multiple threads can be reported simultaneously. An array of thread IDs can be provided.
The perfHint system performance optimization scenario provides the ArkTS APIs listed in the table below. For details about the APIs, see the API Reference.
| API | Description |
|---|---|
| perfHint(config: PerfHintConfig): Promise<void> | System performance optimization API. This API returns the result asynchronously through a promise. |
Import the schedulingOptimization module and related common modules.
import { schedulingOptimization } from '@kit.FASTKit'; Construct an input parameter. Construct the input parameter. The input parameter is a PerfHintConfig object, which contains the scenario type, scenario state, duration type, and an array of thread IDs.
let config: schedulingOptimization.PerfHintConfig = {
sceneType: schedulingOptimization.SceneType.APP_LAUNCH,
sceneState: schedulingOptimization.SceneState.BEGIN,
durationType: schedulingOptimization.DurationType.SHORT,
tids: [] // Enter the thread ID as required.
}; Call the perfHint method to pass the parameter constructed in step 2 to the perfHint method in the module.
try {
await schedulingOptimization.perfHint(config);
console.info('perfHint success');
} catch (err) {
console.error(`perfHint error.code is ${error.code}, message is ${error.message}`);
// Handle the error based on the error code.
}