Skip to content

SMAT-Lab/PhantomRendering

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

2 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Phantom Rendering Detection Framework

Identifying and Analyzing Unnecessary UI Computations in OpenHarmony Applications

This repository contains the code and resources for the HapP(hantom)R(endering)Detection framework, a comprehensive and automated solution for detecting and resolving performance issues related to "Phantom Rendering" in OpenHarmony applications.

Introduction

HapPRDetection is a novel, automated framework designed to detect and analyze Phantom Rendering - a phenomenon where mobile applications perform significant computational work on the UI thread without producing any visible changes or updates to the user interface. This computational waste leads to increased energy consumption, device heating, poor user experience, and reduced battery life.

Traditional performance analysis tools often fail to detect Phantom Rendering because they focus on visual smoothness or require expert interpretation of complex outputs like flame graphs. HapPRDetection overcomes these limitations by providing a developer-friendly approach to diagnose and fix Phantom Rendering issues, transforming complex performance analysis into actionable, function-level insights.

πŸ” What is Phantom Rendering?

Phantom Rendering is a phenomenon where mobile applications perform significant computational work on the UI thread without producing any visible changes or updates to the user interface. This computational waste leads to:

  • Wasted CPU and GPU resources - Applications consume processing power for no visual output
  • Increased energy consumption - Device batteries drain faster due to unnecessary computations
  • Device heating - Continuous processing leads to thermal issues
  • Poor user experience - Reduced responsiveness and application performance
  • Reduced battery life - Higher power consumption affects device longevity

Traditional performance analysis tools often fail to detect Phantom Rendering because they focus on visual smoothness metrics (like frame rates) or require expert interpretation of complex outputs like flame graphs.

Frame Classification Analysis

Figure 1: Frame classification showing the difference between Normal Frames and Phantom Rendering frames

🎯 Key Features & Contributions

HapPRDetection is the first fully automated framework for detecting Phantom Rendering, offering several breakthrough capabilities:

Automated Detection

  • Uses CPU Retired Instructions as a stable metric to quantify computational work and energy consumption
  • Enables precise measurement of wasted resources without requiring manual analysis
  • Provides automated identification of performance bottlenecks

CI/CD Integration

  • Seamlessly integrates into continuous integration/continuous delivery (CI/CD) pipelines
  • Shifts performance optimization from reactive post-development task to proactive, continuous process
  • Enables early detection of performance issues during development

Function-Level Attribution

  • Attributes computational costs to specific functions and code locations
  • Provides concrete optimization guidance without requiring deep system knowledge
  • Eliminates guesswork in performance optimization
Function-Level Attribution Hierarchy

Figure 2: Function-level attribution hierarchy showing computational cost distribution across code components

OpenHarmony Optimized

  • Specifically designed for OpenHarmony's decoupled, dual-thread architecture
  • Analyzes both UI Thread and Render Service Thread interactions
  • Enables precise analysis of rendering inefficiencies in modern mobile architectures
OpenHarmony Multi-thread Coordination

Figure 3: OpenHarmony's dual-thread architecture showing UI Thread and Render Service Thread coordination

Real-World Validation

  • Evaluated on 22 commercial applications
  • Successfully identified issues causing up to 26x computational overhead
  • Reduced diagnostic time from hours to minutes
Real-world Phantom Rendering Issue

Figure 5: Example of a real-world user complaint about application performance issues caused by phantom rendering

πŸ“± Example Application

Our tool includes a comprehensive phantom rendering test application located in the example/ directory that simulates real-world empty frame scenarios based on Xiaohongshu (Little Red Book) performance analysis.

Test Application Structure

The example app (example/entry/src/main/ets/pages/) includes four specialized test pages:

  • Index.ets: Main navigation page with test scenario selection
  • ImageBrowsePage.ets: Step 1 - Image browsing with filter processing simulations
  • LikeInteractionPage.ets: Step 2 - Like interactions with animation calculations
  • PinchZoomPage.ets: Step 3 - Pinch zoom with matrix transformations
  • CommentScrollPage.ets: Step 4 - Comment scrolling with layout calculations

Phantom Rendering Test Modes

Each test page offers two distinct modes:

πŸ”΄ Phantom Rendering Frame Mode

  • Performs real UI calculations but immediately reverts changes
  • Triggers continuous state updates that produce no visual effects
  • Simulates complex processing (filters, animations, transformations)
  • Runs at 15-30fps with zero visible output

