How JD Built a High‑Performance Cross‑Platform Image Library for HarmonyOS with Taro
This article details JD's development of a modular, C++‑based image library for HarmonyOS, explaining the shortcomings of native components, the design of a cross‑platform architecture, core modules, performance pipelines, monitoring, and future optimization plans.
JD launched the development of a HarmonyOS app in early 2024 and identified image loading performance as a critical bottleneck for its e‑commerce platform, prompting the creation of a custom image library.
Background
Because the app heavily relies on images, JD prioritized the image library as a core capability in the first phase of its HarmonyOS infrastructure.
Technical Implementation
Pre‑research
Investigation revealed that the HarmonyOS platform loads network images mainly via two approaches:
System – Image component
The built‑in component offers basic loading but suffers from limited performance, lack of AVIF support, no quality‑monitoring system, and no control over download, decode, or cache pipelines.
Third‑party – ImageKnife
Inspired by Android’s Glide, ImageKnife is implemented in ArkTS but still falls short in performance, stability, and extensibility.
Given these limitations, JD decided to develop its own image library using C++ as the core, enabling cross‑platform reuse for iOS and Android and reducing the overhead of frequent ArkTS ‑ C++ communication.
JDImage Capabilities
Architecture Design
To address cross‑platform compatibility, JD adopted a modular, layered architecture inspired by iOS/Android libraries such as SDWebImage, Glide, and Fresco. The library is split into a Core layer (implemented in C++) and a Client layer for platform‑specific adaptations.
Core Modules
The library consists of independent modules for cache, decoder, source fetching, performance monitoring, and the image component.
Image Cache
Memory cache uses an LRU algorithm to store decoded bitmaps and dynamically adjust memory usage.
Disk cache stores downloaded images in the app sandbox, supports multithreaded reads/writes, and provides size management.
Image Source Fetching
HTTP: Uses Cornet for high‑performance parallel network requests.
Base64: Directly decodes Base64‑encoded images.
Decoder
System decoder supports PNG, JPG, GIF, WebP, SVG, etc.
AVIF decoder integrates libavif to handle JD’s extensive AVIF usage.
Performance Monitoring
Load performance: records stage timings, cache hit rates, format usage, and resource consumption.
Exception monitoring: captures errors with unique codes and categorizes them as warnings or critical failures.
Image Component
Wraps the system Image component, rendering decoded PixelMap objects via the src attribute and offering extra properties such as lazy, sourceSize, and priority for performance tuning.
Performance Optimizations
Image Loading Pipeline
The pipeline, inspired by Fresco, allows flexible task ordering, module invocation, thread scheduling via HarmonyOS FFRT, duplicate task aggregation, load monitoring, and cancel/retry mechanisms.
Server‑Side Image Processing
JD’s image server can perform format conversion, quality reduction, scaling, rounding, and grayscale via URL parameters. The pipeline automatically appends these parameters (e.g., using .avif) to reduce network payload.
Quality Assurance
Online Monitoring
Exception monitoring with distinct error codes and severity levels.
Performance monitoring of load success rates and timing for each pipeline stage.
Exception Recovery
Pipeline retry with strategy based on error type.
Component fallback to the system Image component if custom decoding fails.
Online configuration‑driven degradation for specific users, devices, or app versions.
Future Plans
Network optimizations such as weak‑network handling and HTTPDNS.
Further performance gains: higher cache reuse, memory pool usage, GIF optimization, low‑end device tweaks.
Deeper integration with JD’s image server for dynamic scaling and format selection.
Expand support to iOS, Android, and additional platforms.
Enhance image quality via advanced interpolation, super‑resolution, HDR, etc.
Conclusion
JD’s self‑built HarmonyOS image library, through modular design and a flexible pipeline, resolves cross‑platform development challenges while delivering high performance and stability. The library now powers JD’s HarmonyOS app and sets a foundation for future multi‑platform expansion.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
JD Cloud Developers
JD Cloud Developers (Developer of JD Technology) is a JD Technology Group platform offering technical sharing and communication for AI, cloud computing, IoT and related developers. It publishes JD product technical information, industry content, and tech event news. Embrace technology and partner with developers to envision the future.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
