In application development, while dynamic blur effects can enhance visual experiences, improper usage��such as applying motion blur to image components or setting an excessively large blur radius��can cause performance degradation, including image janks, frame drops, and increased rendering overhead. These issues not only undermine user experience but may also elevate power consumption. Optimizing code logic appropriately can effectively reduce rendering costs and boost user experience. This topic uses the AppAnalyzer tool to detect image blur jank issues in applications and provides targeted optimization solutions based on the fault root causes identified by the tool, helping you resolve image blur performance bottlenecks.
You can inspect the image blur performance of an application via the AppAnalyzer tool and optimize the code according to suggestions in the inspection report to satisfy performance baselines. The procedure for detecting image blur performance using AppAnalyzer is as follows:
Start the AppAnalyzer tool in DevEco Studio.
Select scenario-based health check by default, then click any manual performance check item (page-to-page transition, in-page transition, or page sliding) to enter the corresponding test UI. This topic takes Manual Inter-page Transition Performance Check as an example.
After the check is complete, open the check report and click the expanded transition jank rate. If the test result displays a yellow or red warning accompanied by the root cause "motion blur rendering frame drop diagnosis", an image blur performance issue exists.
If motion blur rendering frame drop diagnosis is listed as the probable fault cause in the detected image blur report, optimize your application according to the following recommendations:
When the motion blur is used to process the image component, if the detection result is abnormal, issues such as frame drops occur during the motion blur drawing. You are advised to use static blur to optimize the image blurring performance. For details about the concepts and application scenarios of motion blur and static blur, see When to Use.
For example, you can click the source code file of the component in the possible cause of malfunction in the detection report to go to the Column component in the TestStructPage.ets file. In the sample code, the blur API is used to blur the image component. As a result, the total time required for the detection is too long and frame drops occur.
Negative example
Column() {
Image($r('app.media.test'))
.width('100%')
.height('30%')
.objectFit(ImageFit.Auto)
.blur(13)
// ...
} Optimization Suggestion
For image blurring scenarios, static blur is recommended. According to the effect comparison, static blur outperforms motion blur when the blurring effect is similar. You are advised to use static blur in scenarios where the background and content do not need real-time updates, as this can reduce jank and frame drops and improve user experience.
Positive example
import { image } from '@kit.ImageKit';
import { effectKit } from '@kit.ArkGraphics2D';
import { window } from '@kit.ArkUI';
import { hilog } from '@kit.PerformanceAnalysisKit';
import { BusinessError } from '@kit.BasicServicesKit';
@Component
export struct StaticBlur {
@Consume('navPathStack') navPathStack: NavPathStack;
@State isShowStaticBlur: boolean = false;
@State pixelMap: image.PixelMap | undefined = undefined;
@State imgSource: image.ImageSource | undefined = undefined;
@State bottomSafeHeight: number = 0;
aboutToAppear(): void {
window.getLastWindow(this.getUIContext().getHostContext()!, (err, windowBar) => {
if (err.code) {
return;
}
try {
this.bottomSafeHeight =
this.getUIContext()
.px2vp(windowBar.getWindowAvoidArea(window.AvoidAreaType.TYPE_NAVIGATION_INDICATOR).bottomRect.height);
} catch (error) {
let err: BusinessError = error as BusinessError;
hilog.warn(0x000, 'testTag', `getWindowAvoidArea failed, code=${err.code}, message=${err.message}`);
}
windowBar.setWindowLayoutFullScreen(true)
.catch((err: BusinessError) => {
hilog.error(0x000, 'testTag', `setWindowLayoutFullScreen failed, code=${err.code}, message=${err.message}`);
})
});
}
aboutToDisappear(): void {
this.pixelMap?.release();
this.pixelMap = undefined;
this.imgSource?.release();
this.imgSource = undefined;
}
async staticBlur(): Promise<void> {
let context: Context = this.getUIContext().getHostContext()!;
await context.resourceManager.getRawFileContent('test.png')
.then((fileData: Uint8Array) => {
let buffer: ArrayBuffer = fileData.buffer.slice(0);
this.imgSource = image.createImageSource(buffer);
})
.catch((err: BusinessError) => {
hilog.error(0x000, 'testTag', `getRawFileContent failed, code=${err.code}, message=${err.message}`);
})
let opts: image.InitializationOptions = {
editable: true,
pixelFormat: 3,
size: {
height: 4,
width: 6
}
};
await this.imgSource!.createPixelMap(opts).then((pixelMap: image.PixelMap) => {
const blurRadius: number = 3;
let headFilter: effectKit.Filter = effectKit.createEffect(pixelMap);
if (headFilter !== null) {
headFilter.blur(blurRadius);
headFilter.getEffectPixelMap().then((pixelMap: image.PixelMap) => {
this.pixelMap = pixelMap;
this.imgSource?.release();
});
}
})
}
@Builder
staticBlurBuilder() {
Stack({ alignContent: Alignment.Bottom }) {
Image(this.pixelMap)
.width('100%')
.height('100%')
.objectFit(ImageFit.Fill)
Button('close')
.width('90%')
.height(40)
.margin({ bottom: this.bottomSafeHeight + 16 })
.onClick(() => {
this.isShowStaticBlur = false;
this.pixelMap?.release();
})
}
.width('100%')
.height('100%')
}
build() {
NavDestination() {
Column() {
Button('static blur')
.width('90%')
.height(40)
.onClick(() => {
this.isShowStaticBlur = true;
this.staticBlur();
})
.bindContentCover(this.isShowStaticBlur, this.staticBlurBuilder(), {
modalTransition: ModalTransition.DEFAULT
})
}
.padding({ bottom: this.bottomSafeHeight + 16 })
.width('100%')
.height('100%')
.justifyContent(FlexAlign.End)
}
.hideTitleBar(true)
}
} When applying blur to non-image components (such as Text components) or in scenarios unsuited for static blur (such as animated GIFs), if test results indicate frame drop anomalies during motion blur rendering, consider reducing the blur radius to optimize image blurring performance.
For example, by clicking the source code file specified under the potential failure root cause in the inspection report, you can navigate directly to the Text component in the ReduceBlurRadius.ets file. In the example code, backdropBlur() is applied to the background of the Text component with a blur radius set to 2.
Negative example
Text('Backdrop Blur')
.padding(5)
.width('90%')
.height('50%')
.fontSize(20)
.fontColor(Color.White)
.textAlign(TextAlign.Center)
.backdropBlur(2)
.backgroundImage($r('app.media.test'))
.backgroundImageSize({ width: '90%' })
.backgroundImagePosition(Alignment.Center) Optimization Suggestion
In non-image blur scenarios, you are advised to reduce the blur radius. The motion blur needs to be recalculated for each frame. Reducing the blur radius can reduce the performance consumption.
Positive example
Text('Backdrop Blur')
.padding(5)
.width('90%')
.height('50%')
.fontSize(20)
.fontColor(Color.White)
.textAlign(TextAlign.Center)
.backdropBlur(0.2)
.backgroundImage($r('app.media.test'))
.backgroundImageSize({ width: '90%' })
.backgroundImagePosition(Alignment.Center) Table 1 Common blurring APIs and optimization suggestions
| Blurring API and Type | Optimization Suggestion |
|---|---|
1. If the component is an image component, static blurring is recommended. 2. If the component is not an image component or static blurring is not applicable, you are advised to reduce the blurring radius. |