🟒 Normal Mode

  • Operates with zero empty frames
  • Only performs UI work when user interacts
  • Demonstrates efficient resource management
  • Provides baseline for comparison

Test Scenarios Based on Real App Analysis

  1. Step 1 - Image Browsing: Simulates image filter processing, color space conversion, and scaling calculations that produce empty frames
  2. Step 2 - Like Interactions: Tests animation calculations, particle effects, and Bezier curve computations
  3. Step 3 - Pinch Zoom: Evaluates matrix transformations, touch processing, and bilinear interpolation
  4. Step 4 - Comment Scrolling: Analyzes text layout, virtual scrolling, and viewport optimization calculations

πŸ—οΈ Framework Architecture

HapPRDetection consists of four interconnected modules that work together to provide comprehensive Phantom Rendering detection:

HapPRDetection Framework Architecture

Figure 4: HapPRDetection Framework Architecture showing the interaction between four core modules

Scripts Generation Module (SGM)

  • Automatically generates executable test scripts for systematic testing
  • Creates reproducible test scenarios based on application behavior
  • Eliminates manual test case creation overhead

Random Click Module (RCM)

  • Simulates realistic user interactions to capture authentic usage patterns
  • Generates diverse interaction sequences for comprehensive coverage
  • Mimics real-world user behavior patterns

Performance Exploration Module (PEM)

  • Collects detailed performance metrics with focus on CPU Retired Instructions
  • Monitors system resources during application execution
  • Captures fine-grained performance data for analysis

Issue Detection Module (IDM)

  • Analyzes collected data to identify, quantify, and localize Phantom Rendering instances
  • Provides function-level attribution of computational waste
  • Generates actionable optimization recommendations

πŸš€ Quick Start

Build

npm install
npm run build

Ubuntu System Dependencies

# Optional: Configure ubuntu-22.04 mirror for faster downloads
sed -i "s@http://.*security.ubuntu.com@http://mirrors.huaweicloud.com@g" /etc/apt/sources.list
sed -i "s@http://.*archive.ubuntu.com@http://mirrors.huaweicloud.com@g" /etc/apt/sources.list

# Optional: Configure ubuntu-24.04 mirror for faster downloads
sed -i "s@http://.*security.ubuntu.com@http://mirrors.huaweicloud.com@g" /etc/apt/sources.list.d/ubuntu.sources
sed -i "s@http://.*archive.ubuntu.com@http://mirrors.huaweicloud.com@g" /etc/apt/sources.list.d/ubuntu.sources

apt-get update && \
apt-get install -y \
    git \
    git-lfs \
    python3 \
    python3-pip \
    python3-venv \
    python3-dev

# Add Command Line Tools for HarmonyOS to PATH
# export command_line_tools=[Command Line Tools for HarmonyOS] directory
export PATH=$PATH:$command_line_tools/tool/node/bin:$command_line_tools/sdk/default/openharmony/toolchains

MacOS Dependencies

brew install git git-lfs python@3.11

# Add Command Line Tools for HarmonyOS to PATH
# export command_line_tools=[Command Line Tools for HarmonyOS] directory
export PATH=$PATH:$command_line_tools/tool/node/bin:$command_line_tools/sdk/default/openharmony/toolchains

Linux Installation

# Initialize environment (only needed once)
git clone https://github.com/your-repo/phantom-rendering-detection
cd phantom-rendering-detection/
npm install
npm run build
# Activate the python virtual environment perf_testing/.venv
source activate.sh
# Configure test cases in config.yaml as needed
python -m scripts.main perf --run_testcases .*_example.*

Dependencies

⚠️ Please make sure that the default python command in your terminal points to a valid Python interpreter in the 3.9 ~ 3.12 range.

πŸ”¬ Detection Commands

Phantom Rendering Analysis

python -m scripts.main perf [options]

Key Options for Phantom Rendering Detection:

  • --run_testcases <patterns>: Run specific test cases (e.g., .*_empty_frame.*)
  • --devices <device_serial>: Target device for analysis
  • --round <N>: Number of test rounds (default: 5)

Example Usage:

# Run phantom rendering detection on example app
python -m scripts.main perf --run_testcases .*_example.*

# Analyze specific empty frame patterns
python -m scripts.main perf --run_testcases .*_empty_frame.* --round 3

Report Generation

The tool automatically generates comprehensive reports including:

  • Phantom Rendering Frame Statistics: Quantitative analysis of phantom rendering occurrences
  • Performance Impact: CPU/GPU usage during phantom rendering events
  • Visual Timeline: Frame-by-frame analysis of rendering operations
  • Optimization Recommendations: Actionable suggestions for reducing phantom rendering

