目录

Using perfHint for System Performance Optimization (ArkTS)

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.

Use Cases

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.

Constraints

API Description

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.

Development Procedure

  1. Import the schedulingOptimization module and related common modules.

    import { schedulingOptimization } from '@kit.FASTKit';
  2. 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.
    };
  3. 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.
    }