πŸ“Š Understanding Results

Phantom Rendering Frame Metrics

  • Phantom Rendering Frame Ratio: Percentage of frames with no visible content
  • Resource Waste: CPU/GPU cycles consumed by phantom rendering
  • Performance Impact: Measured impact on application responsiveness

Report Interpretation

  • Green: Optimal rendering efficiency
  • Yellow: Minor phantom rendering detected
  • Red: Significant phantom rendering issues requiring attention

πŸ› οΈ Configuration

Test Case Configuration

Configure phantom rendering detection in perf_testing/config.yaml:

run_testcases:
  - .*_example.*      # Run the phantom rendering example app tests
  - .*_empty_frame.*  # Focus on empty frame detection patterns

# Custom categories for phantom rendering analysis
kind:
  - 
    name: 'UI_Rendering'
    files:
      - '.*\.ets$'      # ArkTS UI files
      - '.*ImageBrowsePage.*'
      - '.*LikeInteractionPage.*' 
      - '.*CommentScrollPage.*'
    threads:
      - 'RenderThread'
      - 'UI.*Thread'

πŸ”§ Advanced Usage

Custom Phantom Rendering Rules

Create custom detection rules by extending the analysis framework:

  1. Define custom empty frame criteria
  2. Set performance thresholds
  3. Configure reporting preferences
  4. Customize visualization options

πŸ“š Documentation

🎯 Example Scenarios

The included example application demonstrates detection of:

  1. List View Phantom Rendering: Empty frames during scrolling operations
  2. Component Lifecycle Issues: Unnecessary renders during component updates
  3. State Transition Problems: Phantom rendering during state changes
  4. Resource Loading: Empty frames during asynchronous operations

🚨 Common Phantom Rendering Patterns

Our tool specifically detects:

  • Empty Container Renders: Components rendering without content
  • Invisible Element Updates: Updates to off-screen or hidden elements
  • Redundant Layout Operations: Unnecessary layout calculations
  • Stale Frame Rendering: Rendering frames identical to previous ones

πŸŽ‰ Getting Started with Examples

  1. Build the example app:

    cd example/
    # Build using DevEco Studio or hvigor command line tools
    ./hvigorw assembleHap
  2. Install and run the test app on device:

    # Install the built HAP file to your HarmonyOS device
    hdc install entry/build/default/outputs/default/entry-default-signed.hap
  3. Run phantom rendering detection:

    # Run specific example test cases
    python -m scripts.main perf --run_testcases .*_example.*
    
    # Run individual test scenarios
    python -m scripts.main perf --run_testcases ResourceUsage_PerformanceDynamic_example_combined
  4. Analyze results: Check generated reports for phantom rendering insights and compare Phantom Rendering Frame Mode vs Normal Mode performance

πŸ“Š Research Impact & Validation

HapPRDetection has been extensively evaluated and validated through comprehensive research:

Commercial Application Study

  • 22 commercial applications analyzed across different domains
  • Phantom Rendering issues identified in real-world production apps
  • Up to 26x computational overhead detected and quantified
  • Diagnostic time reduced from hours to minutes

Performance Metrics

  • CPU Retired Instructions used as stable, hardware-independent metric
  • Energy consumption analysis through instruction-based measurements
  • Function-level attribution enabling precise optimization targeting
  • CI/CD integration for continuous performance monitoring

OpenHarmony Ecosystem

  • Dual-thread architecture support (UI Thread + Render Service Thread)
  • Native integration with OpenHarmony performance tooling
  • Production-ready deployment in development workflows

πŸ“š Academic Publication

This framework is the subject of the research paper:

"Phantom Rendering Detection: Identifying and Analyzing Unnecessary UI Computations in OpenHarmony Apps"

The paper presents the theoretical foundation, implementation details, and comprehensive evaluation of the HapPRDetection framework, demonstrating its effectiveness in detecting and resolving Phantom Rendering issues in modern mobile applications.

πŸ”— Repository Information

  • Source Code: Available in this repository
  • Framework: Open source under Apache License 2.0
  • Platform: OpenHarmony / HarmonyOS applications
  • Language: TypeScript, Python, ArkTS (OpenHarmony UI framework)

License

This project is licensed under the Apache License 2.0.


HapPRDetection: Advancing mobile application performance through automated Phantom Rendering detection and optimization.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors